no-this-before-super
eslint
No autofixRecommended
eslint.config.js
export default [
{
rules: {
"no-this-before-super": "error",
},
},
];Disallow this/super before calling super() in constructors
class A1 extends B {
constructor() {
this.a = 0;
super();
}
}
class A2 extends B {
constructor() {
this.foo();
super();
}
}
class A3 extends B {
constructor() {
super.foo();
super();
}
}
class A4 extends B {
constructor() {
super(this.foo());
}
}class A1 {
constructor() {
this.a = 0; // OK, this class doesn't have an `extends` clause.
}
}
class A2 extends B {
constructor() {
super();
this.a = 0; // OK, this is after `super()`.
}
}
class A3 extends B {
foo() {
this.a = 0; // OK. this is not in a constructor.
}
}Examples from the ESLint documentation.
no-this-before-super
eslint
export default [
{
rules: {
"no-this-before-super": "error",
},
},
];no-this-before-super
eslint plugin · correctness
{
"rules": {
"no-this-before-super": "error"
}
}correctness/noUnreachableSuper
correctness · since 1.0.0
{
"linter": {
"rules": {
"correctness": {
"noUnreachableSuper": "error"
}
}
}
}Disallow unnecessary boolean casts
Disallow irregular whitespace
Disallow negating the left operand of relational operators
Disallow unreachable code after return, throw, continue, and break statements
Disallow using an async function as a Promise executor