Skip to content

Commit

Permalink
fix: Ignore minContentWidth if greater than lineWidth (fixes #562)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Jul 24, 2024
1 parent f73e1d9 commit 534d8ad
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/03_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ Used by: `stringify()` and `doc.toString()`
| indent | `number` | `2` | The number of spaces to use when indenting code. Should be a strictly positive integer. |
| indentSeq | `boolean` | `true` | Whether block sequences should be indented. |
| 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. |
| minContentWidth | `number` | `20` | Minimum line width for highly-indented content (set to `0` to disable). |
| minContentWidth | `number` | `20` | Minimum line width for highly-indented content (set to `0` to disable). Ignored if greater than lineWidth. |
| nullStr | `string` | `'null'` | String representation for `null` values. |
| simpleKeys | `boolean` | `false` | Require keys to be scalars and always use implicit rather than explicit notation. |
| singleQuote | `boolean ⎮ null` | `null` | Use 'single quote' rather than "double quote" where applicable. Set to `false` to disable single quotes completely. |
Expand Down
1 change: 1 addition & 0 deletions src/stringify/foldFlowLines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function foldFlowLines(
}: FoldOptions = {}
) {
if (!lineWidth || lineWidth < 0) return text
if (lineWidth < minContentWidth) minContentWidth = 0
const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length)
if (text.length <= endStep) return text
const folds = []
Expand Down
7 changes: 7 additions & 0 deletions tests/doc/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,13 @@ describe('lineWidth', () => {
"[ 'Sed', 'ut', 'perspiciatis', 'unde', 'omnis', 'iste', 'natus', 'error', 'sit', 'voluptatem', 'accusantium', 'doloremque', 'laudantium,', 'totam' ]\n"
)
})

test('less than minContentWidth (eemeli/yaml#562)', () => {
const doc = YAML.parseDocument('>\ntest test test test test')
expect(doc.toString({ lineWidth: 18, minContentWidth: 20 })).toBe(
'>\ntest test test\ntest test\n'
)
})
})

describe('collectionStyle', () => {
Expand Down

0 comments on commit 534d8ad

Please sign in to comment.