Skip to content

noUnreachableSuper

Diagnostic Category: lint/correctness/noUnreachableSuper

Since: v1.0.0

Sources:

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

class A extends B {
constructor() {}
}
code-block.js:2:5 lint/correctness/noUnreachableSuper ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

This constructor has code paths that return without calling </span><span style="color: Tomato;"><strong>super()</strong></span><span style="color: Tomato;">.

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 </span><span style="color: Tomato;"><strong>this</strong></span><span style="color: Tomato;"> without calling </span><span style="color: Tomato;"><strong>super()</strong></span><span style="color: Tomato;"> first.

1 │ class A extends B {
> 2 │ constructor(value) {
^^^^^^^^^^^^^^^^^^^^
> 3 │ this.prop = value;
> 4 │ super();
> 5 │ }
^
6 │ }
7 │

</span><span style="color: lightgreen;"><strong>this</strong></span><span style="color: lightgreen;"> 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 </span><span style="color: Tomato;"><strong>super()</strong></span><span style="color: Tomato;">.

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.

export default class A extends B {
constructor() {
super();
}
}
export class A {
constructor() {}
}