Skip to content

feat(linter): implement no-promise-executor-return rule#16779

Merged
camc314 merged 6 commits intooxc-project:mainfrom
tt-a1i:feat/linter-no-promise-executor-return
Dec 12, 2025
Merged

feat(linter): implement no-promise-executor-return rule#16779
camc314 merged 6 commits intooxc-project:mainfrom
tt-a1i:feat/linter-no-promise-executor-return

Conversation

@tt-a1i
Copy link
Contributor

@tt-a1i tt-a1i commented Dec 12, 2025

Summary

Implements ESLint's no-promise-executor-return rule which disallows returning values from Promise executor functions.

The return value of a Promise executor is ignored, so returning a value is likely a mistake. This rule detects:

  • Implicit returns from arrow function expression bodies (new Promise(r => r(1)))
  • Explicit return statements with values (return 1, return resolve(1))
  • Returns inside control flow (if, switch, loops, try-catch, etc.)

Configuration

  • allowVoid (default: false): When true, allows return void expr pattern (both explicit and implicit returns)

Design Notes

This rule only checks executors passed directly as arrow/function expressions. It does not track references like new Promise(executor) where executor is defined elsewhere — this is an intentional design choice consistent with ESLint's implementation.

Test Plan

  • Added 12 pass cases (empty return, no return, nested functions, allowVoid, non-Promise)
  • Added 16 fail cases (implicit return, explicit return, control flow, return resolve/reject)
  • cargo test -p oxc_linter no_promise_executor_return passes
  • cargo clippy -p oxc_linter passes

Closes #7790

@tt-a1i tt-a1i requested a review from camc314 as a code owner December 12, 2025 15:43
@github-actions github-actions bot added A-linter Area - Linter C-enhancement Category - New feature or request labels Dec 12, 2025
@tt-a1i tt-a1i force-pushed the feat/linter-no-promise-executor-return branch from 51ca947 to 211ff89 Compare December 12, 2025 15:46
@codspeed-hq
Copy link

codspeed-hq bot commented Dec 12, 2025

CodSpeed Performance Report

Merging #16779 will not alter performance

Comparing tt-a1i:feat/linter-no-promise-executor-return (bd642bf) with main (fbcb49a)1

Summary

✅ 4 untouched
⏩ 41 skipped2

Footnotes

  1. No successful run was found on main (2124d03) during the generation of this report, so fbcb49a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

  2. 41 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@tt-a1i tt-a1i force-pushed the feat/linter-no-promise-executor-return branch 2 times, most recently from 871054b to 0d5900c Compare December 12, 2025 16:09
@tt-a1i tt-a1i requested a review from Sysix as a code owner December 12, 2025 16:09
@github-actions github-actions bot added the A-editor Area - Editor and Language Server label Dec 12, 2025
@tt-a1i tt-a1i force-pushed the feat/linter-no-promise-executor-return branch 2 times, most recently from c47b640 to 5d03612 Compare December 12, 2025 16:21
@github-actions github-actions bot added the A-cli Area - CLI label Dec 12, 2025
@tt-a1i tt-a1i force-pushed the feat/linter-no-promise-executor-return branch from 5d03612 to 045fa6b Compare December 12, 2025 16:28
Disallow returning values from Promise executor functions.

The return value of the Promise executor is ignored and returning a
value is likely a mistake. The rule detects:
- Implicit returns from arrow function expression bodies
- Explicit return statements with values
- Returns inside control flow (if, switch, loops, try-catch, etc.)

Configuration:
- `allowVoid`: Allow `return void expr` pattern (default: false)

Closes #25083
@tt-a1i tt-a1i force-pushed the feat/linter-no-promise-executor-return branch from 045fa6b to 70f9e88 Compare December 12, 2025 16:37
@camc314 camc314 merged commit 67bde85 into oxc-project:main Dec 12, 2025
21 checks passed
graphite-app bot pushed a commit that referenced this pull request Jan 12, 2026
…17901)

The original implementation of the rule did not port most of the tests. I'm not sure that it's worth retaining the previous tests, so I just replaced them entirely for now.

Almost all the tests pass, thankfully, but a few fail and needed to be commented out. We should probably fix them.

Rule was added in #16779.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-editor Area - Editor and Language Server A-linter Area - Linter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants