Repository navigation
fix: keep a call's arguments on its line when the last is an arrow function whose body breaks inside its parens - #877
Merged
Merged
Conversation
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.
Closes #459
When a call's last argument was an arrow function whose body breaks inside its parens (JSX with
jsx.multiLineParens, or(...) => ({ ... })) and the call didn't fit on one line, every argument went on its own line. Adding a comment inside the parens made it hug instead:Every argument except object and array literals is put in its own line group, so the printer broke before the arrow argument instead of inside its body. With the comment, the parens were already multi-line before anything overflowed, so the arguments hugged the arrow.
Now that kind of arrow is treated like an object or array argument when it's the last argument, and its header (parameters and return type) gets its own line group. So the arguments only go on separate lines when the header doesn't fit:
This also applies to
(...) => ({ ... })bodies. Like prettier, it doesn't hug when the argument before it is also a function (ex.refine((val) => ..., (val) => ({ ... }))), andarguments.preferHanging: alwaysis unchanged.Tests
issue0459.txthas the issue's examples withpreferSingleLine, the object body, a nested call, and cases that keep the arguments on separate lines (the header doesn't fit, the arrow isn't last, the body isn't in parens, the argument before it is a function).issue0459_02.txtcovers the default config, with calls,newand optional calls.issue0459_03.txtcoversarguments.preferHanging: always.