Skip to content
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

fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises #7092

Merged
merged 4 commits into from Jul 16, 2023
Merged

fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises #7092

merged 4 commits into from Jul 16, 2023

Conversation

kirkwaiblinger
Copy link
Member

PR Checklist

Overview

The existing implementation treats .finally as though it can account for a rejected promise. It cannot prevent rejection. This PR implements the change recommended in the discussion for this issue, namely, to make .finally transparent to the rule and check whatever comes before it.

Promise.reject().finally(() => {}) // was ok, now an error
Promise.reject().catch(() => {}).finally(() => {}).finally(() => {}) // was ok - still ok

Note - this will have conflicts with #6881. It would be simpler to merge that PR first and then deal with the conflicts here.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @kirkwaiblinger!

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.

@netlify
Copy link

netlify bot commented Jun 8, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 6354b30
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/64b4284bdde0710008a1106d
😎 Deploy Preview https://deploy-preview-7092--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@kirkwaiblinger kirkwaiblinger changed the title finally is transparent to rejection fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises Jun 8, 2023
@nx-cloud
Copy link

nx-cloud bot commented Jun 8, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit 6354b30. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 35 targets

Sent with 💌 from NxCloud.

@codecov
Copy link

codecov bot commented Jun 8, 2023

Codecov Report

Merging #7092 (6354b30) into main (a9d7bb1) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7092   +/-   ##
=======================================
  Coverage   87.47%   87.47%           
=======================================
  Files         379      379           
  Lines       13230    13230           
  Branches     3906     3906           
=======================================
  Hits        11573    11573           
  Misses       1279     1279           
  Partials      378      378           
Flag Coverage Δ
unittest 87.47% <100.00%> (ø)

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

Impacted Files Coverage Δ
...es/eslint-plugin/src/rules/no-floating-promises.ts 100.00% <100.00%> (ø)

@kirkwaiblinger kirkwaiblinger changed the title fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises fix(eslint-plugin): [no-floating-promises] finally should be transparent to unhandled promises Jun 8, 2023
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.

This looks great, thanks a bunch @kirkwaiblinger!

Sorry for taking so long to review 😞 we've been caught up in v6 work for a while and I'm only now getting back into the PR review queue.

Approving now, will look at the other PR too.

@@ -191,12 +184,8 @@ async function test() {
() => {},
Copy link
Member

Choose a reason for hiding this comment

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

[Non-actionable] Aside: the promiseValue.finally(() => {}); on line 173 (unchanged by this PR) can be removed because that test case doesn't define a promiseValue value. It's an existing typo 😄. Not requesting any action, just noting for reference. This is good good first issue fodder.

packages/eslint-plugin/src/rules/no-floating-promises.ts Outdated Show resolved Hide resolved
if (isPromiseFinallyCallWithHandler(node)) {
return { isUnhandled: false };
// `x.finally()` is transparent to resolution of the promise, so check `x`.
// ("object" in this context is the `x` in `x.finally()`)
Copy link
Member

Choose a reason for hiding this comment

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

[Praise] This second line was very helpful for understanding the code :) great comment!

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.

Thanks, this looks great!

Homer Simpson going 'woohoo!' in the crowded stands at a stadium

@JoshuaKGoldberg JoshuaKGoldberg merged commit 2a4421c into typescript-eslint:main Jul 16, 2023
46 of 50 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [no-floating-promises] Incorrect handling of finally calls
2 participants