Skip to content

Rule proposal: detect useless template literal interpolation #2846

@karlhorky

Description

@karlhorky

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

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy