unnecessaryConcatenation
Reports string concatenation using the + operator when both operands are string literals.
✅ This rule is included in the ts stylistic preset.
Concatenating string literals with the + operator is unnecessary and reduces code readability. String literals can be combined into a single literal, which is clearer and potentially more performant. This rule reports cases where two string literals are concatenated using the + operator when they could be combined into a single string literal.
Examples
Section titled “Examples”const message = "Hello" + "World";const path = "directory" + "/" + "file.txt";const multiLine = "This is a very long string that " + "continues on the next line";const message = "HelloWorld";const path = "directory/file.txt";const multiLine = "This is a very long string that continues on the next line";// Concatenating with variables is allowedconst greeting = "Hello" + name;const fullPath = basePath + "/file.txt";// Template literals are a better choice for string interpolationconst template = `Hello ${name}`;Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase uses string concatenation intentionally for code clarity or consistency (for example, when breaking long strings across multiple lines for readability), you might choose to disable this rule. However, in most cases, combining string literals or using template literals improves code quality.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
noUselessStringConcat - ESLint:
no-useless-concat - Oxlint:
eslint/no-useless-concat