Skip to content

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.

const message = "Hello" + "World";
const path = "directory" + "/" + "file.txt";
const multiLine =
"This is a very long string that " + "continues on the next line";

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.