Add option to no-unused-vars when using object spreads to omit properties
See original GitHub issueWhat version of ESLint are you using? 2.13.1
What rule do you want to change?
I’d like to propose a new option to the no-unused-vars
rule that does not flag variables used in situations when using the Object Spread Properties when omitting properties while copying objects.
The ES proposal for the Stage 2 Object Rest/Spread Properties enhancement can be found here: https://github.com/sebmarkbage/ecmascript-rest-spread
What code should be flagged as correct with this change?
The following code has an object data
that will eventually reach a point where I’d like to copy the object and omit specific properties. In this case I’m copying the properties into copiedData
and omitting property one
.
let data = {one: 1, two: 2, three: 3};
//...
let {one, ...copiedData} = data;
What happens when the rule is applied to this code now? It will specify one as an unused variable. While this is true, having an option to disregard unused variables when used with an omit pattern would be great to have. One area that I’ve used this pattern quite often is in React when passing properties from one component to the next and omitting properties along the way.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:16 (8 by maintainers)
Top GitHub Comments
Just wanted to also give a heads up that apparently this pattern is getting recommended in the React documentation as well: https://facebook.github.io/react/warnings/unknown-prop.html
Awesome, thanks for editing your post. Seems reasonable to me as long as it’s been behind an option. Let’s see what the team thinks.
To clarify: I’m 👍 for this contingent on it being behind an option.