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

Rule proposal: detect useless template literal interpolation #2846

Closed
3 tasks done
karlhorky opened this issue Dec 3, 2020 · 3 comments · Fixed by #7957
Closed
3 tasks done

Rule proposal: detect useless template literal interpolation #2846

karlhorky opened this issue Dec 3, 2020 · 3 comments · Fixed by #7957
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@karlhorky
Copy link

karlhorky commented Dec 3, 2020

Hi there,

First of all, thanks for this great set of ESLint + TS utilities, these are great!

I am unsure if I'm doing this right, because the issue template was about bug reports, but I would like to propose a new rule. Since I didn't see a template for this, I'm going to go ahead like this, and then can change it / resubmit if necessary.

What I wanted to bring up was the idea of a @typescript-eslint/no-useless-interpolation rule, similar to the eslint/eslint#10798 proposal to ESLint, which as far as I can tell, never got implemented.

The idea would be, if there is useless interpolation with a template string, this would be an error.

Example of incorrect code:

`${'abc'}` // incorrect

const str = 'def';
`${str}` // incorrect

`123${'abc'}` // incorrect

`${'abc'}${'def'}` // incorrect

Examples of correct code:

'abc' // correct

const str = 'def';
str // correct

'123abc' // correct

'abcdef' // correct

I would suggest only doing this for strings.

Remaining template things

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.
@karlhorky karlhorky added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Dec 3, 2020
@bradzacher bradzacher added enhancement: new plugin rule New rule request for eslint-plugin and removed triage Waiting for maintainers to take a look labels Dec 3, 2020
@JoshuaKGoldberg JoshuaKGoldberg added the accepting prs Go ahead, send a pull request that resolves this issue label Oct 25, 2021
@bradzacher bradzacher changed the title [no-useless-interpolation] Rule proposal Rule proposal: detect useless template literal interpolation May 3, 2022
@KurtPreston
Copy link

@bradzacher
Copy link
Member

@KurtPreston whilst it shares the name - that rule is very different. For starters - it only works on template strings tagged with html. Second it doesn't support variables - only literals.

@rentalhost
Copy link

Would be nice if we can have that!

StyleShit added a commit to StyleShit/typescript-eslint that referenced this issue Nov 19, 2023
JoshuaKGoldberg added a commit that referenced this issue Dec 12, 2023
* feat(eslint-plugin): [no-useless-template-literals] add new rule

Closes #2846

* fix tests

* thank you josh

* hopefully fix tests?

* support template literals with new lines

* support also quotes

* fix all files (damn, we need an auto fixer...)

* wip

* report on specific node

* fix docs

* fix lint

* wip

* fix lint

* revert unrelated changes

* more reverts

* wip

* wip

---------

Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: new plugin rule New rule request for eslint-plugin package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants