-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
feat(eslint-plugin): add new rule no-misused-promises #612
feat(eslint-plugin): add new rule no-misused-promises #612
Conversation
Codecov Report
@@ Coverage Diff @@
## master #612 +/- ##
==========================================
+ Coverage 94.33% 94.43% +0.09%
==========================================
Files 111 112 +1
Lines 4593 4672 +79
Branches 1268 1286 +18
==========================================
+ Hits 4333 4412 +79
Misses 149 149
Partials 111 111
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thanks for doing this
awesome! great work - thanks for the contribution. |
Related (but a few months late): |
Adds a new
no-misused-promises
rule as discussed previously in #508. Fixes #508Some notes about the implementation:
Trying to determine the type of the parameter for which an argument is provided was harder than I expected. The only way I could find to make it work was to enumerate the call signatures of the function being called and matching argument and parameter by index. This can potentially be problematic for functions with many overloads or rest params, but the rule is conservative enough that there should be no false positives in such cases.
I ended up making the conditional check apply to any situation where the truthiness/falsiness check could end up swallowing a promise. I can't think of any valid use cases where the checks that I have placed will trigger, but I did carve out a case so that code like
const foo = someCheck || promise;
won't be flagged due to short-circuit evaulation.There was no entry in
RuleListener
forLogicalExpression
, so I added it to the type and everything seemed to work. I'm assuming this was just an omission from the type.