Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[no-unused-vars]: reporter should report the last reference instead of declaration

See original GitHub issue

What 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


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 :,

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:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

Lonniebizcommented, Apr 26, 2020

This bug confused me (as shown in 13227).

// esLint version 6.7.2
async function fnTest()
	return "Promise will resolve to this string.";
async function main()
	let usedVariable = fnTest(); // esLint thinks usedVariable is unused
	// Omitted: Do other things before awaiting usedVariable
	usedVariable = await usedVariable; // this reassignment is what is unused (not the first line of this function as reported by eslint)

eslint reports line 1 of main() as unused, but it is actually line 3 of main() 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.

anikethsahacommented, May 25, 2020

I have submitted the PR to move this issue forward quickly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting @typescript-eslint/no-unused-vars warning occurs ...
The error can be resolved by adding the 'include' property. include specifies an array of filenames or patterns to include in the program....
Read more >
no-unused-vars - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Tasks in Visual Studio Code
VS Code supports variable substitution inside strings in the tasks.json file and you can see a full list of predefined variables in the...
Read more >
EBA XBRL Filing Rules version 5.2
Rule. Unused contexts (contexts which are not referred to by facts) clutter the report and add no value to either supervisor or reporter...
Read more >
25.6.1 Statute of Limitations Processes and Procedures - IRS
For reports concerning quality, inventory and aged listing, please refer to ... The clearing of an original tax return does not involve any...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found