Repository navigation
Make WithLineWidth(0) disable line wrapping - #528
Open
antoninbas wants to merge 1 commit into
Open
antoninbas wants to merge 1 commit into
antoninbas wants to merge 1 commit into
Conversation
The WithLineWidth docs say -1 or 0 means unlimited width, but only negative values were normalized to -1. A width of 0 reached the emitter unchanged, and at stream start the emitter replaces any width from 0 to twice the indent with 80. So WithLineWidth(0), and the line-width: 0 option in OptsYAML and the CLI, wrapped at 80 columns. Store any non-positive width as -1 so 0 behaves as documented, and mention 0 in the CLI help for line-width. Reword the comment in isSimpleCollection, since only -1 now reaches its non-positive branch. The options fixture that expected 0 to be stored as-is now expects -1. New Dump fixtures check that widths 0 and -1 both leave long lines unwrapped, and a new CLI test covers -o width=0. Fixes yaml#526 Signed-off-by: Antonin Bas <antonin.bas@gmail.com>
ccoVeille
approved these changes
Nov 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
WithLineWidthdocs say -1 or 0 means unlimited width, but only negative values were normalized to -1. A width of 0 reached the emitter unchanged, and at stream start the emitter replaces any width from 0 to twice the indent with 80. SoWithLineWidth(0), and theline-width: 0option inOptsYAMLand the CLI, wrapped at 80 columns.Store any non-positive width as -1 so 0 behaves as documented, as suggested in #526, and mention 0 in the CLI help for
line-width. Reword the comment inisSimpleCollection, since only -1 now reaches its non-positive branch.The options fixture that expected 0 to be stored as-is now expects -1. New
Dumpfixtures check that widths 0 and -1 both leave long lines unwrapped, and a new CLI test covers-o width=0.Fixes #526
Notes for reviewers
WithLineWidth,OptsYAMLor the CLI): long lines are no longer wrapped at 80. That is the documented behavior, but it may be worth a mention in the next release notes.Emitter.SetWidthis unchanged, so the emitter still follows libyaml (0 means the default of 80). The public API can no longer pass it 0.-o line-width=4wraps at 80 with the default indent of 2). This is not documented.WithFlowSimpleCollections, an unlimited width (-1, and now 0) still limits flow collections to 80 characters (isSimpleCollectionininternal/libyaml/serializer.go), while the option's docs say collections use flow style "if they fit within the line width". This predates this PR. The code could follow the docs, or the docs could mention the 80-character limit; I've only reworded the code comment to describe the current behavior.