# constructor-super

> Require `super()` to be called exactly once in the constructor of a derived class

In a class with `extends`, the constructor must call `super()` before it uses `this` or returns. Without the call, `new` throws a `ReferenceError`. A second call throws too. These errors only show up when that path through the constructor runs.

The rule follows every path through the constructor. It reports a path that has no `super()`, a path that calls it twice, and a `super()` in a class that extends something that can't be a constructor, such as `null`.

This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript already reports a missing `super()`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

On by default as an error. To turn it off:

```toml bunfig.toml
[lint.rules]
"constructor-super" = "off" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
class Admin extends User {
  constructor(name) {
    this.name = name;
  }
}
```

{/* bad */}
```js
class Admin extends User {
  constructor(name) {
    if (name) {
      super(name);
    }
  }
}
```

{/* bad */}
```js
class Admin extends User {
  constructor(name) {
    super(name);
    super(name.trim());
  }
}
```

{/* bad */}
```js
class Dictionary extends null {
  constructor() {
    super();
  }
}
```

Not reported:

{/* good */}
```js
class Admin extends User {
  constructor(name) {
    super(name);
    this.role = "admin";
  }
}

class Guest extends User {
  constructor(name) {
    if (name) {
      super(name);
    } else {
      super("Guest");
    }
  }
}

// Without a constructor, `super()` is called for you.
class Member extends User {}
```
