跳转到内容

noUselessStringConcat

此内容尚不支持你的语言。

biome.json
{
"linter": {
"rules": {
"complexity": {
"noUselessStringConcat": "error"
}
}
}
}

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).

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`