noUselessStringConcat
Este conteúdo não está disponível em sua língua ainda.
Summary
Section titled “Summary”- Rule available since:
v1.8.0 - Diagnostic Category:
lint/complexity/noUselessStringConcat - This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Same as
no-useless-concat
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "complexity": { "noUselessStringConcat": "error" } } }}Description
Section titled “Description”Disallow unnecessary concatenation of string or template literals.
This rule aims to flag concatenation of string or template literals when they could be combined into a single literal. Notably, this also includes concatenating a string with a number (unlike the derivative ESLint rule).
Concatenation of multiple strings is allowed for multi-line strings (such as ones used to prevent exceeding the maximum line width).
Examples
Section titled “Examples”Invalid
Section titled “Invalid”const a = "a" + "b";code-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.
ℹ Safe fix: Remove the useless concatenation
1 │ - const·a·=·“a”·+·“b”;
1 │ + const·a·=·“ab”;
2 2 │
const foo = "string" + 123;code-block.js:1:13 lint/complexity/noUselessStringConcat FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Useless string concatenation.
> 1 │ const foo = “string” + 123;
│ ^^^^^^^^^^^^^^
2 │
ℹ Consider turning the expression into a single string to improve readability and runtime performance.
ℹ Safe fix: Remove the useless concatenation
1 │ - const·foo·=·“string”·+·123;
1 │ + const·foo·=·“string123”;
2 2 │
const a = "a" + "b" + "c";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.
ℹ Safe fix: Remove the useless concatenation
1 │ - const·a·=·“a”·+·“b”·+·“c”;
1 │ + const·a·=·“abc”;
2 2 │
const a = (foo + "a") + ("b" + "c");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.
ℹ Safe fix: Remove the useless concatenation
1 │ - const·a·=·(foo·+·“a”)·+·(“b”·+·“c”);
1 │ + const·a·=·(foo·+·“a”)·+·(“bc”);
2 2 │
const a = 1 + 1;const a = 1 * '2';const a = 1 - 2;const a = foo + bar;const a = 'foo' + bar;Multi-line strings are ignored:
const multiline = 'foo' + // formatting 'bar'const alsoMultiline = 'foo' + 'bar' + `baz`Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.