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.

Remove `no-return-await` rule

See original GitHub issue

What rule do you want to change?

no-return-await.

The rule description body of the rule not longer valid. The rule states that this syntax is useless although it is a very valuable implementation:

It has better performance than hand-written promises, and more importantly it produces better debugging stack traces.

Read full details about the benefits of using return await in this answer: https://stackoverflow.com/questions/44806135/why-no-return-await-vs-const-x-await/44806230#44806230

How will the change be implemented? (New option, new default behavior, etc.)?

I’d suggest removing the rule and introducing a new one that throws if a promise is not awaited inside an async function.

A saner approach is to update the rule description to reflect that this longer is no longer correct and deprecate it in code.

Please provide some example code that this change will affect:

return await <Promise>

What does the rule currently do for this code?

The rule states that this rule is useless although it is a very valuable implementation, it increases performance, produces better debugging stack traces, and it explicitly denotes that the returned function is a promise.

What will the rule do after it’s changed?

I’d vote for removing the rule and creating another one with the exact opposite behavior. IDK how you deal with backwards compatibility.

Are you willing to submit a pull request to implement this change?

No

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:14 (8 by maintainers)

github_iconTop GitHub Comments

6reactions
dbjorgecommented, Nov 25, 2019

I think the analysis of this rule in https://github.com/standard/standard/issues/1442 brings up a second, more important reason that would make me prefer to see this rule either deprecated or at least not-recommended-by-default, which is that it sets a trap for an assortment of different types of refactoring (see that issue for more details). Frankly, I think the refactoring traps are enough that I think it would make more sense for the default recommendation to encourage the await.

4reactions
dbjorgecommented, Nov 25, 2019

Further, I agree with the argument that the difference in stack trace usability and performance should be treated as an implementation detail, but I think that this should encourage picking the choice that leads to code which is easiest for a maintainer to understand regardless of whether some implementations might use an extra wrapping layer with the extra await, and I think making the sync/async nature more obvious to a reader has a bigger impact on improving readability than removing the redundant token does.

async function doThings() {
  const a = await thingA();
  const b = thingB(a);
  // This *looks* synchronous, but actually the reader can't tell without looking up function signatures.
  // The real behavior would be more obvious to a future maintainer with the await.
  return thingC(b);
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

no-return-await - ESLint - Pluggable JavaScript Linter
This rule aims to prevent a likely common performance hazard due to a lack of understanding of the semantics of async function ....
Read more >
no-return-await - Rules - ESLint - Pluggable JavaScript linter
This rule aims to prevent a likely common performance hazard due to a lack of understanding of the semantics of async function ....
Read more >
Why no-return-await vs const x = await? - Stack Overflow
Basically, because return await is redundant. Look at it from a slightly higher level of how you actually use an async function:
Read more >
return-await | typescript-eslint
This rule builds on top of the eslint/no-return-await rule. ... Note: you must disable the base rule as it can report incorrect errors...
Read more >
JSHint Options Reference
Warning This option has been deprecated and will be removed in the next major ... If you would like to enforce rules relating...
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