π Disallow useless compound assignments such as x += 0.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π‘ This rule is manually fixable by editor suggestions.
A compound assignment by an identity value, like x += 0 or x *= 1, does not change the value and is almost always dead code left over from a bad refactor.
This rule only flags arithmetic operators where the right-hand side is the literal identity value: += 0, -= 0, *= 1, /= 1, and **= 1.
Bitwise operators such as x |= 0, x >>>= 0, and x &= -1 are not flagged, because they are deliberate idioms for coercing a value to a 32-bit integer rather than mistakes.
Because the result of these operations depends on the runtime value of the variable (for example, "a" += 0 produces "a0", "5" *= 1 produces the number 5, 5n *= 1 throws a TypeError, and x += 0 turns -0 into +0), the fix is offered as a suggestion rather than an automatic fix.
// β
let total = getTotal();
total += 0;
// β
let total = getTotal();// β
price *= 1;
// β
// (remove the line)// β
return count -= 0;
// β
return count;