noClassAssign
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/suspicious/noClassAssign
Since: v1.0.0
Sources:
- 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
Section titled ExamplesInvalid
Section titled Invalidcode-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;