src/content/docs/linter/rules/no-useless-string-concat.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.8.0` - Diagnostic Category: [`lint/complexity/noUselessStringConcat`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-useless-concat`](https://eslint.org/docs/latest/rules/no-useless-concat){
"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";
const foo = "string" + 123;
const a = "a" + "b" + "c";
const a = (foo + "a") + ("b" + "c");
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`