Skip to content

Rule proposal: detect useless template literal interpolation #2846

Closed
@karlhorky

Description

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.

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: new plugin ruleNew rule request for eslint-pluginpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions