question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `prefer-await`

See original GitHub issue

The 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:open
  • Created 3 years ago
  • Reactions:22
  • Comments:28 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
fiskercommented, Mar 31, 2020

How about no-promise-catch.

Second thought, if we forbid .catch, why not .then? So maybe prefer-await?

3reactions
fiskercommented, Jan 22, 2021

Reopening this, since eslint-plugin-promise don’t have autofix. I’m going to give another shot on it.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found