New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: only warn about literals and undefined on no-return-await #17363
Conversation
Hi @clshortfuse!, thanks for the Pull Request The first commit message isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by running Read more about contributing to ESLint here |
|
✅ Deploy Preview for docs-eslint canceled.
|
In async functions, returning awaited promises no longer has any performance penalty and is now faster than returning promises directly. Because we cannot detect what the result type of a `CallExpression` or the type of a `MemberExpression`, or the type of an `Identifier`, warnings related to whether an actual Promise is being returned cannot be processed. Strictly from at an AST level, we can detect `Literal` node types and `undefined`. * Detect await being used on `Literal` node type * Detect await being used on an `Identifier` named `undefined` * Detect await being used on a `ConditionalExpression` that returns either a `Literal` type or `undefined`. * Detect await being used on a void operation (results in `undefined`) Futher changes can be made to detect syntaxes where a `Literal` type would be returned, such as * await (4 + 3) * await ('foo' + 'bar') Future changes may also, suggest rewriting awaited `CondtionExpression` nodes such as: * async function foo(value) { return await (value ? true : bar()) } This would require more extensive testing. See: https://v8.dev/blog/fast-async Fixes eslint#17345
3ecf6b9
to
4faa777
Compare
@clshortfuse thanks for the PR. In the issue you reference (#17345) it was agreed to make a documentation change, not a change to how the rule works. We'd happily accept a documentation change explaining the points you made. Please revert the changes to the rule itself and update the docs accordingly. |
Hi everyone, it looks like we lost track of this pull request. Please review and see what the next steps are. This pull request will auto-close in 7 days without an update. |
Closing in favor of #17417 |
In async functions, returning awaited promises no longer has any performance penalty and is now faster than returning promises directly.
Because we cannot detect what the result type of a
CallExpression
or the type of aMemberExpression
, or the type of anIdentifier
, warnings related to whether an actual Promise is being returned cannot be processed. Strictly from at an AST level, we can detectLiteral
node types andundefined
.Literal
node typeIdentifier
namedundefined
ConditionalExpression
that returns either aLiteral
type orundefined
.undefined
)Futher changes can be made to detect syntaxes where a
Literal
type would be returned, such asFuture changes may also, suggest rewriting awaited
CondtionExpression
nodes such as:This would require more extensive testing.
Fixes #17345
See: https://v8.dev/blog/fast-async
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
(see commit message)
Is there anything you'd like reviewers to focus on?
It's impossible to properly assess the return type, but we can at least check for
Literal
nodes andundefined
.This keeps the rule being a suggestion, but relaxes type-related checks.