New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rule proposal: no-constructor-return #12481
Rule proposal: no-constructor-return #12481
Comments
I support this proposal. |
@kaicataldo Will you champion this? If so, it'll be better that remove your 👍. |
I've added 👍 so any of us can champion and this is accepted. |
Would it be valuable to add an option, so that any named non-arrow non-generator non-async function also was warned by this rule? (it'd probably want to ignore any |
@ljharb Seems like a good idea to also check non-class (is there a better term for that? Prototypal?) constructor functions, though I would advocate for adding that in later since we already have a PR. |
ah, didn't realize #12529 existed. I'd call them legacy constructors. |
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:
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.
The text was updated successfully, but these errors were encountered: