eslint/no-this-before-super 正确性
作用
要求在使用 this 或 super 之前先调用 super()。
如果是 TypeScript 代码,可以禁用此规则,因为 TypeScript 编译器 已经强制执行了这一检查。
为什么这不好?
在派生类的构造函数中,如果在调用 super() 之前使用了 this/super, 就会抛出 ReferenceError。
示例
以下是此规则的错误代码示例:
javascript
class A1 extends B {
constructor() {
// 必须先调用 super()
this.a = 0;
super();
}
}如何使用
To enable this rule using the config file or in the CLI, you can use:
json
{
"rules": {
"no-this-before-super": "error"
}
}ts
import { defineConfig } from "oxlint";
export default defineConfig({
rules: {
"no-this-before-super": "error",
},
});bash
oxlint --deny no-this-before-super版本
此规则添加于 v0.2.6。
