no-unused-vars produces frequent False Positives Involving Async/Await
See original GitHub issueAnytime 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:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for clarifying this!
I’m closing this issue as a duplicate of #13181.
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!