ES2015 destructiring assignment with renaming causes key-spacing
See original GitHub issueI’m seeing this key-spacing error for reassignment during destructuring, as done here :
I accept that it might be considered appropriate to add a space after the colon, as in the case of a key/value pair, but the wording of the error is a little misleading since it isn’t a key/value pair. Is it worth rewording the error message, or at least adding such an example to the docs so people can see it is not a mistake?
Tell us about your environment
- ESLint Version: v3.19.0
- Node Version: v7.8.0
- npm Version: 4.2.0
What parser (default, Babel-ESLint, etc.) are you using? ?
Please show your full configuration:
{
"extends": ["eslint:recommended", "google"],
"env": {
"browser": true,
"es6": true
},
"plugins": [
"html"
],
"rules": {
"no-var": "off",
"new-cap": ["error", { "capIsNewExceptions": ["Polymer", "PolymerRedux"] }],
"no-console": ["error", { "allow": ["info", "warn", "error"] }]
},
"globals": {
"Polymer": true
},
"parserOptions": {
"ecmaVersion": 6
}
}
What did you do? Please include the actual source code causing the issue.
let {b:c} = {a: 1};
What did you expect to happen? Nothing: ie is it acceptable for there to be no space after the ‘:’ when renaming during destructuring, or: A relevant, helpful error message, such as ‘Missing space before assigned variable in destructuring’ - I’m sure there is something better than that.
What actually happened? Please include the actual, raw output from ESLint.
1:8 error Missing space before value for key 'b' key-spacing
1:8 error 'c' is assigned a value but never used no-unused-vars
✖ 2 problems (2 errors, 0 warnings)
The current message is un-intuitive (imo) since it references a key-value pair, and this isn’t that.
Tagging @btmills, as requested.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:10 (5 by maintainers)
Top GitHub Comments
Any update on this? I would like to be able to enforce a structure like this:
I think disallowing the space after the colon for the renamed variable makes it more clear that it’s a renamed variable and not a value in a key-value pair.
@davidmaxwaterman here’s a less contrived example:
Check out nested object destructuring on MDN.