Skip to content
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: prefer-numeric-literals warns Number.parseInt (fixes #8913) #8929

Merged
merged 2 commits into from Jul 16, 2017

Conversation

platinumazure
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[x] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

See #8913.

What changes did you make? (Give an overview)

The prefer-numeric-literals rule now warns on Number.parseInt invocations as well as parseInt invocations.

Is there anything you'd like reviewers to focus on?

Nothing in particular.

@platinumazure platinumazure added accepted There is consensus among the team that this change meets the criteria for inclusion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules labels Jul 12, 2017
@mention-bot
Copy link

@platinumazure, thanks for your PR! By analyzing the history of the files in this pull request, we identified @not-an-aardvark and @annie to be potential reviewers.

@eslintbot
Copy link

LGTM

Copy link
Member

@gyandeeps gyandeeps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I would recommend adding some of the tests for the similar style use cases present in no-alert unit test. I think that would help with some of the not so common use cases.

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I just have one minor question.

* false otherwise.
*/
function isParseInt(calleeNode) {
if (calleeNode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this null check necessary? I think CallExpressions always have callee nodes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably not strictly necessary, do you believe it needs to be removed?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally don't like having unused checks "just in case". If a CallExpression doesn't have a callee for whatever reason, some invariant has been violated and the rule is likely to do the wrong thing anyway, since we don't know what the "right thing" would be. This also makes it much harder to detect bugs in other parts of the code (in this case, the parser) because the rule just fails silently rather than throwing if it encounters something unexpected.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I can remove it. Maybe you should switch your review to Request Changes so nobody accidentally merges this in?

@platinumazure
Copy link
Member Author

@gyandeeps Are you talking about things like parseInt (or alert, in the no-alert rule) being shadowed? If so, I did notice that the rule is not properly taking those scenarios into account and have decided to treat that as a separate Fix PR in the future. Otherwise, can you please clarify which tests you're referring to? Thanks!

@gyandeeps
Copy link
Member

@platinumazure those are the things i was talking about. Thanks for checking.

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eslintbot
Copy link

LGTM

Copy link
Member

@not-an-aardvark not-an-aardvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

* @returns {boolean} True if the callee is `parseInt` or `Number.parseInt`,
* false otherwise.
*/
function isParseInt(calleeNode) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could probably be done a lot simple with selectors, but this is fine.

@platinumazure
Copy link
Member Author

platinumazure commented Jul 15, 2017 via email

@platinumazure platinumazure merged commit 128591f into master Jul 16, 2017
@platinumazure platinumazure deleted the issue8913-number-parseint branch July 16, 2017 19:35
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Feb 6, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion enhancement This change enhances an existing feature of ESLint rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants