Skip to content

Rule proposal: no-constructor-return #12481

@chiawendt

Description

@chiawendt

Please describe what the rule should do:

Forbid return statements in constructors.

What category of rule is this? (place an "X" next to just one item)

[x] Suggests an alternate way of doing something (suggestion)

Provide 2-3 code examples that this rule will warn about:

class Foo {
  constructor () {
    return Math;
  }
}

class Goo {
  constructor () {
    return this;
  }
}

Why should this rule be included in ESLint (instead of a plugin)?

In Javascript return value in constructor is allowed, and the return value is the evaluated value when the class is new-ed. A class created with pattern behaves very differently from a normal class in the OOP paradigm, for example, in that every new instance should be a separate object. There seemed to be no practical usage of this pattern. Forbidding this pattern prevents mistake resulting from unfamiliarity with the language or copy-paste error.

Are you willing to submit a pull request to implement this rule?

Possibly.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionfeatureThis change adds a new feature to ESLintruleRelates to ESLint's core rules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions