`comma-dangle` incorrectly requires commas after rest properties
See original GitHub issueWhat rule do you want to change? comma-dangle
Does this change cause the rule to produce more or fewer warnings? I guess it depends. But probably more warnings.
How will the change be implemented? (New option, new default behavior, etc.)?
New option, something like {forbidAfterRest: true}
Please provide some example code that this change will affect:
const {
x,
y,
...z
} = foo;
What does the rule currently do for this code?
When using this rule with string option "always-multiline"
, it will warn about missing trailing comma after ...z
.
What will the rule do after it’s changed?
No trailing comma after ...z
will be correct, and a trailing comma will be incorrect.
Motivation: Seems like the spec doesn’t even allow that kind of trailing comma.
Babel’s Babylon v6.11.3 went so far as to consider that as syntax error.
The rationale for this is that the use case for trailing comma is that you can add something at the end without affecting the line above. Since a RestProperty always has to be the last property it doesn’t make sense.
Babylon v6.11.4 temporary rolled back that behavior.
So for now I guess is up to the user to choose if that trailing comma is incorrect or not with the new forbidAfterRest
option.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
… just to clarify, trailing commas are always permitted after spreads, they’re just never permitted after rests - in both iterable or object destructuring, as well as in function argument signatures.
Whoops, looks like I was a bit careless about that distinction when renaming the issue. (I think the fix does distinguish between rest and spread correctly, though.)