Repository: platers/obsidian-linter (ts)

Issue:
Bug: "Preserve existing aliases section style" should check Linter's array section style setting to avoid >1 lint
- [x] I have verified that I am on the latest version of the Linter

## Describe the Bug

With "Preserve existing aliases section style" enabled, Linter first adds the alias between the empty `aliases`'s square brackets on first lint, then on the second, styles `aliases` as a multi-line array. Since Linter knows aliases is set to be styled as a multi-line array, it presumably should be able to style the array correctly in one step.

## How to Reproduce

Steps to reproduce the behavior:

``` markdown
aliases: []
```

1. Change filename (or H1).
2. Lint.

``` markdown
aliases: [Filename]
```

3. Lint again.

``` markdown
aliases:
  - Filename
```

## Expected Behavior

On first lint, produce the second codeblock above.

## Screenshots

**Array multi-line setting:**

![Obsidian_2024-05-04_13-47-29](https://github.com/platers/obsidian-linter/assets/25013746/319abfde-e351-4297-97ae-e4f4dd52d7f3)

**Array multi-line setting:**

![Obsidian_2024-05-04_13-47-57](https://github.com/platers/obsidian-linter/assets/25013746/0fe06b6b-e9da-4556-b34a-73bb3d992027)

**"Preserve existing aliases section style" setting:**

![Obsidian_2024-05-04_13-46-50](https://github.com/platers/obsidian-linter/assets/25013746/a1f3e730-f93f-4626-8cc8-367e61c57f91)


## Device

- [x] Desktop
- [ ] Mobile

Pull request description:
Fix: `yaml-title-alias` Does Not Respect Multiline Format when Initially Empty with Preserve Existing Format Used
Fixes #1085 

There was a reported issue where `yaml-title-alias` did not seem to be working when the aliases section was empty, default aliases section style was multiline, and the setting for preserving the style of the aliases section was set to true. The fix was to make sure that we assume that `[]` is not tied to any one type. So if that is the value for aliases and the default style for aliases is multiline, we will assume it is meant to be a multiline array.

Changes Made:
- Added a UT for the scenario in question
- Made sure to only consider the aliases section to be single line if there are no new lines in the values and the aliases value is not a blank yaml array with a default aliases section style of multiline

Patch:
diff --git a/src/rules/yaml-title-alias.ts b/src/rules/yaml-title-alias.ts
index 7205d43..2cf24d8 100644
--- a/src/rules/yaml-title-alias.ts
+++ b/src/rules/yaml-title-alias.ts
@@ -77,7 +77,7 @@ export default class YamlTitleAlias extends RuleBuilder<YamlTitleAliasOptions> {
       let currentAliasStyle: NormalArrayFormats | SpecialArrayFormats = NormalArrayFormats.MultiLine;
       const isEmpty = aliasesValue === '';
       let isSingleString = false;
-      if (!aliasesValue.includes('\n')) {
+      if (!aliasesValue.includes('\n') && !(aliasesValue === '[]' && options.aliasArrayStyle === NormalArrayFormats.MultiLine)) {
         if (aliasesValue.match(/^\[.*\]/) === null) {
           // Note that the value here is just really a placeholder to indicate it is not single-line or multi-line
           currentAliasStyle = SpecialArrayFormats.SingleStringToSingleLine;


Test patch:
diff --git a/__tests__/yaml-title-alias.test.ts b/__tests__/yaml-title-alias.test.ts
index 4762df3..43883a8 100644
--- a/__tests__/yaml-title-alias.test.ts
+++ b/__tests__/yaml-title-alias.test.ts
@@ -1391,5 +1391,28 @@ ruleTest({
         defaultEscapeCharacter: '"',
       },
     },
+    { // accounts for https://github.com/platers/obsidian-linter/issues/1085
+      testName: 'Make sure that if the aliases section is empty and the default format for arrays is multiline, then it should use multiline as the output',
+      before: dedent`
+        ---
+        aliases: []
+        ---
+      `,
+      after: dedent`
+        ---
+        aliases:
+          - Filename
+        aliases2: Filename
+        ---
+      `,
+      options: {
+        aliasArrayStyle: NormalArrayFormats.MultiLine,
+        defaultEscapeCharacter: '"',
+        preserveExistingAliasesSectionStyle: true,
+        aliasHelperKey: 'aliases2',
+        keepAliasThatMatchesTheFilename: true,
+        fileName: 'Filename',
+      },
+    },
   ],
 });