Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swap to from js-yaml to yaml for Parsing YAML #1227

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 115 additions & 10 deletions __tests__/yaml-key-sort.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ ruleTest({
`,
after: dedent`
---
related-companies:${' '}
stakeholders:${' '}
pr-pipeline-stage:${' '}
pr-priority:${' '}
pr-size:${' '}
pr-urgency:${' '}
pr-type:${' '}
pr-okr:${' '}
pr-due-date:${' '}
pr-completed-date:${' '}
related-companies:
stakeholders:
pr-pipeline-stage:
pr-priority:
pr-size:
pr-urgency:
pr-type:
pr-okr:
pr-due-date:
pr-completed-date:
template: "[[Pro New Project Outcome Template]]"
created-date: '[[<% tp.file.creation_date("YYYY-MM-DD") %>]]'
modified: Tuesday, October 22nd 2024, 10:58:16 am
Expand All @@ -199,5 +199,110 @@ ruleTest({
],
},
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/1082
testName: 'Make sure that literal operator `|` is handled correctly',
before: dedent`
---
sorting-spec: |
order-desc: a-z
first: alphabetical
---
`,
after: dedent`
---
first: alphabetical
sorting-spec: |
order-desc: a-z
---
`,
options: {
yamlKeyPrioritySortOrder: [
'first',
'sorting-spec:',
],
},
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/912
testName: 'Make sure that lots of nesting does not get broken',
before: dedent`
---
AAA:
- BBB: x
CCC: x
- DDD: x
EEE: x
FFF:
- GGG: x
- HHH
III: x
FFF:
-${' '}
---
`,
after: dedent`
---
AAA:
- BBB: x
CCC: x
- DDD: x
EEE: x
FFF:
- GGG: x
- HHH
III: x
FFF:
${' '}
-${' '}
---
`, // note that this does look wonky, but it works the same in Obsidian, so I am going to consider this fine for now
// see https://github.com/eemeli/yaml/issues/590 for more information on this
options: {
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
},
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/660
testName: 'Make sure that comments are not removed when sorting',
before: dedent`
---
created: 2023-02-18T10:53:01+00:00
# Dont remove me
disabled rules: [capitalize-headings]
modified: 2023-03-20T14:53:42+00:00
---
`,
after: dedent`
---
created: 2023-02-18T10:53:01+00:00
# Dont remove me
disabled rules: [ capitalize-headings ]
modified: 2023-03-20T14:53:42+00:00
---
`,
options: {
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
},
},
{ // accounts for https://github.com/platers/obsidian-linter/issues/660
testName: 'Make sure that scalars are not removed when sorting',
before: dedent`
---
name: John
husband: Tim
biography: |
A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap.
---
`,
after: dedent`
---
biography: |
A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap. A very nice chap.
husband: Tim
name: John
---
`,
options: {
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
},
},
],
});
43 changes: 16 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@types/diff": "^5.0.9",
"@types/diff-match-patch": "^1.0.32",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.5",
"@types/node": "^20.11.28",
"@typescript-eslint/eslint-plugin": "^7.2.0",
"@typescript-eslint/parser": "^7.2.0",
Expand Down Expand Up @@ -61,7 +60,6 @@
"@popperjs/core": "^2.11.6",
"async-lock": "^1.4.1",
"diff-match-patch": "^1.0.5",
"js-yaml": "^4.1.0",
"loglevel": "^1.9.1",
"mdast-util-from-markdown": "^2.0.0",
"mdast-util-frontmatter": "^2.0.1",
Expand All @@ -75,6 +73,7 @@
"moment-parseformat": "^4.0.0",
"quick-lru": "^7.0.0",
"ts-dedent": "^2.2.0",
"unist-util-visit": "^5.0.0"
"unist-util-visit": "^5.0.0",
"yaml": "^2.6.0"
}
}
Loading
Loading