Skip to content

Commit 534d8ad

Browse files
committed
fix: Ignore minContentWidth if greater than lineWidth (fixes #562)
1 parent f73e1d9 commit 534d8ad

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

docs/03_options.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Used by: `stringify()` and `doc.toString()`
161161
| indent | `number` | `2` | The number of spaces to use when indenting code. Should be a strictly positive integer. |
162162
| indentSeq | `boolean` | `true` | Whether block sequences should be indented. |
163163
| lineWidth | `number` | `80` | Maximum line width (set to `0` to disable folding). This is a soft limit, as only double-quoted semantics allow for inserting a line break in the middle of a word. |
164-
| minContentWidth | `number` | `20` | Minimum line width for highly-indented content (set to `0` to disable). |
164+
| minContentWidth | `number` | `20` | Minimum line width for highly-indented content (set to `0` to disable). Ignored if greater than lineWidth. |
165165
| nullStr | `string` | `'null'` | String representation for `null` values. |
166166
| simpleKeys | `boolean` | `false` | Require keys to be scalars and always use implicit rather than explicit notation. |
167167
| singleQuote | `boolean ⎮ null` | `null` | Use 'single quote' rather than "double quote" where applicable. Set to `false` to disable single quotes completely. |

src/stringify/foldFlowLines.ts

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function foldFlowLines(
5151
}: FoldOptions = {}
5252
) {
5353
if (!lineWidth || lineWidth < 0) return text
54+
if (lineWidth < minContentWidth) minContentWidth = 0
5455
const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length)
5556
if (text.length <= endStep) return text
5657
const folds = []

tests/doc/stringify.ts

+7
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,13 @@ describe('lineWidth', () => {
920920
"[ 'Sed', 'ut', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error', 'sit', 'voluptatem', 'accusantium', 'doloremque', 'laudantium,', 'totam' ]\n"
921921
)
922922
})
923+
924+
test('less than minContentWidth (eemeli/yaml#562)', () => {
925+
const doc = YAML.parseDocument('>\ntest test test test test')
926+
expect(doc.toString({ lineWidth: 18, minContentWidth: 20 })).toBe(
927+
'>\ntest test test\ntest test\n'
928+
)
929+
})
923930
})
924931

925932
describe('collectionStyle', () => {

0 commit comments

Comments
 (0)