noClassAssign
诊断类别:lint/suspicious/noClassAssign
¥Diagnostic Category: lint/suspicious/noClassAssign
自从:v1.0.0
¥Since: v1.0.0
来源:
¥Sources:
-
与以下相同:
no-class-assign
¥Same as:
no-class-assign
禁止重新分配类成员。
¥Disallow reassigning class members.
类声明创建了一个我们可以修改的变量,但是,在大多数情况下,修改是一个错误。
¥A class declaration creates a variable that we can modify, however, the modification is a mistake in most cases.
¥Examples
¥Invalid
code-block.js:2:1 lint/suspicious/noClassAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ ‘A’ is a class.
1 │ class A {}
> 2 │ A = 0;
│ ^
3 │
ℹ ‘A’ is defined here.
> 1 │ class A {}
│ ^
2 │ A = 0;
3 │
code-block.js:1:1 lint/suspicious/noClassAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ ‘A’ is a class.
> 1 │ A = 0;
│ ^
2 │ class A {}
3 │
ℹ ‘A’ is defined here.
1 │ A = 0;
> 2 │ class A {}
│ ^
3 │
code-block.js:3:3 lint/suspicious/noClassAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ ‘A’ is a class.
1 │ class A {
2 │ b() {
> 3 │ A = 0;
│ ^
4 │ }
5 │ }
ℹ ‘A’ is defined here.
> 1 │ class A {
│ ^
2 │ b() {
3 │ A = 0;
code-block.js:3:3 lint/suspicious/noClassAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ ‘A’ is a class.
1 │ let A = class A {
2 │ b() {
> 3 │ A = 0;
│ ^
4 │ // let A
is shadowed by the class name.
5 │ }
ℹ ‘A’ is defined here.
> 1 │ let A = class A {
│ ^
2 │ b() {
3 │ A = 0;
¥Valid
¥Related links