Skip to content

noUnreachableSuper (since v1.0.0)

Diagnostic Category: lint/correctness/noUnreachableSuper

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() {}
}
correctness/noUnreachableSuper.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();
}
}
correctness/noUnreachableSuper.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();
}
}
}
correctness/noUnreachableSuper.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.
  
export default class A extends B {
constructor() {
super();
}
}
export class A {
constructor() {}
}