From 9e0ec3fcee8c482ca9233aeea5f455a1352b0e09 Mon Sep 17 00:00:00 2001 From: Pachat-Kas Date: Sat, 10 Oct 2026 05:36:54 +0200 Subject: [PATCH 1/5] fix extra line for tags and anchors --- src/compose/resolve-props.ts | 2 +- tests/tag-fixer.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/tag-fixer.ts diff --git a/src/compose/resolve-props.ts b/src/compose/resolve-props.ts index 2780ba98..227d572c 100644 --- a/src/compose/resolve-props.ts +++ b/src/compose/resolve-props.ts @@ -100,7 +100,7 @@ export function resolveProps( case 'newline': if (atNewline) { if (comment) comment += token.source - else if (!found || indicator !== 'seq-item-ind') spaceBefore = true + else if (!found || indicator !== 'seq-item-ind') if(!tag && !anchor) spaceBefore = true } else commentSep += token.source atNewline = true hasNewline = true diff --git a/tests/tag-fixer.ts b/tests/tag-fixer.ts new file mode 100644 index 00000000..d31c3869 --- /dev/null +++ b/tests/tag-fixer.ts @@ -0,0 +1,11 @@ +import { parseDocument, stringify } from 'yaml' + +test('tag test', () => { + const broken = ` +- x: !!null + +- y +`; + + expect(stringify(parseDocument(broken))).toEqual(broken) +}) \ No newline at end of file From b1b4f3f5207c1dd925541c57ef50b880fcc6e843 Mon Sep 17 00:00:00 2001 From: Pachat-Kas Date: Sat, 10 Oct 2026 05:42:43 +0200 Subject: [PATCH 2/5] wah weh woh, don't do if's like I do --- src/compose/resolve-props.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compose/resolve-props.ts b/src/compose/resolve-props.ts index 227d572c..ef619200 100644 --- a/src/compose/resolve-props.ts +++ b/src/compose/resolve-props.ts @@ -100,7 +100,7 @@ export function resolveProps( case 'newline': if (atNewline) { if (comment) comment += token.source - else if (!found || indicator !== 'seq-item-ind') if(!tag && !anchor) spaceBefore = true + else if ((!found || indicator !== 'seq-item-ind') && (!tag && !anchor)) spaceBefore = true } else commentSep += token.source atNewline = true hasNewline = true From a7715e840913f866e63beeee1aaaf13e1440a7f9 Mon Sep 17 00:00:00 2001 From: Pachat-Kas Date: Sat, 10 Oct 2026 05:46:49 +0200 Subject: [PATCH 3/5] add this thing too I guess. --- src/stringify/stringify.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stringify/stringify.ts b/src/stringify/stringify.ts index 81c109ce..5cf11c12 100644 --- a/src/stringify/stringify.ts +++ b/src/stringify/stringify.ts @@ -192,6 +192,6 @@ export function stringify( : node.toString(ctx, onComment, onChompKeep) if (!props) return str return node instanceof Scalar || str[0] === '{' || str[0] === '[' - ? `${props} ${str}` + ? str !== "" ? `${props} ${str}` : props+"\n" : `${props}\n${ctx.indent}${str}` } From a427c8a8a30a4b3a1cd10a8db1f6a788d3454ad5 Mon Sep 17 00:00:00 2001 From: Pachat-Kas Date: Sat, 10 Oct 2026 05:49:18 +0200 Subject: [PATCH 4/5] pinky promise, I know what I'm doing --- tests/tag-fixer.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/tag-fixer.ts b/tests/tag-fixer.ts index d31c3869..5a664b5d 100644 --- a/tests/tag-fixer.ts +++ b/tests/tag-fixer.ts @@ -1,8 +1,7 @@ import { parseDocument, stringify } from 'yaml' test('tag test', () => { - const broken = ` -- x: !!null + const broken = `- x: !!null - y `; From d9578933996369763be7c1bb966fe644ba394328 Mon Sep 17 00:00:00 2001 From: Pachat-Kas Date: Sat, 10 Oct 2026 10:44:10 +0200 Subject: [PATCH 5/5] make things pretty, please --- src/compose/resolve-props.ts | 3 ++- src/stringify/stringify.ts | 4 +++- tests/tag-fixer.ts | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compose/resolve-props.ts b/src/compose/resolve-props.ts index ef619200..d00fe52e 100644 --- a/src/compose/resolve-props.ts +++ b/src/compose/resolve-props.ts @@ -100,7 +100,8 @@ export function resolveProps( case 'newline': if (atNewline) { if (comment) comment += token.source - else if ((!found || indicator !== 'seq-item-ind') && (!tag && !anchor)) spaceBefore = true + else if ((!found || indicator !== 'seq-item-ind') && !tag && !anchor) + spaceBefore = true } else commentSep += token.source atNewline = true hasNewline = true diff --git a/src/stringify/stringify.ts b/src/stringify/stringify.ts index 5cf11c12..aff50283 100644 --- a/src/stringify/stringify.ts +++ b/src/stringify/stringify.ts @@ -192,6 +192,8 @@ export function stringify( : node.toString(ctx, onComment, onChompKeep) if (!props) return str return node instanceof Scalar || str[0] === '{' || str[0] === '[' - ? str !== "" ? `${props} ${str}` : props+"\n" + ? str !== '' + ? `${props} ${str}` + : props + '\n' : `${props}\n${ctx.indent}${str}` } diff --git a/tests/tag-fixer.ts b/tests/tag-fixer.ts index 5a664b5d..99886c06 100644 --- a/tests/tag-fixer.ts +++ b/tests/tag-fixer.ts @@ -4,7 +4,7 @@ test('tag test', () => { const broken = `- x: !!null - y -`; +` expect(stringify(parseDocument(broken))).toEqual(broken) -}) \ No newline at end of file +})