Skip to content

unnecessaryConcatenation

Reports string concatenation using the + operator when both operands are string literals.

✅ This rule is included in the ts stylistic and stylisticStrict presets.

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.

AEconsB0messaAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DHel1<1"sp ansty="le--0:#C792EA;--1:#8844">AE <+ sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DWor1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">AEconsB0paAE <= sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Ddirecto1<1"sp ansty="le--0:#C792EA;--1:#8844">AE <+ sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">41<1"sp ansty="le--0:#C792EA;--1:#8844">AE <+ sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dfile.t1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meec-li">AEconsB0multiLiAE< =d ivclassNa="meec-li">nt< sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4DThis is a very long string tha1<1"sp ansty="le--0:#C792EA;--1:#8844">AE <+ sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dcontinues on the next li1<1"sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><";d>
44AEco61B0mes44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DHelloW1<111" spans="tyle--0:#D6DEEB;--1:#40">344AEco61B044A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Ddirectory/file<.txt spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">344AEco61B0multi44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DThis is a very long string that continues on the next 1<111" spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">6376// Concatenating with variables is all44AEco61B0gree44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4DH1<111" spans="tyle--0:#C792EA;--1:#88">44A3F53n44AEco61B0full44A3F53base44A1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D/file<.txt spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#D6DEEB;--1:#40">3<;di vdivclass="Nameexpressive-">6376// Template literals are a better choice for string interpola44AEco61B0temp44A361B0He38<34${ spans="tyle--0:#D6DEEB;--1:#40">3F533<834} spans="tyle--0:#D6DEEB;--1:#40">33

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.