Skip to content

No Increment Decrement

SuggestionAuto-fixable
small-rules/no-increment-decrement

Disallow standalone `++` and `--` statements and for-loop update clauses.

Rationale

This matches the reason Swift removed these operators in Swift 3.

  • Low utility relative to the readability loss: these operators only save a few characters compared to value += 1 or value -= 1. That trade is seldom useful.

  • Prefix vs postfix confusion: having both ++value and value++ is confusing. It can also lead to fun subtle bugs, especially when you nest them inside larger expressions where evaluation order matters.

  • Redundancy: the increment and decrement operators repeat what += and -= already do. You can add or subtract any value, not just 1.

  • Clarity over brevity: explicit code is the goal. Writing value += 1 makes the intent immediately clear without requiring anyone to puzzle over operator precedence.

Swift bans the operators outright. This rule still allows array[size++] = value. That form beats array.push(value) when the extra call costs too much, and the increment is a short spelling for that one case. The native Oxlint rule has no such exception.

Diagnostic Messages

noDecrement
Do not use standalone `--`. Use `-= 1` instead.
noIncrement
Do not use standalone `++`. Use `+= 1` instead.

Configuration

This rule accepts one options object after the severity.

allowAutofixOptional

Allow the fixer to replace standalone ++ and -- statements and for-loop updates.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/no-increment-decrement": [
"error",
{
"allowAutofix": false
}
]
}
}

Examples

Post-increment compound assignment fix
size++;

After auto-fix

size += 1;
Compound assignment is allowed
size += 1;