How to enforce in JavaScript using ESLint not to use myStr = myStr + 'Some string'
and use myStr += 'Some string'
.
Asked
Active
Viewed 49 times
0

Penny Liu
- 15,447
- 5
- 79
- 98

mapledreams
- 67
- 8
1 Answers
2
You can use the operator-assignment rule:
/*eslint operator-assignment: ["error", "always"]*/
x = x + y;
// The above line will throw a linting error
x += y;
// The above line will not throw a linting error
(keep in mind, this will apply to all forms of operator assignment, like *
and -
etc, not just +
)

CertainPerformance
- 356,069
- 52
- 309
- 320