no-class-assign
不允许重新分配类成员
配置文件 中的
"extends": "eslint:recommended"
属性启用了该规则
ClassDeclaration
创建了一个变量,我们可以修改这个变量。
/*eslint-env es6*/
class A { }
A = 0;
但在大多数情况下,修改是错误的。
规则详情
该规则旨在标记修改类声明的变量。
KIjVZ8jbyN1kWo441FXYIh3AmcQhCDgs/8OlFVGexGn4OCCKsdfcgNWXdLQQbb4u
/*eslint no-class-assign: "error"*/
/*eslint-env es6*/
class A { }
A = 0;
/*eslint no-class-assign: "error"*/
/*eslint-env es6*/
A = 0;
class A { }
/*eslint no-class-assign: "error"*/
/*eslint-env es6*/
class A {
b() {
A = 0;
}
}
/*eslint no-class-assign: "error"*/
/*eslint-env es6*/
let A = class A {
b() {
A = 0;
// `let A` is shadowed by the class name.
}
}
AoqXtTV6Q8irP1mRQNh34rATVScSSkZAU175f14ev6145njeerHH1txMZ4OQcdup
/*eslint no-class-assign: "error"*/
/*eslint-env es6*/
let A = class A { }
A = 0; // A is a variable.
/*eslint no-class-assign: "error"*/
/*eslint-env es6*/
let A = class {
b() {
A = 0; // A is a variable.
}
}
/*eslint no-class-assign: 2*/
/*eslint-env es6*/
class A {
b(A) {
A = 0; // A is a parameter.
}
}
何时不使用
VUPoE9Nq6d7iihsKAqbqY+A1e9djyJZ3o9JlP2lIwPuURwWw7NsuvgsdF4NR7fhCfvRJgfNmZrS4+ihnIvJICPHioZ1I8Hit1pBNVWnLf9h/Cn9arp+UCKvPjy7kXS4KtLwbrsUF/zkVgsPHYqapRQ==