Incorrect comma-dangle error shown when using object rest/spread.
See original GitHub issue- ESLint Version: 4.3.0
- Node Version: 6.1.0.0
- npm Version: 3.10.10 What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
Configuration
{
"env": {
"es6": true,
"browser": true,
},
"extends": "airbnb",
"plugins": [],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalDecorators": true
}
},
"globals": {
"SyntheticInputEvent": true,
"SyntheticKeyboardEvent": true,
},
"rules": {
"indent": ["error", 4, {
"SwitchCase": 1
}],
"space-before-function-paren": ["error", "always"],
"react/jsx-filename-extension": [1, {
"extensions": [".js", ".jsx"]
}],
"react/jsx-indent": [2, 4],
"react/jsx-indent-props": [2, 4],
"import/no-unresolved": [2, {
"ignore": ['^rdx', '^app', '^utils']
}],
"react/sort-comp": [0],
"import/no-extraneous-dependencies": [0],
"import/prefer-default-export": [0],
"import/extensions": [0],
"no-return-assign": [2, "except-parens"],
"no-unneeded-ternary": ["error", {
"defaultAssignment": true
}],
"valid-typeof": [0],
"jsx-a11y/href-no-hash": "off",
"jsx-a11y/label-has-for": "off",
"class-methods-use-this": "off",
"no-class-assign": "off",
"linebreak-style": ["warn", "unix"]
}
}
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
const mapStateToProps = (
state,
{
id,
type,
...post, // <- ESLint says this comma shouldn't be here
},
) => ({
liked: true,
...post,
});
./node_modules/.bin/eslint path/to/file.js
What did you expect to happen? No errors.
What actually happened? Please include the actual, raw output from ESLint.
6:16 error Unexpected trailing comma comma-dangle
1 problem (1, error, 0 warnings)
1 error, 0 warnings potentially fixable with the `--fix` option.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
comma-dangle - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Why (and How Can I FIx) ESLint import/no-extraneous ...
As far as I can tell, there is no issue with your package.json, so it has to be a syntax problem. I don't...
Read more >ESLint | John Vincent
I chose to install and use the Visual Studio Code extension Prettier ... const sortObject = obj => Object.keys(obj).sort().reduce((res, ...
Read more >eslint-config-nicestyle - npm package - Snyk
An important project maintenance signal to consider for eslint-config-nicestyle is that it hasn't seen any new versions released to npm in the past...
Read more >List of available rules - ESLint - Pluggable JavaScript linter
Possible Errors. These rules relate to possible syntax or logic errors in JavaScript code: ... require using Error objects as Promise rejection reasons....
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
Sure, but I don’t think it makes sense to use invalid JavaScript instead of valid JavaScript just for visual consistency. Presumably, you will need to run your code at some point, and JavaScript engines can only run valid JavaScript code.
I don’t think it would make sense to add an option that would encourage users to write invalid JavaScript. Of course, you could create a plugin that does this if you’d like, so that you could enforce it on an existing codebase (provided that you’re using a parser that also handles invalid trailing commas.)
It’s a purely stylistic thing, and of course, I understand all the arguments to the contrary. It’s simply that the comma looks good and consistent, and seems logical. Visual consistently is important because when attempting to add lint rules to an existing code base and modify others’ behaviors, forcing developers to think causes them to resist the lint rules 😃