-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add new rule require-await #674
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 require-await #674
Conversation
Codecov Report
@@ Coverage Diff @@
## master #674 +/- ##
==========================================
- Coverage 94.43% 94.41% -0.02%
==========================================
Files 112 113 +1
Lines 4672 4711 +39
Branches 1286 1293 +7
==========================================
+ Hits 4412 4448 +36
- Misses 149 150 +1
- Partials 111 113 +2
|
9b2d736 to
edf4614
Compare
JamesHenry
left a comment
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.
Nicely done, thank you!
bradzacher
left a comment
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.
few nits, otherwise LGTM.
Thanks for doing this, this is a great addition.
edf4614 to
d3d7830
Compare
|
unless github is glitching out on me, it looks like your push didn't push any changes. |
d3d7830 to
ab16eac
Compare
|
Sorry @bradzacher, minor brain explosion here. Should be OK now. |
|
I think this rule missed await-less arrow functions: OKasync function foo() {
return Promise.resolve();
}Not OKconst foo = () => Promise.resolve(); |
Extends the
require-awaitrule from ESlint core to allow for async functions that explicitly return a promise (as opposed to a non-promise value that theasyncfunction implicitly wraps inPromise.resolve).To recap, the main intent of the
require-awaitrule in ESlint core is guard against marking a function asasyncunnecessarily. The presence of anawaitexpression is the signal used to determine ifasyncis necessary.However, when used in conjunction with:
@typescript-eslint/promise-function-async, which requires all functions that return a promise to be marked asasync; andno-return-await, which warns against usingreturn await..there is an unresolvable conflict.
Fixes #669
Examples of newly allowed code
The above function would normally generate a warning from
require-await:Similarly:
The above
asyncfunctionnumberOnereturns the result of anotherasyncfunctiongetAsyncNumber, which would normally trigger two warnings.Aside from this one specific case, the rule passes through to ESLint core
require-awaitfor everything else, so the following still applies:Examples of valid code
Examples of invalid code