Linter · Rules
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.
Configure
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-multi-assign" = "error" # or "warn"
Every option, set to its default:
bunfig.toml
[lint.rules]
"no-multi-assign" = ["error", {
ignoreNonDeclaration = false,
}]
Examples
Reported:
const width = height = 100;
let first, last;
first = last = items[0];
class Box {
width = this.height = 100;
}
Not reported:
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. |
let first, last;
first = last = items[0];
const width = height = 100;