sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-useless-interpolation`
Closed
#1,261 opened on May 11, 2021
help wantednew rule
Repository metrics
- Stars
- (5,022 stars)
- PR merge metrics
- (Avg merge 1d 16h) (399 merged PRs in 30d)
Description
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
const withString = `${str}`;
const withStringLiteral = `${'abc'}`;
const withMultipleStringLiterals = `${'abc'}${'def'}`;
Pass
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.