noUnreachableSuper
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noUnreachableSuper¥Diagnostic Category:
lint/correctness/noUnreachableSuper -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
no-this-before-super相同¥Same as
no-this-before-super
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noUnreachableSuper": "error" } } }}¥Description
如果类具有超类,则确保在访问 this 之前,在类构造函数中的每个代码路径上都只调用一次 super() 构造函数
¥Ensures the super() constructor is called exactly once on every code path in a class constructor before this is accessed if the class has a superclass
¥Examples
¥Invalid
class A extends B { constructor() {}}code-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This constructor has code paths that return without calling `super()`.
1 │ class A extends B {
> 2 │ constructor() {}
│ ^^^^^^^^^^^^^^^^
3 │ }
4 │
ℹ If this is intentional, add an explicit throw statement in unsupported paths.
class A extends B { constructor(value) { this.prop = value; super(); }}code-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This constructor has code paths accessing `this` without calling `super()` first.
1 │ class A extends B {
> 2 │ constructor(value) {
│ ^^^^^^^^^^^^^^^^^^^^
> 3 │ this.prop = value;
> 4 │ super();
> 5 │ }
│ ^
6 │ }
7 │
ℹ `this` is accessed here:
1 │ class A extends B {
2 │ constructor(value) {
> 3 │ this.prop = value;
│ ^^^^
4 │ super();
5 │ }
ℹ If this is intentional, add an explicit throw statement in unsupported paths.
class A extends B { constructor(cond) { if(cond) { super(); } }}code-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This constructor has code paths that return without calling `super()`.
1 │ class A extends B {
> 2 │ constructor(cond) {
│ ^^^^^^^^^^^^^^^^^^^
> 3 │ if(cond) {
> 4 │ super();
> 5 │ }
> 6 │ }
│ ^
7 │ }
8 │
ℹ If this is intentional, add an explicit throw statement in unsupported paths.
¥Valid
export default class A extends B { constructor() { super(); }}export class A { constructor() {}}¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号