-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to no-unused-vars when using object spreads to omit properties #6563
Comments
Hi @basicdays, it looks like you're proposing a rule change. Could you please augment your original post to answer the questions asked on the linked documentation? Thanks! |
Hi @basicdays, thanks for the issue. It looks like there's not enough information for us to know how to help you. If you're reporting a bug, please be sure to include:
Requesting a new rule? Please see Proposing a New Rule for instructions. If it's something else, please just provide as much additional information as possible. Thanks! |
@platinumazure Thanks for pointing that out, I've updated the initial post. |
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. |
Why don't you write it as:
instead? |
@alberto good question. The end goal of this is to actually get all the rest of the props from |
Oh, sorry I didn't read carefully enough and misunderstood the issue. It seems reasonable to me. |
@alberto To use Though I think too early to add an option for the stage 2 proposal. |
Mmm, good point. |
I can certainly understand shelving the idea until the proposal rises to higher stages. For now I've just been doing something like the following example to tell the linter to not flag it: I'd imagine a lot of people are probably going to be using this pattern over time, assuming the proposal doesn't get derailed. :) Is there a way to make it a plugin? I wouldn't mind finally looking at how eslint works if you all want to hold off integrating it into eslint proper. |
Yes, you can copy and alter the rule as a plugin. Closing for now. |
I guess you can use
This is similar to |
Sounds good, I'll look into it. Thanks for the feedback. |
Do we have a 3rd-party solution to this yet? I'd like this feature too. I use object spread to omit vars all the time; it's very common in React. |
Wish I've had time to write something for this, but haven't been able to get into it yet. I haven't looked to see if anyone else have written something yet though. |
What 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 intocopiedData
and omitting propertyone
.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.
The text was updated successfully, but these errors were encountered: