constructor-super
Added in v0.1.14Configuration
Rule Details
Verifies that constructors of derived classes (classes that extend another class) call super(), and that constructors of non-derived classes do not call super(). Also detects duplicate super() calls in the same constructor. A return with a value substitutes for super(); a bare return; does not. Explicit constructors in classes extending null must return a value, because null cannot be called as a constructor.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Autofix and Suggestions
This rule does not provide autofixes or suggestions.
Differences from Upstream
The upstream reference is ESLint v10.8.1. Rslint preserves its diagnostic messages and ranges, but corrects the following code-path bugs:
return super()is a single call, not a duplicate. Returning a value is tracked separately from initializingthis, so afinallyblock can replace the pending return.- A literal-false loop does not revisit its body.
do { super(); } while (false)calls once; pure constant loop conditions and parentheses do not introduce imaginary exits or back edges. - Every label directly attached to a loop refers to that loop.
outer: inner: while (true) { super(); continue outer; }has a repeatable call and reportsduplicate. - Binding defaults use the incoming value: a known own data property with
undefinedtriggers the default, a known supplied value skips it, and unknown values retain both paths. Getter, iterator and assignment operations remain possible exception sources. - A catch is reached from potentially throwing operations, not declaration names or the normal end of a try. Retrying a
super()that threw before bindingthisis not itself a duplicate. Instance element initialization can throw after bindingthis; a second call in that catch is still a duplicate. - Nested class static field initializers and static blocks run during class definition. Their escaping exceptions reach the enclosing catch; instance field initializers and method bodies remain deferred. ESLint v10.8.1 misses the static initialization exception paths.
- Ordinary template substitutions and computed property names can throw during conversion after a successful
super(). Such a catch cannot safely retrysuper(). Literal primitive conversions do not create exception paths, and tagged templates pass substitution values without automatic string conversion. finallyruns for normal, returned, thrown, break and continue completions. Its own abrupt completion replaces the pending one. An unconditional object return from finally satisfies the constructor; a bare return that replaces an object return still requires initializedthis.- A
forupdate expression does not erase the body's call state. For example, the loop below reportsmissingSomeandduplicate; ESLint v10.8.1 reports onlymissingAll.
Rslint also reports badSuper for super() in a constructor without an extends clause. ESLint's parser rejects this syntax before the rule runs.
As in the pinned rule, arbitrary call return values are not inferred while selecting logical branches. The complete upstream suite retains that conservative contract.