Lax comma-dangle
See original GitHub issueESLint 3.0.0 just disabled this rule in their recommended config:
comma-dangle used to be recommended because Internet Explorer 8 and earlier threw a syntax error when it found a dangling comma on object literal properties. However, Internet Explorer 8 was end-of-lifed in January 2016 and all other active browsers allow dangling commas. As such, we consider dangling commas to now be a stylistic issue instead of a possible error.
I’d suggest to follow suit and drop the error. Dangling commas are supported in arrays, object, and hopefully soon even in function parameters. They also make git diffs smaller:
[
"one"
]
add “two”:
[
- "one"
+ "one",
+ "two",
]
but with a dangling comma:
[
"one",
]
becomes:
[
"one",
+ "two",
]
For this reason I’d prefer the option ["error", "always-multiline"]
but ["error", "only-multiline"]
would be lax enough.
Edit: more reasons below
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:9 (7 by maintainers)
@kevva the point of this issue is to change your opinion on whether you should use the dangle or not.
Besides git, this is also what you can do:
Many practical reasons to use dangling commas, yet we’re stuck with “I don’t like the way it looks”
Dangling commas might look a bit weird at first, it’s true, but I thought of this: (forget code style preconceptions for a moment)
^ No dangling comma. Looks beautiful, commas are symmetrical and natural.
^ hmmm. So-so.
^ Multiline, single element. You wouldn’t do that but it’s still beautiful, symmetrical and it’s valid in xo.
^ Multiline, multiple elements, no dangle. That final element feels off. It doesn’t match the lines above. It looks like you forgot the period at the end of a sentence or the semicolon at the end of a line.
^ Read them line by line and forget the brackets. Finally they all match! 🎉
So:
Now,
always-multiline
means that this also needs a comma:So maybe I’d go for
only-multiline
or perhaps suggest an option likealways-multiline-multielements
to eslint