Skip to content

fix: keep a multi-line value of a hanging list on the line after the previous value - #913

Merged
dsherret merged 1 commit into
mainfrom
fix-array-hanging-binary-stability
Nov 10, 2026
Merged

dsherret merged 1 commit into
mainfrom
fix-array-hanging-binary-stability

Conversation

@dsherret

Copy link
Copy Markdown
Member

Fixes output that changed when formatted a second time in hanging lists (ex. arrayExpression.preferHanging: always or arguments.preferHanging: always). At lineWidth: 40:

const t = [1, aaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbb + ccccccccccc, 2];

was formatted as:

const t = [1,
    aaaaaaaaaaaaaaaaaaa
    + bbbbbbbbbbbbbbbbbbbbbb
    + ccccccccccc, 2];

and formatting that again gave:

const t = [1, aaaaaaaaaaaaaaaaaaa
    + bbbbbbbbbbbbbbbbbbbbbb
    + ccccccccccc, 2];

A value that doesn't fit beside the previous value is moved to the next line before it's broken up. Its line breaks are then kept the next time (ex. the ones between the operands of a binary expression), so its first line fits beside the previous value and it was moved back. The same happened with conditional expressions, member expressions, and calls with arguments that break.

Now a value of a hanging list that's on the line after the previous value in the source stays there when it's multi-line. A value on a single line is still moved beside the previous value, and so is a value that's allowed to be inline multi-line (ex. a function), which keeps call(1,\n function() { becoming call(1, function() {.

Notes

  • Both forms are now stable: a multi-line value stays on the line it's written on.
  • This is done in the plugin with a condition that looks ahead to the end of the value. It could instead be done in the hanging path of gen_separated_values in dprint-core, which would need a new input per value.
  • An arrow function with parameters that break in a hanging list still changes on a second format, because it's allowed to be inline multi-line.

@dsherret
dsherret merged commit 384cd93 into main Nov 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant