-
Notifications
You must be signed in to change notification settings - Fork 657
🐛 noConstructorReturn
reasoning is wrong
#4005
Comments
@Conaclos what do you think? You implemented the rule in the first place, your input would be really valuable! |
We should note though that a linter is not a compiler, what we consider to be errors is not strictly bound to the ECMAScript spec, and we can afford to be more strict if it helps catch potential errors, that's what the |
Yes. However, it is harmful regarding the mental model that developers generally have about classes. There is only one case or the returned value affects the program: when derived classes enter the play. By the way, MDN discourages the use of this "feature":
We could update the rule description in a way that does not contradict MDN docs. However, I think we should avoid describing this "feature". We could relax the rule and allow returning |
I think it's totally reasonable for a linter to be rather parental about a "technically could be valid, but usually a bad idea" case like this — I don't feel strongly about the rule, I would just advocate updating the docs if the intention is to warn on "valid" use cases! |
Environment information
What happened?
https://docs.rome.tools/lint/rules/noconstructorreturn/ states:
This is inaccurate:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/constructor
I'm not saying it's a great idea to do so, but it's not particularly harmful to the type safety of the program if the returned object is of the same class (that the constructor would already return).
Expected result
The rule should either avoid erroring on returned objects (at least when the return type matches the constructor's class), or the documentation should be updated.
Code of Conduct
The text was updated successfully, but these errors were encountered: