# no-multi-assign

> Disallow chained assignments such as `a = b = c`

In `const width = height = 100`, only `width` is declared. `height` is a plain assignment. It throws in strict mode if nothing declares it, and creates a global variable otherwise. Even when every name is declared, the second assignment is easy to overlook.

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

Every option, set to its default:

```toml bunfig.toml
[lint.rules]
"no-multi-assign" = ["error", {
  ignoreNonDeclaration = false,
}]
```

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

## Examples

Reported:

{/* bad */}
```js
const width = height = 100;
```

{/* bad */}
```js
let first, last;
first = last = items[0];
```

{/* bad */}
```js
class Box {
  width = this.height = 100;
}
```

Not reported:

{/* good */}
```js
const width = 100;
const height = 100;

let first, last;
first = items[0];
last = first;
```

## Options

| Option | Default | What it does |
| --- | --- | --- |
| `ignoreNonDeclaration` | `false` | Only report chains in a `var`, `let` or `const` declaration or a class field. Allow them between variables that already exist. |

{/* good {"options": [{"ignoreNonDeclaration": true}]} */}
```js
let first, last;
first = last = items[0];
```

{/* bad {"options": [{"ignoreNonDeclaration": true}]} */}
```js
const width = height = 100;
```
