Skip to content

fix(eslint-plugin): [await-thenable, return-await] don't flag awaiting unconstrained type parameter as unnecessary #10314

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

Merged

Conversation

ronami
Copy link
Member

@ronami ronami commented Nov 9, 2024

PR Checklist

Overview

This PR resolves #10311 and stops reporting on some type constraints (see playground link).

As per @kirkwaiblinger's comment, I shared common logic between await-thenable and return-await, so this fixes similar issues with both (playground link for return-await).

On top of not reporting on unconstrained type parameters, this also stops reporting on type parameters with valid constraints like unknown or any (not part of the original issue); please let me know if this is OK.

// type parameter with no constraint
async function test1<T>(value: T) {
  return await value;
}

// type parameter with `any` or `unknown` constraint
async function test2<T extends unknown>(value: T) {
  return await value;
}

async function test3<T extends any>(value: T) {
  return await value;
}

// direct `any` or `unknown` type pass
async function test4(value: unknown) {
  return await value;
}

async function test5(value: any) {
  return await value;
}

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ronami!

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 Nov 9, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit aa274e9
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/673250d6780aa90008b9c765
😎 Deploy Preview https://deploy-preview-10314--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: 99 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (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 Nov 9, 2024

☁️ Nx Cloud Report

CI is running/has finished running commands for commit aa274e9. 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 1 target

Sent with 💌 from NxCloud.

Copy link

codecov bot commented Nov 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.58%. Comparing base (124b65d) to head (aa274e9).
Report is 23 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10314      +/-   ##
==========================================
+ Coverage   86.56%   86.58%   +0.01%     
==========================================
  Files         431      432       +1     
  Lines       15188    15145      -43     
  Branches     4418     4424       +6     
==========================================
- Hits        13148    13113      -35     
+ Misses       1683     1675       -8     
  Partials      357      357              
Flag Coverage Δ
unittest 86.58% <100.00%> (+0.01%) ⬆️

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

Files with missing lines Coverage Δ
packages/eslint-plugin/src/rules/await-thenable.ts 100.00% <100.00%> (ø)
packages/eslint-plugin/src/rules/return-await.ts 97.41% <100.00%> (-0.03%) ⬇️
...ackages/eslint-plugin/src/util/needsToBeAwaited.ts 100.00% <100.00%> (ø)

... and 27 files with indirect coverage changes

@ronami ronami marked this pull request as ready for review November 9, 2024 15:54
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.

Pacha from Emperor's New Groove giving a perfection sign with a hand. Caption: "PERFECTION!"

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Nov 10, 2024
@kirkwaiblinger kirkwaiblinger changed the title fix(eslint-plugin): [await-thenable] don't flag values of an unconstrained type parameter fix(eslint-plugin): [await-thenable, return-await] don't flag awaiting unconstrained type parameter as unnecessary Nov 11, 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.

Just minor changes requested. Looks great!

Co-authored-by: Kirk Waiblinger <kirk.waiblinger@gmail.com>
@github-actions github-actions bot removed the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Nov 11, 2024
@bradzacher bradzacher added the bug Something isn't working label Nov 16, 2024
@bradzacher bradzacher merged commit 013c5cc into typescript-eslint:main Nov 16, 2024
64 of 65 checks passed
@ronami ronami deleted the await-thenable-no-type-constraint branch November 16, 2024 04:16
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Nov 18, 2024
##### [v8.15.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8150-2024-11-18)

##### 🚀 Features

-   **eslint-plugin:** \[prefer-nullish-coalescing] fix detection of `ignoreConditionalTests` involving boolean `!` operator ([#10299](typescript-eslint/typescript-eslint#10299))
-   **eslint-plugin:** new rule `no-unsafe-type-assertion` ([#10051](typescript-eslint/typescript-eslint#10051))
-   **eslint-plugin:** added related-getter-setter-pairs rule ([#10192](typescript-eslint/typescript-eslint#10192))

##### 🩹 Fixes

-   **utils:** add defaultOptions to meta in rule ([#10339](typescript-eslint/typescript-eslint#10339))
-   **eslint-plugin:** report deprecations used in default export ([#10330](typescript-eslint/typescript-eslint#10330))
-   **eslint-plugin:** \[explicit-module-boundary-types] and \[explicit-function-return-type] don't report on `as const satisfies` ([#10315](typescript-eslint/typescript-eslint#10315))
-   **eslint-plugin:** \[await-thenable, return-await] don't flag awaiting unconstrained type parameter as unnecessary ([#10314](typescript-eslint/typescript-eslint#10314))
-   **eslint-plugin:** \[consistent-indexed-object-style] handle circular mapped types ([#10301](typescript-eslint/typescript-eslint#10301))

##### ❤️  Thank You

-   Josh Goldberg ✨
-   Kim Sang Du [@developer-bandi](https://github.com/developer-bandi)
-   Luis Sebastian Urrutia Fuentes [@LuisUrrutia](https://github.com/LuisUrrutia)
-   Phillip Huang
-   Ronen Amiel
-   Szydlak [@wszydlak](https://github.com/wszydlak)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Nov 19, 2024
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.14.0 | 8.15.0 |
| npm        | @typescript-eslint/parser        | 8.14.0 | 8.15.0 |


## [v8.15.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8150-2024-11-18)

##### 🚀 Features

-   **eslint-plugin:** \[prefer-nullish-coalescing] fix detection of `ignoreConditionalTests` involving boolean `!` operator ([#10299](typescript-eslint/typescript-eslint#10299))
-   **eslint-plugin:** new rule `no-unsafe-type-assertion` ([#10051](typescript-eslint/typescript-eslint#10051))
-   **eslint-plugin:** added related-getter-setter-pairs rule ([#10192](typescript-eslint/typescript-eslint#10192))

##### 🩹 Fixes

-   **utils:** add defaultOptions to meta in rule ([#10339](typescript-eslint/typescript-eslint#10339))
-   **eslint-plugin:** report deprecations used in default export ([#10330](typescript-eslint/typescript-eslint#10330))
-   **eslint-plugin:** \[explicit-module-boundary-types] and \[explicit-function-return-type] don't report on `as const satisfies` ([#10315](typescript-eslint/typescript-eslint#10315))
-   **eslint-plugin:** \[await-thenable, return-await] don't flag awaiting unconstrained type parameter as unnecessary ([#10314](typescript-eslint/typescript-eslint#10314))
-   **eslint-plugin:** \[consistent-indexed-object-style] handle circular mapped types ([#10301](typescript-eslint/typescript-eslint#10301))

##### ❤️  Thank You

-   Josh Goldberg ✨
-   Kim Sang Du [@developer-bandi](https://github.com/developer-bandi)
-   Luis Sebastian Urrutia Fuentes [@LuisUrrutia](https://github.com/LuisUrrutia)
-   Phillip Huang
-   Ronen Amiel
-   Szydlak [@wszydlak](https://github.com/wszydlak)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [await-thenable] Don't flag values of an unconstrained type parameter
4 participants