From 5af5d3da01c55ecbadd596babab70fa9db9e47ee Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Mon, 20 Feb 2023 21:39:42 +0100 Subject: [PATCH] fix: Use correct argument order when stringifying flow collection comments (fixes #443) --- src/stringify/stringifyCollection.ts | 2 +- tests/doc/comments.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index 326e3afb..7d9e780a 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -161,7 +161,7 @@ function stringifyFlowCollection( } if (comment) { - str += lineComment(str, commentString(comment), indent) + str += lineComment(str, indent, commentString(comment)) if (onComment) onComment() } return str diff --git a/tests/doc/comments.js b/tests/doc/comments.js index 74130f02..681ae07d 100644 --- a/tests/doc/comments.js +++ b/tests/doc/comments.js @@ -543,6 +543,15 @@ describe('stringify comments', () => { } `) }) + + test('line comment after flow collection (eemeli/yaml#443)', () => { + const doc = YAML.parseDocument(source` + [ value1, value2 ] # comment + `) + expect(String(doc)).toBe(source` + [ value1, value2 ] # comment + `) + }) }) })