Disallow ++ and – (no-plusplus)
The no-plusplus
rule flags the use of unary operators, ++
and --
.
var foo = 0;
foo++;
The ++
and --
operators are subject to automatic semicolon insertion. When their use is allowed, introducing whitespace may change semantics of source code. Enabling the rule may prevent this kind of errors.
var i = 10;
var j = 20;
i ++
j
// i = 11, j = 20
var i = 10;
var j = 20;
i
++
j
// i = 10, j = 21
Rule Details
This rule is aimed at flagging the use of ++
and --
. Some believe that the use of these unary operators reduces code quality and clarity. There are some programming languages that completely exclude these operators.
The following patterns are considered warnings:
var foo = 0;
foo++;
var bar = 42;
bar--;
The following patterns are not considered warnings:
var foo = 0;
foo += 1;
var bar = 42;
bar -= 1;
Version
This rule was introduced in ESLint 0.0.9.