0

How to enforce in JavaScript using ESLint not to use myStr = myStr + 'Some string' and use myStr += 'Some string'.

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

1 Answers1

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