Disallow unnecessary concatenation of strings (no-useless-concat)

It’s unnecessary to concatenate two strings together, such as:

varfoo="a"+"b";

This code is likely the result of refactoring where a variable was removed from the concatenation (such as "a" + b + "b"). In such a case, the concatenation isn’t important and the code can be rewritten as:

varfoo="ab";

Rule Details

This rule aims to flag the concatenation of 2 literals when they could be combined into a single literal. Literals can be strings or template literals.

Examples of incorrect code for this rule:

/*eslint no-useless-concat: "error"*//*eslint-env es6*/// these are the same as "10"vara=`some`+`string`;vara='1'+'0';vara='1'+`0`;vara=`1`+'0';vara=`1`+`0`;

Examples of correct code for this rule:

/*eslint no-useless-concat: "error"*/// when a non string is includedvarc=a+b;varc='1'+a;vara=1+'1';varc=1-2;// when the string concatenation is multilinevarc="foo"+"bar";

When Not To Use It

If you don’t want to be notified about unnecessary string concatenation, you can safely disable this rule.