Skip to content

eslint/no-plusplus Restriction

🚧 An auto-fix is still under development.

What it does

Disallow the unary operators ++`` and --`.

Why is this bad?

Because the unary ++ and -- operators are subject to automatic semicolon insertion, differences in whitespace can change the semantics of source code. For example, these two code blocks are not equivalent:

js
var i = 10;
var j = 20;

i++;
j;
// => i = 11, j = 20
js
var i = 10;
var j = 20;

i;
++j;
// => i = 10, j = 21

Examples

Examples of incorrect code for this rule:

js
var x = 0;
x++;
var y = 0;
y--;
for (let i = 0; i < l; i++) {
  doSomething(i);
}

Examples of correct code for this rule:

js
var x = 0;
x += 1;
var y = 0;
y -= 1;
for (let i = 0; i < l; i += 1) {
  doSomething(i);
}

References

Released under the MIT License.