Version 3.8.0 comma-dangle breaks Flowtype annotations when a object rest parameter is used
See original GitHub issueTell us about your environment
- ESLint Version: v3.8.0
- Node Version: v6.7.0
- npm Version: 3.10.3
What parser (default, Babel-ESLint, etc.) are you using? Babel-ESLint
Please show your full configuration:
.eslintrc.js
module.exports = {
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true
},
"plugins": [
"flowtype",
"flow-vars"
],
"extends": "eslint:recommended",
"rules": {
"comma-dangle": [
"error",
"always-multiline"
],
}
};
.babelrc
{
"plugins": [
"transform-flow-comments",
"transform-function-bind",
"transform-async-to-generator",
"transform-exponentiation-operator",
"transform-class-properties",
"transform-es2015-destructuring",
"transform-es2015-spread",
"transform-es2015-parameters",
"transform-object-rest-spread",
"transform-es2015-classes",
"transform-es2015-modules-commonjs"
]
}
What did you do? Please include the actual source code causing the issue. I created a “minimal” demo to reproduce the problem. My impression is that since 3.8.0 (it works on 3.7.1) comma-dangle (set to always-multiline) reports a comma in a flow annotation when a object rest parameter is used before.
Complete demo code: https://gist.github.com/mormahr/e6af53438a9bae9b9fe8905cc938b77d
export default class AntragsEvent {
id: ?string
rest: any
constructor({
id,
...rest, // <- this (the object rest spread) is causing
}: {
id?: string, // <- this comma to be reported by comma-dangle
}) {
this.id = id
this.rest = rest
}
}
What did you expect to happen? No report of an unexpected comma
What actually happened? Please include the actual, raw output from ESLint.
[PRIVATE]/CommaDangleBug/test.js 9:14 error Unexpected trailing comma comma-dangle
✖ 1 problem (1 error, 0 warnings)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:9 (7 by maintainers)
Top GitHub Comments
I understand that you’re using babel, but a trailing comma after a rest property is not valid syntax even according to the current proposal spec, because there is nothing that could follow a rest property.
The same thing applies with the already-standardized rest elements:
In order to be more compliant with the spec, babel’s parser temporarily reported this as a syntax error, but it was later reverted due to breakage.
The fix in this case is to simply remove the comma, so that it becomes valid syntax according to the Stage 3 proposal.
For what it’s worth, I think your syntax is invalid based on the current version of the rest/spread spec; trailing commas aren’t allowed after rest properties, since no property could actually be added after it. (See https://github.com/eslint/eslint/issues/7297 for more info.)
Does the problem go away if you remove that comma?