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: no-loss-of-precision (fixes #11279) #12747
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR! I left a few suggestions.
function isBaseTen(node) { | ||
const prefixes = ["0x", "0X", "0b", "0B", "0o", "0O"]; | ||
|
||
return prefixes.every(prefix => !node.raw.startsWith(prefix)) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will treat the literal 0
as octal, which is incorrect although it doesn't affect the result of the precision check.
lib/rules/no-loss-of-precision.js
Outdated
|
||
return prefixes.every(prefix => !node.raw.startsWith(prefix)) && | ||
(!node.raw.startsWith("0") || | ||
node.raw.startsWith("0e") || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be incorrect for something like 0E5
.
lib/rules/no-loss-of-precision.js
Outdated
(!node.raw.startsWith("0") || | ||
node.raw.startsWith("0e") || | ||
node.raw.startsWith("0.") || | ||
!isOctalDigitsOnly(node.raw)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be simplified to:
return prefixes.every(prefix => !node.raw.startsWith(prefix)) &&
!/^0[0-7]+$/.test(node.raw)
@kaicataldo has your concerns been addressed? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix (template)
[ X] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
#11279
What changes did you make? (Give an overview)
Is there anything you'd like reviewers to focus on?
Nope