prefer-addition-subtraction-assignments
Warns when ++
or --
is used instead of +=
or -=
.
Using ++
does not make it obvious that the underlying variable is actually being mutated, whereas +=
more clearly does (it's an assignment with an =
sign).
Additionally, +=
is more convenient when changing the increment to a number other than 1
.
Example
❌ Bad:
void main() {
int value = 1;
// LINT: Prefer += or -= over ++ or --.
value++;
// LINT: Prefer += or -= over ++ or --.
value--;
}
✅ Good:
void main() {
int value = 1;
value += 1;
value -= 1;
}