-
-
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
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!
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-await
rule from ESlint core to allow for async functions that explicitly return a promise (as opposed to a non-promise value that theasync
function implicitly wraps inPromise.resolve
).To recap, the main intent of the
require-await
rule in ESlint core is guard against marking a function asasync
unnecessarily. The presence of anawait
expression is the signal used to determine ifasync
is 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
async
functionnumberOne
returns the result of anotherasync
functiongetAsyncNumber
, which would normally trigger two warnings.Aside from this one specific case, the rule passes through to ESLint core
require-await
for everything else, so the following still applies:Examples of valid code
Examples of invalid code