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

New: prefer-numeric-literals rule (fixes #6068) #7029

Merged
merged 1 commit into from Sep 4, 2016

Conversation

annie
Copy link
Contributor

@annie annie commented Aug 31, 2016

ref: #6068

@mention-bot
Copy link

@azhang496, thanks for your PR! By analyzing the annotation information on this pull request, we identified @nzakas, @alberto and @kaicataldo to be potential reviewers

@eslintbot
Copy link

LGTM

```js
/*eslint prefer-numeric-literals: "error"*/

parseInt(\"111110111\", 2) === 503;
Copy link
Member

Choose a reason for hiding this comment

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

I think the red/syntax highlighting issue is the \" - just " should be ok

@eslintbot
Copy link

LGTM

@@ -0,0 +1,41 @@
# disallow `parseInt` in favor of binary, octal, and hexadecimal literals (prefer-numeric-literals)

Binary and octal literals were introduced in ES6. Prior to this, `parseInt` was used to turn binary and octal strings into integers. This rule encourages use of binary, octal, and hexadecimal literals instead of `parseInt`.
Copy link
Member

Choose a reason for hiding this comment

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

Can you use parseInt() with parens throughout? We try to stick to that convention in the docs.

@nzakas
Copy link
Member

nzakas commented Sep 1, 2016

This looks really good, just a few small things to clean up on the docs.

@eslintbot
Copy link

LGTM

) {
context.report({
node,
message: "Use {{radixName}} literals instead of parseInt",
Copy link
Member

@kaicataldo kaicataldo Sep 2, 2016

Choose a reason for hiding this comment

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

Two small things - could we use parseInt() here to be consistent with the docs? Makes it clear that it's a function as well. Also, would you mind adding a period to the end of the error message? A while back we went through to try to make it consistent: #6762

So I'm thinking: "Use {{radixName}} literals instead of parseInt()."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yes good catch on the parseInt()!

@kaicataldo
Copy link
Member

kaicataldo commented Sep 2, 2016

One nit pick in the error message, but otherwise this looks great to me. Thanks for all the recent contributions, @azhang496!

@eslintbot
Copy link

LGTM

module.exports = {
meta: {
docs: {
description: "disallow `parseInt` in favor of binary, octal, and hexadecimal literals",
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for all the nitpicking - caught one more thing! This should match the other descriptions and say parseInt().

@eslintbot
Copy link

LGTM

@@ -0,0 +1,49 @@
# disallow `parseInt()` in favor of binary, octal, and hexadecimal literals (prefer-numeric-literals)

The `parseInt()` function can be used to turn binary, octal, and hexadecimal strings into integers. As binary, octal, and hexadecimal literals are supported in ES6, this rule encourages use of those numeric literals instead of `parseInt()`.
Copy link
Member

Choose a reason for hiding this comment

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

maybe rule encourages the use

@hzoo
Copy link
Member

hzoo commented Sep 2, 2016

👍

@kaicataldo
Copy link
Member

LGTM. Thanks for contributing to ESLint!

@btmills
Copy link
Member

btmills commented Sep 4, 2016

LGTM, thanks @azhang496!

@btmills btmills merged commit 3960617 into eslint:master Sep 4, 2016
@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
archived due to age This issue has been archived; please open a new issue for any further discussion
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants