fix: add trailing comma after wrapped arrow expression body in call (#696)#789
Open
todor-a wants to merge 2 commits into
Open
fix: add trailing comma after wrapped arrow expression body in call (#696)#789todor-a wants to merge 2 commits into
todor-a wants to merge 2 commits into
Conversation
…print#696) `gen_parameters_or_arguments` has a special branch for single-argument calls whose argument is an arrow function with an expression body. When the body wraps the call across lines, the branch emitted a plain `Signal::NewLine` before the closing paren, never a comma — so: ["a", "b", "c"].map(value => value == "a long paragraph" ) …stayed comma-less even with `trailingCommas: always`. Emit `,` in that conditional branch when `trailingCommas` resolves to `always`. `onlyMultiLine` keeps its previous behavior to avoid churn for the default config; switching it would update many existing specs and could be revisited separately.
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.
Fixes #696.
Transparency note: This PR was prepared with AI assistance (Claude).
Problem
With
trailingCommas: always:…formats to (no comma after the arrow body):
Issue reports the expected output should be:
Root cause
gen_parameters_or_arguments(src/generation/generate.rs) has a special branch for calls with a single argument that is an arrow function with an expression body:When the arrow body forces the call onto multiple lines, the true branch emits a bare
Signal::NewLinebefore the closing paren — no comma, regardless oftrailingCommas. The fallthroughgen_separated_valuesbranch (which honorstrailingCommasviaseparator: trailing_commas.into()) is bypassed.Fix
Inject
,into the true branch whentrailingCommasresolves toalways:Scope is limited to
always.onlyMultiLinekeeps existing behavior — extending it would update several existing specs (issue105, issue165, JsxElement_MultiLineParens_Never, Arguments_SpaceAround_True) and might surprise users running the default config. Could be revisited as a follow-up.Tests
Corner-case probe also based on prettier's tests/format/js/trailing-comma (function-calls.js, dynamic-import.js, jsx.js).