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: `no-return-await`

See original GitHub issue

Please describe what the rule should do: Inside an async function, return await is useless. Since the return value of an async function is always wrapped in Promise.resolve, return await doesn’t actually do anything except add an extra tick before the overarching promise resolves/rejects. This pattern is almost certainly due to programmer ignorance of the return semantics of async functions.

What category of rule is this? (place an “X” next to just one item)

[ ] Enforces code style [ ] Warns about a potential error [x] Suggests an alternate way of doing something [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

async function foo() {
  return await bar;
}

in favor of:

async function foo() {
  return bar;
}

Why should this rule be included in ESLint (instead of a plugin)? People are very anxious to use await, and will likely overuse it. This rule prevents a common hazard, and also helps educate developers about how async function works.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:30 (21 by maintainers)

github_iconTop GitHub Comments

2reactions
shinoutcommented, Oct 28, 2017

I found a case we need return await.


async function foo() {
  try {
    return await bar()
  }
  catch (e) {
    console.log(e) // error comes here
  }
}

async function fooWithoutAwait() {
  try {
    return bar()
  }
  catch (e) {
    console.log(e) // cannot catch async error
  }
}

async function bar() {
  throw new Error('bar')
}

foo() // catch error
fooWithoutAwait() // unhandled promise rejection

How can we manage these async exceptions?

2reactions
vitorbalcommented, Nov 5, 2016

I will 👍 this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
Federal Register/Vol. 87, No. 46/Wednesday, March 9, 2022 ...
ACTION: Proposed rule. SUMMARY: The Securities and Exchange. Commission is proposing new rules under the Investment Advisers Act of.
Read more >
Are there performance concerns with `return await`?
I see there is an eslint rule, no-return-await , for disallowing return await . In the rule's description, it states a return await...
Read more >
ESLint v3.13.0 released
Autofix support was added to the following rules: ... ebcae1f Update: no-return-await with with complex return argument (fixes #7594) (#7595) (Dalton Santos) ...
Read more >
eslint-config-ash-nazg - npm
See index.js (and node.js for ash-nazg/node rules) for the rules we explicitly ... ash-nazg aims to offer defaults which adhere to norms, ...
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