For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/eslint/no-constructor-return.md.
close

no-constructor-return

Added in v0.1.14

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-constructor-return': 'error',
    },
  },
]);

Rule Details

Disallows return statements that return a value from class constructors. Returning a value from a constructor of a class is usually a mistake, as the returned value is only used when the constructor is called without new. Bare return statements (without a value) are allowed for flow control purposes.

Examples of incorrect code for this rule:

class A {
  constructor() {
    return 'value';
  }
}

class B {
  constructor() {
    return { something: true };
  }
}

Examples of correct code for this rule:

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

class B {
  constructor() {
    if (!valid) {
      return; // bare return for flow control is fine
    }
    this.init();
  }
}

Original Documentation