[no-unused-vars]: reporter should report the last reference instead of declaration
See original GitHub issueWhat rule do you want to change?
no-unused-vars
Does this change cause the rule to produce more or fewer warnings? same
How will the change be implemented? (New option, new default behavior, etc.)? default
Please provide some example code that this change will affect: Currently, the reporter reports the location in a declaration of a variable which is fine but not for all cases.
case 1
const unusedVar = 1; // reporting here is ok
case2
let a = 1 // currently its reporting here, reporting here is not ok as `a` has references though its being self referred
a = a + 1;
a = a + 2;
a = a + 3; // it should report here
In this way, it makes easy to track the error if any. Another advantage of reporting this way is many editors do provide shortcut keys to jump to the declaration of any variable/function but the opposite is not true for some.
ref : https://github.com/eslint/eslint/issues/12871, https://github.com/eslint/eslint/issues/13172
What does the rule currently do for this code? reports in the variable declaration
What will the rule do after it’s changed? reports in the last reference of the variable if the variable is being self-referred
Are you willing to submit a pull request to implement this change? Yes
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
This bug confused me (as shown in 13227).
eslint reports line 1 of
main()
as unused, but it is actually line 3 ofmain()
that is unused. eslint should report line 3 of that function-body as “unused reassignment”. To me that seems like the most clear thing to call it.I have submitted the PR https://github.com/eslint/eslint/pull/13354 to move this issue forward quickly.