From ad763fd5ba051356205b3b988f7dbc65366a6c57 Mon Sep 17 00:00:00 2001 From: no92 Date: Mon, 12 Feb 2024 19:59:55 +0100 Subject: [PATCH] fix: use the `lineWidth` option for line breaking in flow collections This should address issues #288 and #507. --- src/stringify/stringifyCollection.ts | 2 +- tests/doc/stringify.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stringify/stringifyCollection.ts b/src/stringify/stringifyCollection.ts index a572718d..70b65909 100644 --- a/src/stringify/stringifyCollection.ts +++ b/src/stringify/stringifyCollection.ts @@ -148,7 +148,7 @@ function stringifyFlowCollection( } else { if (!reqNewline) { const len = lines.reduce((sum, line) => sum + line.length + 2, 2) - reqNewline = len > Collection.maxFlowStringSingleLineLength + reqNewline = ctx.options.lineWidth !== 0 && len > ctx.options.lineWidth } if (reqNewline) { str = start diff --git a/tests/doc/stringify.ts b/tests/doc/stringify.ts index a094203a..8140dd13 100644 --- a/tests/doc/stringify.ts +++ b/tests/doc/stringify.ts @@ -616,7 +616,7 @@ describe('scalar styles', () => { y, n ]\n` - expect(String(doc)).toBe(str) + expect(doc.toString({ lineWidth: 1 })).toBe(str) expect(YAML.parse(str)).toEqual([ true, false,