Rule proposal: `no-return-await`
See original GitHub issuePlease 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 function
s.
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:
- Created 7 years ago
- Reactions:8
- Comments:30 (21 by maintainers)
Top GitHub Comments
I found a case we need
return await
.How can we manage these async exceptions?
I will 👍 this.