Skip to content

No Increment Decrement

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

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

Rationale

My reasoning for this rule are pretty much identical to why Swift removed them back in Swift 3.

  • Low utility relative to the readability loss: these operators only save a few characters compared to value += 1 or value -= 1. Almost never worth it.

  • 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 are redundant with += and -=, which are more general and therefore more useful. You can increment or decrement by any value, not just 1.

  • Clarity over brevity: we like to prioritize explicit and readable code. Writing value += 1 makes the intent immediately clear without requiring anyone to puzzle over operator precedence.

Now, where I differ on Swift is instead of banning it entirely, I allow it for array[size++] = value expressions. I already prefer doing this over array.push(value) when possible for performance reasons, and I think the increment operator is a nice shorthand for this specific use case. That is why this rule exists when the native Oxlint version also does.

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;