Skip to content
← Back to rules

eslint/no-constructor-return Pedantic

What it does

Disallow returning value from constructor.

Why is this bad?

In JavaScript, returning a value in the constructor of a class may be a mistake. Forbidding this pattern prevents mistakes resulting from unfamiliarity with the language or a copy-paste error.

Examples

Examples of incorrect code for this rule:

js
class C {
  constructor() {
    return 42;
  }
}

Examples of correct code for this rule:

js
class C {
  constructor() {
    this.value = 42;
  }
}

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "no-constructor-return": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-constructor-return": "error",
  },
});
bash
oxlint --deny no-constructor-return

References