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

feat(eslint-plugin): [no-useless-template-literals] rename to no-useless-template-expression (deprecate no-useless-template-literals) #8821

Conversation

kirkwaiblinger
Copy link
Member

@kirkwaiblinger kirkwaiblinger commented Apr 2, 2024

PR Checklist

Overview

Copy old rule to new rule.
Deprecate rule under old name.
Lots of documentation updating.

@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.

Copy link

netlify bot commented Apr 2, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 4829797
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/66423646c9a00b0008679c2c
😎 Deploy Preview https://deploy-preview-8821--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: 93 (🔴 down 3 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.

@kirkwaiblinger kirkwaiblinger changed the title Rename no-useless-template-literals to no-useless-template-expression fix(eslint-plugin): [no-useless-template-literals] rename to no-useless-template-expression Apr 2, 2024
@kirkwaiblinger kirkwaiblinger marked this pull request as ready for review April 2, 2024 04:01
@JoshuaKGoldberg JoshuaKGoldberg added this to the 8.0.0 milestone Apr 14, 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.

LGTM in general! Just requesting changes on some docs touchups (the suggestions). Nothing functionally blocking from me. Thanks! ✨

@kirkwaiblinger
Copy link
Member Author

@JoshuaKGoldberg
This is a super last-minute thought, but I wonder whether we should soften it to "no-unnecessary-template-expression" instead of "no-useless-template-expression". The other no-useless-* rules are true noops that can be removed entirely, whereas this is just code that could be simplified. More in line with the no-unnecessary-* rules. We did plenty of bikeshedding on the "template-expression"/"template-interpolation"/"template-substitution" part of the rule in #8544, but didn't give the first half any thought. Not that it was the part of the name that was motivating to change, of course.

@JoshuaKGoldberg
Copy link
Member

no-unnecessary-template-expression

I'm up for the no-unnecesssary preference, that's a good distinction. Thoughts @Josh-Cena ?

@@ -16,10 +16,10 @@ This rule restricts what can be thrown as an exception.

:::warning
This rule is being renamed to [`only-throw-error`](./only-throw-error.mdx).
When it was first created, it only prevented literals from being thrown (hence the name), but it has now been expanded to only allow expressions which have a possibility of being an `Error` object.
With the `allowThrowingAny` and `allowThrowingUnknown` options, it can be configured to only allow throwing values which are guaranteed to be an instance of `Error`.
The current name, `no-throw-literal`, will be removed in a future major version of typescript-eslint.
Copy link
Contributor

Choose a reason for hiding this comment

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

since this PR changes multiple rules, maybe we should also change its title?
(so it'll also be squashed with the proper commit message)

or maybe split tp multiple PRs?

Copy link
Member Author

Choose a reason for hiding this comment

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

This comes out of #8821 (comment).
I think it makes sense to include in this change set since it's such a small (and related) change.


## When Not To Use It

When you want to allow string expressions inside template literals.
Copy link
Contributor

Choose a reason for hiding this comment

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

IIRC, it's not only for strings, it's also for other literals such as numbers, booleans, null, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, true. That part of the PR is just unchanged code moved from the existing page, though. See on main:

## When Not To Use It
When you want to allow string expressions inside template literals.

I don't feel strongly about it, so I would prefer not to bother changing it in this PR 🙃. Feel free to submit a separate PR to change that line if you like! 🙂

Comment on lines +74 to +78
:::info
This rule does not aim to flag template literals without substitution expressions that could have been written as an ordinary string.
That is to say, this rule will not help you turn `` `this` `` into `"this"`.
If you are looking for such a rule, you can configure the [`@stylistic/ts/quotes`](https://eslint.style/rules/ts/quotes) rule to do this.
:::
Copy link
Contributor

Choose a reason for hiding this comment

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

Like it!

packages/eslint-plugin/tests/docs.test.ts Outdated Show resolved Hide resolved
Copy link

codecov bot commented May 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 87.39%. Comparing base (f53fece) to head (12182f5).
Report is 13 commits behind head on main.

Current head 12182f5 differs from pull request most recent head 4829797

Please upload reports for the commit 4829797 to get more accurate results.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8821      +/-   ##
==========================================
- Coverage   88.04%   87.39%   -0.66%     
==========================================
  Files         410      256     -154     
  Lines       14187    12522    -1665     
  Branches     4136     3927     -209     
==========================================
- Hits        12491    10943    -1548     
+ Misses       1391     1304      -87     
+ Partials      305      275      -30     
Flag Coverage Δ
unittest 87.39% <100.00%> (-0.66%) ⬇️

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

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

... and 189 files with indirect coverage changes

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.

🚀 sorry for the delay, this is great!

I'm happy for you to merge whenever you're comfortable with it.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval One team member has approved this PR; a second should be enough to merge it label May 26, 2024
@bradzacher bradzacher changed the title fix(eslint-plugin): [no-useless-template-literals] rename to no-useless-template-expression feat(eslint-plugin): [no-useless-template-literals] rename to no-useless-template-expression (deprecate no-useless-template-literals) May 28, 2024
@bradzacher bradzacher merged commit 09ecbe2 into typescript-eslint:main May 28, 2024
59 checks passed
@kirkwaiblinger kirkwaiblinger deleted the rename-no-useless-template-literal branch May 29, 2024 06:45
@Eugeno
Copy link

Eugeno commented Jun 4, 2024

"no-useless-template-expression" was renamed to "no-unnecessary-template-expression", but in the release note:

eslint-plugin: [no-useless-template-literals] rename to no-useless-template-expression (deprecate no-useless-template-literals) (#8821)

same for issues 8597, 8669, 8677.

@kirkwaiblinger
Copy link
Member Author

@Eugeno

Yes, the premature merge was a tad unfortunate. Was amended in #9174, which went in before the release, though, so the only impact should be a small handful of slightly confusing release notes and issue/pr titles, but nothing overt to the user

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 approval One team member has approved this PR; a second should be enough to merge it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docs: Clarify purpose of no-useless-template-literal (or rename?)
5 participants