8000 feat(eslint-plugin): add suggestion to `require-await` to remove `async` keyword by reduckted · Pull Request #9718 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

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

Conversation

reduckted
Copy link
Contributor
@reduckted reduckted commented Aug 4, 2024

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 the async 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 to T, or if it has a return type annotation of AsyncGenerator<T>, the suggestion will also change the return type annotation to Generator<T>.

@typescript-eslint
Copy link
Contributor

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.

Copy link
netlify bot commented Aug 4, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 3a7065f
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66bf4b0ac79c6d00083b2bb2
😎 Deploy Preview https://deploy-preview-9718--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (🔴 down 4 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 90 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
nx-cloud bot commented Aug 4, 2024

☁️ Nx Cloud Report

CI 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 targets

Sent with 💌 from NxCloud.

@reduckted
Copy link
Contributor Author

@kirkwaiblinger Could you please reopen #9621, as the feature has now been merged into ESLint.

Copy link
codecov bot commented Aug 4, 2024

Codecov Report

Attention: Patch coverage is 83.07692% with 11 lines in your changes missing coverage. Please review.

Project coverage is 87.90%. Comparing base (eaddd92) to head (3a7065f).
Report is 13 commits behind head on main.

Files Patch % Lines
.../eslint-plugin/src/util/needsPrecedingSemiColon.ts 65.62% 10 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
unittest 87.90% <83.07%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
packages/eslint-plugin/src/rules/require-await.ts 97.26% <100.00%> (+1.34%) ⬆️
...nt-plugin/src/util/isStartOfExpressionStatement.ts 100.00% <100.00%> (ø)
.../eslint-plugin/src/util/needsPrecedingSemiColon.ts 65.62% <65.62%> (ø)

@kirkwaiblinger kirkwaiblinger added the enhancement New feature or request label Aug 5, 2024
Copy link
Member
@kirkwaiblinger kirkwaiblinger left a 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.

Copy link
Member
@kirkwaiblinger kirkwaiblinger left a 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!

@kirkwaiblinger kirkwaiblinger added the awaiting response Issues waiting for a reply from the OP or another party label Aug 9, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 10, 2024
Copy link
Member
@kirkwaiblinger kirkwaiblinger left a 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: '',
Copy link
Member

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.

Copy link
Member

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! 🙂

@kirkwaiblinger kirkwaiblinger added the awaiting response Issues waiting for a reply from the OP or another party label Aug 15, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 16, 2024
@kirkwaiblinger kirkwaiblinger added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Aug 16, 2024
Copy link
Member
@kirkwaiblinger kirkwaiblinger left a 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!

Copy link
Member
@JoshuaKGoldberg JoshuaKGoldberg left a 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 😄

@JoshuaKGoldberg JoshuaKGoldberg merged commit 478990f into typescript-eslint:main Aug 19, 2024
61 of 62 checks passed
@reduckted reduckted deleted the feature/require-await-suggestion branch August 19, 2024 11:19
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [require-await] Add suggestion to remove async keyword
3 participants
0