No trailing comma for function calls with only a single argument
See original GitHub issueThis is a formatting request. When I enable trailingCommas: 'all'
it always bothers me that Prettier adds a trailing comma to a function call with a single item. I think it would look aesthetically better if Prettier did not include a trailing comma only for function calls with a single argument. Below are two examples of code I wish didn’t include the trailing comma.
Prettier 1.18.2 Playground link
--parser babylon
--trailing-comma all
Input:
client.execute(Post.selectAll().where(Post.id.eq(42)).where(Post.published.eq(true)));
array.map(item => item.reallyReallyReallyReallyReallyReallyReallyReallyLongMethodName());
Output:
client.execute(
Post.selectAll()
.where(Post.id.eq(42))
.where(Post.published.eq(true)),
);
array.map(item =>
item.reallyReallyReallyReallyReallyReallyReallyReallyLongMethodName(),
);
Desired behavior:
client.execute(
Post.selectAll()
.where(Post.id.eq(42))
.where(Post.published.eq(true))
);
array.map(item =>
item.reallyReallyReallyReallyReallyReallyReallyReallyLongMethodName()
);
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Why is a trailing comma in a function call not a syntax error?
Most languages accept trailing commas in comma-separated lists like argument lists or tuple or array literals. This is helpful if you split ...
Read more >PHP 7.3: Allow trailing comma in function and method calls
This is a simple change, which suggests allowing trailing commas in function and method calls. This does not affect declarations.
Read more >Trailing commas - JavaScript - MDN Web Docs
JavaScript allows trailing commas wherever a comma-separated list of values is accepted and more values may be expected after the last item.
Read more >Best practices for using trailing commas in JavaScript
A trailing comma, also known as a dangling or terminal comma, is a comma symbol that is typed after the last item of...
Read more >Trailing comma for function arguments and call parameters
Thing to note: rest params. After the rest there should be no trailing comma in the function arguments list, but still can be...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Do you mind explaining why the number of arguments should matter here? The argument I usually see for enforcing trailing commas is to minimize diff noise, and it feels like doing this would defeat the purpose of using trailing commas at all.
I don’t think we can accept this, we print
,
for array and objectsPrettier 2.0.5 Playground link
Input:
Output: