Skip to content

noUselessStringConcat (JavaScript)

Language JavaScript (and super languages)
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).

Concatenations split across multiple lines are allowed (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`