Repository navigation
feat: add arrayExpression.linePerElement option - #739
Merged
Merged
Conversation
Contributor
Author
|
@dsherret I know you may be busy. This PR has been open for a while. Any feedback would help. Thanks |
dsherret
reviewed
Feb 11, 2026
xseman
force-pushed
the
array-expression-max-width
branch
from
November 4, 2026 21:37
9d04925 to
2d2a262
Compare
arrayExpression.maxWidth configurationarrayExpression.linePerElement option
xseman
force-pushed
the
array-expression-max-width
branch
from
November 5, 2026 13:32
2d2a262 to
3f77aea
Compare
When `false`, an array expression whose elements are all literals, identifiers or unary expressions of them maintains the line breaks as written and fits as many elements on each line as the line width allows. Any other array formats as with `true` (the default). Closes dprint#677
xseman
force-pushed
the
array-expression-max-width
branch
from
November 5, 2026 13:50
3f77aea to
69635e1
Compare
… after a newly multi-line one on a new line
…lement # Conflicts: # src/generation/generate.rs
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.
Adds
arrayExpression.linePerElement(defaulttrue, so existing output doesn't change). Whenfalse, an array expression whose elements are all literals, identifiers or unary expressions of them keeps the line breaks as written and fits as many elements on each line aslineWidthallows. Any other array (objects, calls, functions, holes, spreads) formats as withtrue.This replaces the earlier
arrayExpression.maxWidthversion, following the review: nothing is measured from the source text anymore. The elements are generated normally, andgen_array_like_nodessetsmaintain_line_breakson the multi-line options. That's the same mechanismbinaryExpression.linePerExpression: falseuses, so the printer does the wrapping with the formatted widths, comments and blank lines included. The change ingenerate.rsis about 20 lines.Validation:
lineWidth120, 80 and 40. The default output is byte-identical tomain, and withfalseno file becomes unstable or unparseable.Known limitation (in dprint-core): if the array wraps but all its elements would fit on one indented line,
forcedNewLineIfNoNewLineinir_helpers/gen_separated_values.rsmoves the last element to its own line ([\n 1, 2,\n 3,\n]). Skipping that condition whennewline_at_startis set fixes it. With that one-line change, the wrapping matches prettier on all 300 arrays and all the specs here still pass. I can open a dprint PR for it if you'd like.Closes #677
Closes #910