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
no-unused-vars produces frequent False Positives Involving Async/Await #13227
Comments
This is an intended behavior but there might need some changes with the location and the message. Hope it helps. |
In async programming, the pattern of doing something else (while waiting on another thing to finish) is so common that I can't see how eslint would consider this "intended behavior". This is a false positive, and in my coding, it is a frequently used technique that gets a lot of stuff done simultaneously (rather than waiting unnecessarily). If this rule is not sophisticated enough to recognize such an obvious and proper use of a variable, as showcased in my example, it needs to either evolve to do so, or be omitted as a default rule, in my opinion. Otherwise, my code files are going to have more instances of To disable this completely, would be a shame, because I am generally interested in being notified of unused variables, but not at the cost of too many false positives, like this rule currently produces. |
This is my opinion, not eslint's. as I may be wrong or missing something about it. you can use the This rule clearly focuses on whether the variable is being used (not self-reassigned) or not. Again, I may miss something so lets hear from others. |
Obviously, the example I've provided is contrived for the purpose of succinctly exemplifying the essence of the issue being reported. In practice, it is indeed the "awaited resolved promise" of I can't emphasize the obvious enough: the variable is used in the vary same written-code-block. Certainly, eslint could evolve to avoid these obvious false positives. How can you say I'm not using that variable? On the vary line I create the variable, I set it to a promise via calling an async function. Later, I update that variable's value to the resolved promise. You say this doesn't count because it is self-reassigned. However, look on the right side of Perhaps eslint should evaluate the code block first, as a whole, before allow its attention to be diverted down the promise rabbit hole. If it did, I appreciate your suggestions, but I cannot appreciate your defense of false positives. |
@Lonniebiz thanks for the issue! I agree that we should improve this rule to show a different message and report the location of the last self-assignment, as proposed in #13181. That being said, the provided example doesn't look like a false positive, because |
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! |
Thanks for clarifying this! I'm closing this issue as a duplicate of #13181. |
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:
This reminds me of a similar issue I reported 8 months ago:
#11967
The text was updated successfully, but these errors were encountered: