Skip to main content

prefer-addition-subtraction-assignments

has auto-fix
pro+

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;

value++; // LINT: Prefer += or -= over ++ or --.
value--; // LINT: Prefer += or -= over ++ or --.
}

✅ Good:

void main() {
int value = 1;

value += 1;
value -= 1;
}