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
Update: Report constructor calls in no-obj-calls #12909
Conversation
Would it also be worth throwing on |
Like |
|
I think this isn't related to globals, |
Yes, so is new Math(). I’m suggesting that the “no object calls” rule should warn on builtin objects that aren’t functions, which includes both Math and Boolean.prototype. |
I understand the logic now - for every builtin function Makes sense (just not sure how often people write |
Perhaps, just seems like an easy addition and in the same spirit of the RFC. |
I support this change, though I think we should mark it as breaking since the rule is catching a whole new class of error. |
@kaicataldo it seems like the same class to me - using |
I’m not a fan of checking for prototypes as I just don’t think that’s a common enough mistake. However, if others disagree please open a separate issue to discuss. We shouldn’t add anything more to this PR. |
I mean, fair, but is |
@mdjermanovic it looks like there’s a merge conflict, can you rebase and fix the conflicts? |
5e7eb82
to
f5ea76f
Compare
Rebased, fixed conflicts, and added some tests that combine changes from this PR with changes from #12774. |
That seems like a good idea to get #11984 unblocked. 👍 to adding those commits to this PR |
Done! (tests are failing only because of #13076). |
Merged #13076. Can you try rebasing to see if that makes the CI happy? |
d7b83c7
to
792f8a3
Compare
It works well now 🎉 |
Awesome, thanks! |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[X] Changes an existing rule
Note: this PR also removes
Math
andJSON
from theno-new-wrappers
rule.What rule do you want to change?
no-obj-calls
Does this change cause the rule to produce more or fewer warnings?
more
How will the change be implemented? (New option, new default behavior, etc.)?
new default behavior
Please provide some example code that this change will affect:
What does the rule currently do for this code?
no errors
What will the rule do after it's changed?
4 errors
What changes did you make? (Give an overview)
Updated
no-obj-calls
to warn onNewExpression
as well.Is there anything you'd like reviewers to focus on?
As suggested in #11984 (comment),
no-obj-calls
instead ofno-new-wrappers
should reportnew Math()
andnew JSON()
. I guess it makes sense to report all 4 objects when used withnew
, it's always a runtime error.I think there is no need for a new messageId.