Skip to content

fix(return-await): guard concise arrow body path with hasAsync check#751

Merged
camc314 merged 2 commits intooxc-project:mainfrom
wagenet:fix/return-await-non-async-arrow
Feb 26, 2026
Merged

fix(return-await): guard concise arrow body path with hasAsync check#751
camc314 merged 2 commits intooxc-project:mainfrom
wagenet:fix/return-await-non-async-arrow

Conversation

@wagenet
Copy link
Copy Markdown
Contributor

@wagenet wagenet commented Feb 26, 2026

Summary

  • Non-async concise arrow functions (e.g. const f = (): Promise<number> => Promise.resolve(1)) were incorrectly flagged in always, in-try-catch, and error-handling-correctness-only modes
  • The KindArrowFunction exit handler called testEachPossiblyReturnedNode on the concise body without checking scope.hasAsync, bypassing the guard that already exists on the KindReturnStatement handler
  • Fix adds && scope != nil && scope.hasAsync to the concise-body branch, making it consistent with the block-body path

Test plan

  • Added three valid (no-error) test cases for a non-async typed arrow returning a Promise, one per affected mode (always, in-try-catch, error-handling-correctness-only)
  • go test ./internal/rules/return_await/... passes

🤖 Generated with Claude Code

Non-async arrow functions with a concise body (e.g. `const f = () =>
Promise.resolve(1)`) were incorrectly flagged in `always` mode because
`testEachPossiblyReturnedNode` was called without checking `scope.hasAsync`.
The `KindReturnStatement` handler already had this guard; add the same
guard to the `KindArrowFunction` exit handler.

Fixes: non-async concise arrows producing TS1308 ('await' expression
only allowed in async functions) when the unsafe fixer is applied.
Comment thread internal/rules/return_await/return_await_test.go
@camc314 camc314 self-assigned this Feb 26, 2026
Copy link
Copy Markdown
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@camc314 camc314 enabled auto-merge (squash) February 26, 2026 12:18
@camc314 camc314 merged commit fff3c00 into oxc-project:main Feb 26, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants