"comma-dangle": [2, "always-multiline"] should not add trailing commas to function arguments
See original GitHub issuehttp://eslint.org/docs/rules/comma-dangle#options
According to the eslint docs, “always-multiline” ignores functions by default. I believe that means that prettier-eslint should set prettier’s --trailing-comma
option to es5
rather than all
, unless functions: "always"
is specified in eslint.
Relevant eslint config:
{
"rules": {
"comma-dangle": [2, "always-multiline"],
}
}
Prettier command:
prettier --single-quote --no-semi --trailing-comma es5
Unformatted:
function someFunction(longParamater1, longParamater2, longParamater3, longParamater4) {
return ''
}
Prettier + eslint --fix
output:
function someFunction(
longParamater1,
longParamater2,
longParamater3,
longParamater4 // no comma
) {
return ''
}
Prettier-eslint output:
function someFunction(
longParamater1,
longParamater2,
longParamater3,
longParamater4, // comma
) {
return ''
}
Edit:
It is possible to fix it using prettier-eslint --prettier.trailing-comma es5
, but those options aren’t available when using prettier-atom.
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
comma-dangle - ESLint - Pluggable JavaScript Linter
Trailing commas simplify adding and removing items to objects and arrays, since only the lines you are modifying must be touched. Another argument...
Read more >Why you should enforce Dangling Commas for Multiline ...
Personally, I prefer ESLint for JavaScript. Fortunately ESLint has the comma-dangle rule which allows you to enforce dangling commas for multiline statements.
Read more >Why does this trigger comma-dangle rule in eslint?
Based on the airbnb config the rule is setup like this comma-dangle: [2, "always-multiline"] . Acoording to this, The expected code is
Read more >Best practices for using trailing commas in JavaScript
We'll start with the common data types, like arrays and objects, where you can safely add a trailing comma to the end of...
Read more >How to Allow Trailing Commas (Comma-Dangle) With ...
You can lint your TypeScript code and also require formatting rules using the ESLint config file. This config file is typically a .eslintrc...
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 FreeTop 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
Top GitHub Comments
@enriquecaballero Are you trying to get trailing commas for all function arguments? If so, you need to set your eslint config to:
Either of the following will give you trailing commas for everything EXCEPT functions:
Pretty sure setting this in your eslintrc should get you the same results for both prettier-eslint and prettier-eslint-cli. Could be wrong though.
Here’s the code that should change, here’s where you’d add a test case, here’s a free course on how to contribute to OSS (if you’re new to contributing), and here’s our CONTRIBUTING.md.
Cheers!