question-mark
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 produces frequent False Positives Involving Async/Await

See original GitHub issue

Anytime you set a variable equal to the output of an async function and then do some other work before awaiting the returned promise, eslint falsely assumes that the variable is unused, when it actually is used.

Here’s the shortest example I could quickly come up with:

// 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; // <------- Used!
}

This reminds me of a similar issue I reported 8 months ago: https://github.com/eslint/eslint/issues/11967

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Apr 25, 2020

Thanks for clarifying this!

I’m closing this issue as a duplicate of #13181.

1reaction
Lonniebizcommented, Apr 26, 2020

Ok, I’m starting to understand what you guys are telling me.

You all are saying that the real issue is that the wrong line is being reported as unused by eslint and that anytime a reassignment isn’t used, that too is “fair game” for no-unused-var, but it should be properly marked as “unused reassignment” (and the correct line should be reported instead of the one eslint is currently reporting). Yes, indeed, that is what has caused the confusion.

@anikethsaha : I finally understand what you were saying. I agree now; the real issue is #13181. Thanks for your patience.

Let this thread stand as a testament to the confusion #13181 can cause!

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-eslint/no-unused-vars false positive in type ...
Question: What's wrong with this rule and why it triggers in this case. Why eslint recognizes type declaration for functions in types/interfaces ...
Read more >
TransactionScope and Async/Await. Be one with the flow
This is a big problem, as it makes writing asynchronous code involving transactions extremely error-prone. The good news is that as part of...
Read more >
Understanding the Event Loop, Callbacks, Promises, and ...
In this article, you will learn about the event loop, the original way of dealing with asynchronous behavior through callbacks, the updated ...
Read more >
async function - JavaScript - MDN Web Docs - Mozilla
The behavior of async / await is similar to combining generators and promises. Async functions always return a promise. If the return value...
Read more >
Running asynchronous code in Node.js - Pipedream
This step was still trying to run code when the step ended. Make sure you await all Promises, or promisify callback functions. As...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found