Repository: platers/obsidian-linter (ts)

Issue:
Bug: `Format Yaml Array` rule breaks nested YAML objects
## Describe the Bug

`Format Yaml Array` rule breaks nested YAML objects

## How to Reproduce

Steps to reproduce the behavior:

``` markdown
---
key1:
  key2: value2
  key3:
    - item1
    - item2
---
```

## Expected Behavior

Not changed

## Actual Behavior

```markdown
key1:
  - item1
  - item2
```markdown

Pull request:
Don't call format array for non-arrays
Fixes #477 

Patch:
diff --git a/src/rules/format-yaml-arrays.ts b/src/rules/format-yaml-arrays.ts
index eabbf93..c3ee018 100644
--- a/src/rules/format-yaml-arrays.ts
+++ b/src/rules/format-yaml-arrays.ts
@@ -49,11 +49,6 @@ export default class RuleTemplate extends RuleBuilder<FormatYamlArrayOptions> {
         return text;
       }
 
-      // https://stackoverflow.com/a/44198641
-      const isValidDate = function(date: any) {
-        return date && Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date);
-      };
-
       if (options.formatAliasKey && Object.keys(yaml).includes(OBSIDIAN_ALIASES_KEY)) {
         text = setYamlSection(text, OBSIDIAN_ALIASES_KEY, formatYamlArrayValue(convertAliasValueToStringOrStringArray(splitValueIfSingleOrMultilineArray(getYamlSectionValue(text, OBSIDIAN_ALIASES_KEY))), options.aliasArrayStyle));
       }
@@ -67,7 +62,7 @@ export default class RuleTemplate extends RuleBuilder<FormatYamlArrayOptions> {
 
         for (const key of Object.keys(yaml)) {
           // skip non-arrays and already accounted for keys
-          if (keysToIgnore.includes(key) || !(typeof yaml[key] === 'object' && !isValidDate(yaml[key]) && yaml[key] as string[])) {
+          if (keysToIgnore.includes(key) || !Array.isArray(yaml[key])) {
             continue;
           }
 


Test patch:
diff --git a/__tests__/format-yaml-arrays.test.ts b/__tests__/format-yaml-arrays.test.ts
index 77c6060..a7c7c94 100644
--- a/__tests__/format-yaml-arrays.test.ts
+++ b/__tests__/format-yaml-arrays.test.ts
@@ -785,5 +785,29 @@ ruleTest({
         ---
       `,
     },
+    {
+      testName: 'Nested objects are preserved',
+      before: dedent`
+        ---
+        key1:
+          key2: value2
+          key3:
+            - item1
+            - item2
+        ---
+      `,
+      after: dedent`
+        ---
+        key1:
+          key2: value2
+          key3:
+            - item1
+            - item2
+        ---
+      `,
+      options: {
+        defaultArrayStyle: NormalArrayFormats.MultiLine,
+      },
+    },
   ],
 });