Do you want to work on this issue?
You can request for a bounty in order to promote it!
Rule proposal: `no-useless-interpolation` #1261
karlhorky posted onGitHub
<!-- 🍩 Please don't ignore this template -->
<!-- 1️⃣ Explain here why this rule would be beneficial -->
Hi there! 👋 First of all, thanks again for this plugin, super helpful, the things available in this plugin.
I wanted to propose a new rule to address a pattern that I have seen from a lot of our students at @upleveled - writing overly complex patterns with unnecessary interpolations in template strings (eg. a single string variable, or a string literal, or multiple string literals).
Fail
<!-- 2️⃣ Specify an example of code that should be detected -->
const withString = `${str}`;
const withStringLiteral = `${'abc'}`;
const withMultipleStringLiterals = `${'abc'}${'def'}`;
Pass
<!-- 3️⃣ Specify an example of code that would be accepted in its place -->
const withString = str;
const withStringLiteral = 'abc';
const withMultipleStringLiterals = 'abcdef';
Implementation ideas
Looking into the ASTExplorer, I guess the simple version of the first failure case below would be:
- only 1 element in
TemplateLiteral.expressions
(anIdentifier
) - only 2 elements in
TemplateLiteral.quasis
, all empty strings
For the literals, I guess no limit to the quasis
, but every element in expressions
should be a Literal
.