feat(require-await): implement suggestions#896
Merged
camc314 merged 5 commits intoApr 21, 2026
Conversation
…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
There was a problem hiding this comment.
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
removeAsyncsuggestion forrequire-await, including fixes to removeasyncand adjust return types (Promise<T>→T,AsyncGenerator→Generator). - Introduce
utils.FindModifierand a newutils.GetFunctionHeadLochelper (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.
There was a problem hiding this comment.
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.
Contributor
|
part of #668 |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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