noUselessStringConcat
Diagnostic Category: lint/complexity/noUselessStringConcat
Since: v1.8.0
Sources:
- Same as:
no-useless-concat
Disallow unnecessary concatenation of string or template literals.
This rule aims to flag the concatenation of 2 literals when they could be combined into a single literal. Literals can be strings or template literals. Concatenation of multiple strings is allowed when the strings are spread over multiple lines in order to prevent exceeding the maximum line width.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:11 lint/complexity/noUselessStringConcat FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Useless string concatenation.
> 1 │ const a = “a” + “b”;
│ ^^^^^^^^^
2 │
ℹ Consider turning the expression into a single string to improve readability and runtime performance.
ℹ Unsafe fix: Remove the useless concatenation
1 │ - const·a·=·“a”·+·“b”;
1 │ + const·a·=·“ab”;
2 2 │
code-block.js:1:11 lint/complexity/noUselessStringConcat FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Useless string concatenation.
> 1 │ const a = “a” + “b” + “c”;
│ ^^^^^^^^^^^^^^^
2 │
ℹ Consider turning the expression into a single string to improve readability and runtime performance.
ℹ Unsafe fix: Remove the useless concatenation
1 │ - const·a·=·“a”·+·“b”·+·“c”;
1 │ + const·a·=·“abc”;
2 2 │
code-block.js:1:26 lint/complexity/noUselessStringConcat FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Useless string concatenation.
> 1 │ const a = (foo + “a”) + (“b” + “c”);
│ ^^^^^^^^^
2 │
ℹ Consider turning the expression into a single string to improve readability and runtime performance.
ℹ Unsafe fix: Remove the useless concatenation
1 │ - const·a·=·(foo·+·“a”)·+·(“b”·+·“c”);
1 │ + const·a·=·(foo·+·“a”)·+·(“bc”);
2 2 │