platers / obsidian-linter

An Obsidian plugin that formats and styles your notes with a focus on configurability and extensibility.
https://platers.github.io/obsidian-linter/
MIT License
1.13k stars 79 forks source link

Bug: YAML Key Sort Does Not Support Line Break Syntax #992

Open bryanwhiting opened 6 months ago

bryanwhiting commented 6 months ago

Describe the Bug

Linting with line breaks doesn't work properly with the sorting feature. You'll notice the description falls down into the "draft" property.

Before lint:

title: 'hello'
description: |
  "Something nut"
date: 2024-01-07T00:00:00
updated: 2024-01-07T12:18:20
categories: favorite
draft: false
hi: |
  "Hello world"
bye: |
  There bob

After lint:

---
title: 'hello'
description: |
date: 2024-01-07T00:00:00
updated: 2024-01-07T12:21:18
categories: favorite
draft: false
  "Something nut"
hi: |
  "Hello world"
bye: |
  There bob
---

How to Reproduce

Sorting yaml rules in options

title:
description:
date:
updated:
categories:
draft:

Expected Behavior

It should not shift the stuff after "|" down.

Screenshots

See above

Device

pjkaufman commented 6 months ago

Hey @bryanwhiting . It looks like you ran into a some YAML syntax that the Linter does not know how to handle. I am not sure when or if this will get addressed since there currently is not a good way to handle this scenario without reformatting the key value pairs at this time.

If someone would like to add a fix for this or handle this syntax before I or someone else does, feel free to make a PR.

In the meantime, if you do not have a particular reason to use the line break YAML syntax, I would not use it at this time.

bryanwhiting commented 6 months ago

Thanks for the quick reply. I'll just turn off sorting for now then, as I'm probably useless in trying to resolve this.

Turning off sorting keys prevents the problem.