# no-sequences

> Disallow the comma operator

`a, b` evaluates both expressions and keeps only the value of the last one. In `if (load(), ready)` the result of `load()` is thrown away, which is easy to miss. And if you type a comma instead of a `.` or a `;`, the code still parses.

The first and last parts of a `for` header are always allowed, since `for (i = 0, j = 10; i < j; i++, j--)` is the usual way to drive two counters.

{/* 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-sequences" = "error" # or "warn"
```

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-sequences" = ["error", {
  allowInParentheses = true,
}]
```

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

## Examples

Reported:

{/* bad {"count": 2} */}
```js
count++, save();

while (item = queue.shift(), item) {
  handle(item);
}
```

Not reported:

{/* good */}
```js
count++;
save();

for (let i = 0, j = items.length - 1; i < j; i++, j--) {
  swap(items, i, j);
}
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `allowInParentheses` | `true` | Allow a sequence that's wrapped in its own parentheses. |

The parentheses show that the comma is on purpose. Parentheses that belong to the statement, as in `while (..)`, don't count, so you need a second pair there. The same goes for an arrow function's body.

{/* good */}
```js
const last = (step(), result());

while ((item = queue.shift(), item)) {
  handle(item);
}

const log = (value) => ((console.log(value), value));
```

{/* bad */}
```js
const log = (value) => (console.log(value), value);
```

{/* bad {"options": [{"allowInParentheses": false}]} */}
```js
const last = (step(), result());
```
