super() should be called only once in the constructor

  • MULTIPLE_SUPER_CALL
  • Error
  • High
  • es6

This rule applies when super() is called multiple times in the constructor.

Multiple super() calls throw a ReferenceError exception.

Noncompliant Code Example

View with compliant examples side by side
class A {}
class B extends A {
  constructor(props) {
    super(props);
    props.forEach(p => test(p));
    super(props); // MULTIPLE_SUPER_CALL alarm
  }
}
const obj = new B(props);

Compliant Code Example

View with noncompliant examples side by side
class A {}
class B extends A {
  constructor(props) {
    super(props);
    props.forEach(p => test(p));
  }
}
const obj = new B(props);

Version

This rule was introduced in DeepScan 1.11.0-beta.

See

Was this documentation helpful?