Skip to content
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

Breaking: no-unused-vars reports all after-used params (fixes #9909) #10119

Merged
merged 3 commits into from
Apr 13, 2018

Conversation

platinumazure
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

See #9909.

What changes did you make? (Give an overview)

The no-unused-vars rule was changed some time ago (likely unintentionally) to only report the last unused parameter when using the args: "after-used" setting. This resulted in poor UX in the case of a function with multiple unused parameters after the last used parameter, because ESLint would only report one parameter, and then report another parameter after the user fixed the first reported parameter.

This change simplifies the args: "after-used" logic by using this simple algorithm to check if a parameter is "after used parameters": If there exists at least one parameter (declared after the one being examined) which has at least one reference, then the parameter being examined is not "after the last used parameter" and so it shouldn't be reported. This approach allows for multiple parameters to be reported, as needed.

Is there anything you'd like reviewers to focus on?

  • Do we need any new unit tests to cover destructuring cases that are not covered well enough right now?
  • Any suggestions for improving the new description I've put in the documentation?

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Mar 23, 2018
@platinumazure platinumazure added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion breaking This change is backwards-incompatible and removed triage An ESLint team member will look at this issue soon labels Mar 23, 2018
Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestions for improving the new description I've put in the documentation?

I had one idea, let me know what you think!

Code LGTM, and test coverage looks to be sufficient.

@@ -150,7 +150,7 @@ console.log(secondVar);

The `args` option has three settings:

* `after-used` - only the last argument must be used. This allows you, for instance, to have two named parameters to a function and as long as you use the second argument, ESLint will not warn you about the first. This is the default setting.
* `after-used` - unused arguments that occur before the last used argument will not be checked, but all other arguments (including after the last used argument) will be checked.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about this tweak?

"Unused positional arguments that occur before the last used argument will not be checked, but all named arguments and all positional arguments after the last used argument will be checked."

@platinumazure
Copy link
Member Author

@btmills Rebased and pushed an extra commit with your suggested wording, please review at your convenience. Thanks!

Copy link
Member

@btmills btmills left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice work!

@platinumazure platinumazure merged commit 2324570 into master Apr 13, 2018
@platinumazure platinumazure deleted the no-unused-vars-after-used branch April 13, 2018 03:43
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Oct 11, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Oct 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion breaking This change is backwards-incompatible bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants