# no-plusplus

> Disallow the `++` and `--` operators

`i++` and `++i` change the variable the same way but evaluate to different values: the old one and the new one. That's easy to get wrong inside a larger expression such as `queue[--position]`. `i += 1` as its own statement leaves nothing to mix up.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"no-plusplus" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-plusplus" = ["error", {
  allowForLoopAfterthoughts = false,
}]
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
let retries = 0;
retries++;

const next = queue[--position];
```

Not reported:

{/* good */}
```js
let retries = 0;
retries += 1;

position -= 1;
const next = queue[position];
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowForLoopAfterthoughts` | `false` | Allow `++` and `--` in the last part of a `for (;;)` header. |

With `{ allowForLoopAfterthoughts: true }`, this is allowed:

{/* good {"options": [{"allowForLoopAfterthoughts": true}]} */}
```js
for (let i = 0, j = items.length - 1; i < j; i++, j--) {
  swap(items, i, j);
}
```

In the loop body they're still reported:

{/* bad {"options": [{"allowForLoopAfterthoughts": true}]} */}
```js
for (let i = 0; i < items.length; ) {
  send(items[i]);
  i++;
}
```
