Skip to content

feat(require-await): implement suggestions#896

Merged
camc314 merged 5 commits into
oxc-project:mainfrom
younggglcy:feat/require-await-suggestion
Apr 21, 2026
Merged

feat(require-await): implement suggestions#896
camc314 merged 5 commits into
oxc-project:mainfrom
younggglcy:feat/require-await-suggestion

Conversation

@younggglcy

Copy link
Copy Markdown
Contributor

Happen to find out this rule is not implemented, so I made a PR for it.

All changes are vide coded, made by Opus 4.7 xhigh and reviewd by GPT 5.4 xhigh

All Tests should be passed. 2 more testcases added via 9eba640#diff-812e0a4dddcd773e6d9fb8d19bb18a8584f9b87de2bbd540ddcec1c056871610R618-R655

…eadLoc

Ports the remaining TODO logic in the require-await rule from typescript-eslint:

- Report the function head range (modifiers through the opening `(` of params, or
  the `=>` token for arrow functions) instead of the whole function body
- Attach a `removeAsync` suggestion that:
  - removes the `async` keyword plus trailing whitespace while preserving
    trailing comments (mirrors `getTokenAfter(async, {includeComments: true})`)
  - unwraps `Promise<T>` to `T` in the return type annotation for non-generators
  - renames `AsyncGenerator` to `Generator` in the return type annotation for
    generators
  - inserts a leading `;` when removing `async` before `[` or `(` would change
    parsing due to ASI hazard (class computed methods, expression statements)
- Enable all previously commented-out `Suggestions` assertions in the test file
  and regenerate the snapshot

Extracts two reusable helpers to internal/utils/:

- `utils.GetFunctionHeadLoc` — port of typescript-eslint's getFunctionHeadLoc,
  placed next to the existing `GetForStatementHeadLoc`. Unblocks the
  `TODO(port): getFunctionHeadLoc` markers in promise_function_async and
  no_misused_promises.
- `utils.FindModifier` — returns the modifier node of a given kind, symmetric
  companion to `IncludesModifier`; the latter is now a thin wrapper over it.

Made-with: Cursor
Avoid generating invalid removeAsync suggestions for qualified Promise and AsyncGenerator return annotations.

Made-with: Cursor
Record the new require-await head ranges and removeAsync suggestions in the e2e snapshot so CI matches the rule output introduced on this branch.

Made-with: Cursor

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Implements the missing “suggestion” behavior for the require-await rule, aligning it more closely with typescript-eslint by offering a “Remove 'async'” suggestion (including return type adjustments) and improving diagnostic ranges to point at the function head.

Changes:

  • Add a removeAsync suggestion for require-await, including fixes to remove async and adjust return types (Promise<T>T, AsyncGeneratorGenerator).
  • Introduce utils.FindModifier and a new utils.GetFunctionHeadLoc helper (ported from typescript-eslint) to support suggestion generation and tighter diagnostic ranges.
  • Update rule tests and snapshots (unit + e2e) to assert suggestions and new diagnostic ranges.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/utils/utils.go Adds FindModifier helper and refactors IncludesModifier to use it.
internal/utils/ts_eslint.go Adds GetFunctionHeadLoc helper to compute function “head” ranges for reporting.
internal/rules/require_await/require_await.go Implements removeAsync suggestions + fix generation (including ASI handling and return type edits).
internal/rules/require_await/require_await_test.go Enables/extends suggestion assertions and adds new cases for qualified return types.
internal/rule_tester/snapshots/require-await.snap Updates snapshots for narrowed diagnostic ranges and suggestions.
e2e/snapshots/snapshot.test.ts.snap Updates e2e snapshots to include suggestions and updated ranges for require-await.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@camc314 camc314 left a comment

Copy link
Copy Markdown
Contributor

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) April 21, 2026 10:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/rules/require_await/require_await.go
@camc314 camc314 merged commit ee23618 into oxc-project:main Apr 21, 2026
8 checks passed
@younggglcy younggglcy deleted the feat/require-await-suggestion branch April 21, 2026 15:18
@camc314

camc314 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor

part of #668

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