Skip to content

Commit 185ceaf

Browse files
authored
Merge pull request #1227 from pjkaufman/swap-to-yaml
Swap to from `js-yaml` to `yaml` for Parsing YAML
2 parents 25a3e05 + f37e82a commit 185ceaf

File tree

7 files changed

+300
-66
lines changed

7 files changed

+300
-66
lines changed

__tests__/yaml-key-sort.test.ts

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,165 @@ ruleTest({
199199
],
200200
},
201201
},
202+
{ // accounts for https://github.com/platers/obsidian-linter/issues/1082
203+
testName: 'Make sure that literal operator `|` is handled correctly',
204+
before: dedent`
205+
---
206+
sorting-spec: |
207+
order-desc: a-z
208+
first: alphabetical
209+
---
210+
`,
211+
after: dedent`
212+
---
213+
first: alphabetical
214+
sorting-spec: |
215+
order-desc: a-z
216+
---
217+
`,
218+
options: {
219+
yamlKeyPrioritySortOrder: [
220+
'first',
221+
'sorting-spec:',
222+
],
223+
},
224+
},
225+
{ // accounts for https://github.com/platers/obsidian-linter/issues/912
226+
testName: 'Make sure that lots of nesting does not get broken',
227+
before: dedent`
228+
---
229+
AAA:
230+
- BBB: x
231+
CCC: x
232+
- DDD: x
233+
EEE: x
234+
FFF:
235+
- GGG: x
236+
- HHH
237+
III: x
238+
FFF:
239+
-${' '}
240+
---
241+
`,
242+
after: dedent`
243+
---
244+
AAA:
245+
- BBB: x
246+
CCC: x
247+
- DDD: x
248+
EEE: x
249+
FFF:
250+
- GGG: x
251+
- HHH
252+
III: x
253+
FFF:
254+
-${' '}
255+
---
256+
`, // note that this does look wonky, but it works the same in Obsidian, so I am going to consider this fine for now
257+
// see https://github.com/eemeli/yaml/issues/590 for more information on this
258+
options: {
259+
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
260+
},
261+
},
262+
{ // accounts for https://github.com/platers/obsidian-linter/issues/660
263+
testName: 'Make sure that comments are not removed when sorting',
264+
before: dedent`
265+
---
266+
created: 2023-02-18T10:53:01+00:00
267+
# Dont remove me
268+
disabled rules: [capitalize-headings]
269+
modified: 2023-03-20T14:53:42+00:00
270+
---
271+
`,
272+
after: dedent`
273+
---
274+
created: 2023-02-18T10:53:01+00:00
275+
# Dont remove me
276+
disabled rules: [capitalize-headings]
277+
modified: 2023-03-20T14:53:42+00:00
278+
---
279+
`,
280+
options: {
281+
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
282+
},
283+
},
284+
{ // accounts for https://github.com/platers/obsidian-linter/issues/660
285+
testName: 'Make sure that scalars are not removed when sorting',
286+
before: dedent`
287+
---
288+
name: John
289+
husband: Tim
290+
biography: |
291+
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.
292+
---
293+
`,
294+
after: dedent`
295+
---
296+
biography: |
297+
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.
298+
husband: Tim
299+
name: John
300+
---
301+
`,
302+
options: {
303+
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
304+
},
305+
},
306+
{ // accounts for https://github.com/platers/obsidian-linter/issues/1258
307+
testName: 'Make sure that folded block scalars are not broken up when sorting',
308+
before: dedent`
309+
---
310+
aliases: []
311+
tags:
312+
- media/podcast/episode
313+
description: >-
314+
Follow our ad-free Rain Playlist here:
315+
image: 'https://i.scdn.co/image/ab6765630000ba8a8d796ac81fdad1d895dd28a1'
316+
links:
317+
- https://open.spotify.com/episode/1LSnoZVPWB8ynOCMCwKw5S
318+
showName: ASMR Rain Recordings
319+
created: 11-05-2024 21:09
320+
updated: 13-01-2025 08:16
321+
---
322+
`,
323+
after: dedent`
324+
---
325+
aliases: []
326+
created: 11-05-2024 21:09
327+
description: >-
328+
Follow our ad-free Rain Playlist here:
329+
image: 'https://i.scdn.co/image/ab6765630000ba8a8d796ac81fdad1d895dd28a1'
330+
links:
331+
- https://open.spotify.com/episode/1LSnoZVPWB8ynOCMCwKw5S
332+
showName: ASMR Rain Recordings
333+
tags:
334+
- media/podcast/episode
335+
updated: 13-01-2025 08:16
336+
---
337+
`,
338+
options: {
339+
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
340+
},
341+
},
342+
{ // accounts for https://github.com/platers/obsidian-linter/issues/660
343+
testName: 'Make sure that comments on an array do not cause issues when sorting',
344+
before: dedent`
345+
---
346+
Ingredients: # [\`<free text for ingredient>\`,\`<amount>\`, \`<unit>\`, \`<form>\`, \`<note>\`]
347+
- [Watermelon, 80 g, cubed, note]
348+
- [sugar, 20 g]
349+
---
350+
`,
351+
after: dedent`
352+
---
353+
Ingredients: # [\`<free text for ingredient>\`,\`<amount>\`, \`<unit>\`, \`<form>\`, \`<note>\`]
354+
- [Watermelon, 80 g, cubed, note]
355+
- [sugar, 20 g]
356+
---
357+
`,
358+
options: {
359+
yamlSortOrderForOtherKeys: 'Ascending Alphabetical',
360+
},
361+
},
202362
],
203363
});

package-lock.json

Lines changed: 16 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@types/diff": "^5.0.9",
3232
"@types/diff-match-patch": "^1.0.32",
3333
"@types/jest": "^29.5.12",
34-
"@types/js-yaml": "^4.0.5",
3534
"@types/node": "^20.11.28",
3635
"@typescript-eslint/eslint-plugin": "^7.2.0",
3736
"@typescript-eslint/parser": "^7.2.0",
@@ -61,7 +60,6 @@
6160
"@popperjs/core": "^2.11.6",
6261
"async-lock": "^1.4.1",
6362
"diff-match-patch": "^1.0.5",
64-
"js-yaml": "^4.1.0",
6563
"loglevel": "^1.9.1",
6664
"mdast-util-from-markdown": "^2.0.0",
6765
"mdast-util-frontmatter": "^2.0.1",
@@ -75,6 +73,7 @@
7573
"moment-parseformat": "^4.0.0",
7674
"quick-lru": "^7.0.0",
7775
"ts-dedent": "^2.2.0",
78-
"unist-util-visit": "^5.0.0"
76+
"unist-util-visit": "^5.0.0",
77+
"yaml": "^2.7.0"
7978
}
8079
}

0 commit comments

Comments
 (0)