Rule proposal: `prefer-await`
See original GitHub issueThe rule name may be named unicorn/prefer-await
.
This only applies for ES6 code that have the await
keyword available.
Prefer await
over Promise#then()
, Promise#catch()
and Promise#finally()
Prefer using await
operator over Promise#then()
, Promise#catch()
and Promise#finally()
, which is easier to write and to read afterwards.
This rule is fixable.
Fail
await doSomething().then(() => {
// …
});
doSomething().then(() => {
// …
});
await doSomething().catch((err) => {
// …
});
doSomething().catch((err) => {
// …
});
Pass
await doSomething();
try {
await doSomething();
} catch (err) {
// …
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:28 (2 by maintainers)
Top Results From Across the Web
Proposed rule: Order Competition Rule - SEC.gov
proposed rule would prohibit a restricted competition trading center from internally executing certain orders of individual investors at a ...
Read more >Rule proposal: `prefer-await` #1144 - Issuehunt
Proposing a rule to require await when the callee is async . Fail. const a = async () => {}; a(); /* error:...
Read more >eslint-plugin-unicorn - Bountysource
The rule name may be named unicorn/prefer-await . ... Rule proposal: Use `Array.includes()` instead of repeated conditional checks $ 0.
Read more >Cypress: Setting up the first acceptance tests in Gitlab CI ...
For example, we force devs to use async/await in unit tests but we turned off the promise/prefer-await-to-then rule for cypress workspace ...
Read more >Documents 177 through 193 - state.gov
Mr. Schlesinger suggested we take up Ambassador Thompson's proposal to make a ... However, the Assembly's rules of procedure provide for the election...
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
How about
no-promise-catch
.Second thought, if we forbid
.catch
, why not.then
? So maybeprefer-await
?Reopening this, since
eslint-plugin-promise
don’t have autofix. I’m going to give another shot on it.