fix(js_formatter): array printing and grouping in arrows #917
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.
Summary
This fix is largely just pulled straight from astral-sh/ruff#6815, which adds a reset to the
PrintMode
for a group whenever it has to get remeasured. The linked PR has a more thorough description, but without this, a group that gets measured, realizes it doesn't fit, and then gets remeasured will always assume that it must print asExpanded
, because the previous measuring will have failed to fit. This just resets that mode toFlat
before attempting to remeasure, ensuring that it will try to fit on a single line first in whatever new context it's being printed in.The other small change in this PR is allowing
JsArrayExpression
to start of the same line when used as the single expression body of an arrow function, like:Previously, the opening bracket would be forced onto a newline, which didn't match the existing behavior for objects, sequences, or block statement bodies.
All of this is starting an attempt to fix
prettier/js/arrows/curried
, but that's proven to be far more complicated.Test Plan
The two snapshot changes show the new diff, reducing incompatibilities with Prettier.