Skip to content

fix: keep a call's arguments on its line when the last is an arrow function whose body breaks inside its parens - #877

Merged
dsherret merged 2 commits into
mainfrom
fix-issue-459
Nov 4, 2026
Merged

dsherret merged 2 commits into
mainfrom
fix-issue-459

Conversation

@dsherret

@dsherret dsherret commented Nov 4, 2026

Copy link
Copy Markdown
Member

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:

Array.from(
  { length: 1 },
  (_, i) => (
    <div key={i}>...</div>
  ),
);

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:

Array.from({ length: 1 }, (_, i) => (
  <div key={i}>...</div>
));

This also applies to (...) => ({ ... }) bodies. Like prettier, it doesn't hug when the argument before it is also a function (ex. refine((val) => ..., (val) => ({ ... }))), and arguments.preferHanging: always is unchanged.

Tests

  • issue0459.txt has the issue's examples with preferSingleLine, 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.txt covers the default config, with calls, new and optional calls.
  • issue0459_03.txt covers arguments.preferHanging: always.

@dsherret
dsherret merged commit cc1ed72 into main Nov 4, 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.

preferSingleLine sometimes doesn't collapse arguments, until a comment is added

1 participant