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] handle TaggedTemplateExpression #8758

Conversation

naruaway
Copy link
Contributor

@naruaway naruaway commented Mar 24, 2024

PR Checklist

Overview

This PR makes "no-floating-promises" rule to raise error when floating promise is created from a tagged templates, which is essentially a function call in this context.
The motivating example is with dax, which is a popular library to write shell script in TypeScript.
Its $ API is a tagged template and it returns a Promise (with other methods on it) and we need to await on that.
If we forget to await, execution orders will be messed up and the main script might exit too early.

After this PR, "no-floating-promises" will be able to capture the mistake in the following snippet:

import $ from 'dax-sh'

// Here we are forgetting `await` and , "no-floating-promises" cannot detect it without the PR
$`echo hello`
$`echo world`

I added the corresponding test cases in the PR and confirmed that the test fails before the implementation change in this PR.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @naruaway!

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 Mar 24, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 7c8c9dd
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6601b29c28655f00086b2149
😎 Deploy Preview https://deploy-preview-8758--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: 98 (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

codecov bot commented Mar 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.36%. Comparing base (e408b93) to head (7c8c9dd).
Report is 14 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8758      +/-   ##
==========================================
- Coverage   87.98%   87.36%   -0.63%     
==========================================
  Files         404      255     -149     
  Lines       14045    12498    -1547     
  Branches     4110     3923     -187     
==========================================
- Hits        12358    10919    -1439     
+ Misses       1382     1304      -78     
+ Partials      305      275      -30     
Flag Coverage Δ
unittest 87.36% <100.00%> (-0.63%) ⬇️

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

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

... and 156 files with indirect coverage changes

Copy link
Member

@Josh-Cena Josh-Cena left a comment

Choose a reason for hiding this comment

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

I don't know if they work differently but could you add tests for tag`aaa`.then, tag`aaa`.catch, and tag`aaa`.finally?

@naruaway naruaway force-pushed the no-floating-promise-should-handle-tagged-template-expression branch from 2bc344c to d5f77d4 Compare March 24, 2024 15:45
@naruaway
Copy link
Contributor Author

@Josh-Cena thanks for the review, I just added test cases for then/catch/finally for sure. I think adding these makes sense to make sure the logic is the same as the function call

@naruaway naruaway force-pushed the no-floating-promise-should-handle-tagged-template-expression branch from d5f77d4 to fa4c831 Compare March 25, 2024 14:28
@naruaway naruaway requested a review from Josh-Cena March 25, 2024 15:36
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.

We normally ask that PRs (other than small docs fixes) have a backing issue for discussion. But this one is pretty small and straightforward. Just requesting changes on tests. Thanks! 🏷️

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Mar 25, 2024
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Mar 25, 2024
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.

Older woman on Antiques Roadshow happily clapping and saying 'this is wonderful'

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Mar 25, 2024
@JoshuaKGoldberg JoshuaKGoldberg merged commit 5707268 into typescript-eslint:main Mar 26, 2024
60 checks passed
peanutenthusiast pushed a commit to peanutenthusiast/typescript-eslint that referenced this pull request Mar 27, 2024
…ssion (typescript-eslint#8758)

* fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpression

* Improve test cases
yeonjuan pushed a commit to yeonjuan/typescript-eslint that referenced this pull request Mar 31, 2024
…ssion (typescript-eslint#8758)

* fix(eslint-plugin): [no-floating-promises] handle TaggedTemplateExpression

* Improve test cases
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants