-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add suggestion to require-await
to remove async
keyword
#9718
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
feat(eslint-plugin): add suggestion to require-await
to remove async
keyword
#9718
Conversation
Thanks for the PR, @reduckted! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 3a7065f. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 2 targetsSent with 💌 from NxCloud. |
@kirkwaiblinger Could you please reopen #9621, as the feature has now been merged into ESLint. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #9718 +/- ##
==========================================
- Coverage 87.93% 87.90% -0.03%
==========================================
Files 403 405 +2
Lines 13795 13859 +64
Branches 4022 4047 +25
==========================================
+ Hits 12130 12183 +53
- Misses 1358 1368 +10
- Partials 307 308 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sending this in! I don't have time for a full review right now, but I wanted to get the question about return types in front of you to contemplate early, in case it affects the PR substantially.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another high-level pass, a few minor changes requested. Main blocker is the question about async generators.
Good stuff!
…uto-formatting applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff!
I haven't seen any issues with the actual rule logic, just requesting a some changes around our repo's code style and some unnecessarily defensive conditions.
Awesome work! Getting close!
node.returnType.typeAnnotation.typeName.range[0], | ||
openAngle.range[1], | ||
], | ||
replacement: '', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) Rather than using replaceTextRange()
with replacement: ''
, would you mind refactoring this to use fixer.removeTextRange()
? Just for simplicity. I realize this will require you to move a few things around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, for this I was thinking more like
const fix: ReportFixFunctino = fixer => {
const fixes: RuleFix[] = [];
// ...
fixes.push(
fixer.replaceTextRange(asyncRange, addSemiColon ? ';' : ''),
);
// ...
fixes.push(fixer.removeRange(closeAngle.range));
fixes.push(
fixer.removeRange([
node.returnType.typeAnnotation.typeName.range[0],
openAngle.range[1],
]),
);
// ....
return fixes;
}
if that makes sense. But the way you have it is fine to keep too! 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff! Up to you if you want to make any changes with respect to #9718 (comment) or keep as is 🙂
Thanks for handling this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comments in there were really helpful for review, thanks 😄
478990f
into
typescript-eslint:main
PR Checklist
Overview
Implements the suggestion that was added in eslint/eslint#18713 (pull request: eslint/eslint#18716)
The
require-await
rule now includes a suggestion to remove theasync
keyword.This mirrors the behavior of the underlying ESLint rule's suggestion. If the function has a return type annotation of
Promise<T>
, the suggestion will also change the return type annotation toT
, or if it has a return type annotation ofAsyncGenerator<T>
, the suggestion will also change the return type annotation toGenerator<T>
.