no-multi-assign

禁止使用链式赋值表达式

链接变量的分配可能会导致意想不到的结果并且难以阅读。

(function() {
    const foo = bar = 0; // Did you mean `foo = bar == 0`?
    bar = 1;             // This will not fail since `bar` is not constant.
})();
console.log(bar);        // This will output 1 since `bar` is not scoped.

规则详情

此规则不允许在单个语句中使用多个赋值。

此规则的错误代码示例:

/*eslint no-multi-assign: "error"*/

var a = b = c = 5;

const foo = bar = "baz";

let a =
    b =
    c;

class Foo {
    a = b = 10;
}

a = b = "quux";

此规则的正确代码示例:

/*eslint no-multi-assign: "error"*/

var a = 5;
var b = 5;
var c = 5;

const foo = "baz";
const bar = "baz";

let a = c;
let b = c;

class Foo {
    a = 10;
    b = 10;
}

a = "quux";
b = "quux";

选项

9NHbribgvlAIiqeVNtZmFJBXFzE5ZrwC3cI4vwFctVWZPLWT9F2r70/2F9O2nCh5

    2E63PxWXZgwghie8srJGmCkbcfu9QDAz0q6FDMKazXvnhFteXTcoJXCD5cvL54u+xysdNoh/T242hEnxGRCf7rhLTZOP7wqDoEini7awblKA17OpnEZRiYJW3GTeObhNPARLREaD4ThTcxUe3wbxwF6nKb5TryKiXmxAdSWa7lIWbvdlOpAKNNfk3TgTS/Q0phuL4NXldRkHKKUISznDgKURlpRwpt0/8r2yQH/TAy4hRVmHhdaxNDoHjS6OapHQ6yjcUOgkuESVrv2GrI5EJA==

ignoreNonDeclaration

jPUWC9XxWF+uwExP8rP1uOHL7ZVVSg96YPS+6hcg6tVxj1q3+NNQQ3gdM8PTkO22nzSRpexqnb7FMUaY+nljJpUzO82CJUEN2KVmFfQ3JAU=

/*eslint no-multi-assign: ["error", { "ignoreNonDeclaration": true }]*/

let a;
let b;
a = b = "baz";

const x = {};
const y = {};
x.one = y.one = 1;

jPUWC9XxWF+uwExP8rP1uOHL7ZVVSg96YPS+6hcg6tVxj1q3+NNQQ3gdM8PTkO229bHfTy+8NiirUm4Uro+RUBur8xLS/ca86WX5/QRG+oc=

/*eslint no-multi-assign: ["error", { "ignoreNonDeclaration": true }]*/

let a = b = "baz";

const foo = bar = 1;

class Foo {
    a = b = 10;
}