Lint Rules

noConstructorReturn (since v11.0.0)

Disallow returning a value from a constructor

While returning a value from a constructor does not produce an error, the returned value is being ignored. Therefore, returning a value from a constructor is either unnecessary or a possible error.

Only returning without a value is allowed, as it’s a control flow statement.

Examples

Invalid

class A {
    constructor() {
        return 0;
    }
}
nursery/noConstructorReturn.js:3:9 lint/nursery/noConstructorReturn ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

   The constructor should not return a value.
  
    1 │ class A {
    2 │     constructor() {
  > 3 │         return 0;
           ^^^^^^^^^
    4 │     }
    5 │ }
  
   The constructor is here:
  
    1 │ class A {
  > 2 │     constructor() {
       ^^^^^^^^^^^^^^^
  > 3 │         return 0;
  > 4 │     }
       ^
    5 │ }
    6 │ 
  
   Returning a value from a constructor is ignored.
  

Valid

class A {
    constructor() {}
}
class B {
    constructor(x) {
        return;
    }
}