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-useless-template-literals] detect TemplateLiteral #8575

Conversation

waynzh
Copy link
Contributor

@waynzh waynzh commented Feb 29, 2024

PR Checklist

Overview

Add detect for TemplateLiteral

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @waynzh!

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 Feb 29, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 67c097e
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65e82fb75a2ecb0008efa584
😎 Deploy Preview https://deploy-preview-8575--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 (🟢 up 6 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.

@waynzh waynzh force-pushed the fix/no-useless-template-literals-detect-templateliteral branch from 40f2513 to a259377 Compare March 1, 2024 01:54
Copy link

codecov bot commented Mar 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.17%. Comparing base (6954a4a) to head (67c097e).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8575      +/-   ##
==========================================
+ Coverage   87.12%   87.17%   +0.04%     
==========================================
  Files         251      251              
  Lines       12268    12275       +7     
  Branches     3868     3872       +4     
==========================================
+ Hits        10689    10701      +12     
+ Misses       1307     1303       -4     
+ Partials      272      271       -1     
Flag Coverage Δ
unittest 87.17% <100.00%> (+0.04%) ⬆️

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

Files Coverage Δ
...t-plugin/src/rules/no-useless-template-literals.ts 100.00% <100.00%> (ø)

... and 58 files with indirect coverage changes

auvred
auvred previously approved these changes Mar 1, 2024
Copy link
Member

@auvred auvred left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀 Thanks for working on this!

Crowd applauds

@kirkwaiblinger
Copy link
Member

@waynzh Nice work on this!
Unfortunately, I didn't notice this PR until just now, and I worked on a fix myself over the weekend 🤦.

I did one or two things slightly differently, though, so I thought I'd mention them here. Here is the commit for reference: kirkwaiblinger@8bdddbd.

  1. I think that this code should flag on nested template literals with a nonzero number of substitution expressions. The fixer code change is straightforward (feel free to copy it):
               } else if (expression.type === AST_NODE_TYPES.TemplateLiteral) {
                 // Note that some template literals get handled in the previous branch too.
                 // Remove the beginning and trailing backtick characters.
                 fixes.push(
                   fixer.removeRange([
                     expression.range[0],
                     expression.range[0] + 1,
                   ]),
                   fixer.removeRange([
                     expression.range[1] - 1,
                     expression.range[1],
                   ]),
                 );
    and the test cases pass.
  2. (testing only, not a bug) I think this should have a test case to make sure we don't flag on tagged template literals.
    `
       \`not a useless \${String.raw\`nested interpolation \${a}\`}\`;
    `,

(expression): expression is TSESTree.Literal | TSESTree.Identifier =>
(
expression,
): expression is
Copy link
Member

Choose a reason for hiding this comment

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

consider just returning boolean/omitting the return type since the type guard isn't needed for any subsequent code.

It's suspect to me to change the type guards based on a pure implementation change in one of the functions being called.

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.

Yup, what @kirkwaiblinger said!

Looks great otherwise ✨ very clean. Thanks!

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Mar 5, 2024
@waynzh
Copy link
Contributor Author

waynzh commented Mar 6, 2024

Sorry for the late reply. I'll refactor the code soon.
Thanks for the review and reference! @kirkwaiblinger @JoshuaKGoldberg

@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Mar 6, 2024
{
code: noFormat`
\`u\${
// hopefully this comment is not needed.
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] Oh, right, this reminds me I'd wanted to file a low-priority followup bug about the comments being removed. Thanks 😄 #8609

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.

🙌

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval PR that a maintainer has LGTM'd - any maintainer can merge this when ready label Mar 6, 2024
@kirkwaiblinger
Copy link
Member

🚀

@JoshuaKGoldberg JoshuaKGoldberg merged commit ef0e5cc into typescript-eslint:main Mar 6, 2024
62 of 64 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 14, 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
5 participants