]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-useless-concat.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-useless-concat.md
CommitLineData
eb39fafa
DC
1# Disallow unnecessary concatenation of strings (no-useless-concat)
2
3It's unnecessary to concatenate two strings together, such as:
4
5```js
6var foo = "a" + "b";
7```
8
9This 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:
10
11```js
12var foo = "ab";
13```
14
15## Rule Details
16
17This 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.
18
19Examples of **incorrect** code for this rule:
20
21```js
22/*eslint no-useless-concat: "error"*/
23/*eslint-env es6*/
24
25var a = `some` + `string`;
26
27// these are the same as "10"
28var a = '1' + '0';
29var a = '1' + `0`;
30var a = `1` + '0';
31var a = `1` + `0`;
32```
33
34Examples of **correct** code for this rule:
35
36```js
37/*eslint no-useless-concat: "error"*/
38
39// when a non string is included
40var c = a + b;
41var c = '1' + a;
42var a = 1 + '1';
43var c = 1 - 2;
44// when the string concatenation is multiline
45var c = "foo" +
46 "bar";
47```
48
49## When Not To Use It
50
51If you don't want to be notified about unnecessary string concatenation, you can safely disable this rule.