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
Add prefer-number-is-integer
rule
#1509
Add prefer-number-is-integer
rule
#1509
Conversation
rules/prefer-number-is-integer.js
Outdated
'[left.callee.type="MemberExpression"]', | ||
'[left.callee.object.name="Math"]', | ||
'[left.callee.property.name="round"]', | ||
'[left.arguments.0.type="Identifier"]', |
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 don't think we should limit this to Identifier
, it should work for anything, just make sure the argument and the right side are the same reference, you can use isSameReference
.
And don't auto-fix if the expression has side effect.
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.
@fisker I've updated the PR to use isSameReference
.
Can you give me an example of an expression with a side effect that fits here? So I can TDD against it :)
Thanks for the feedback on PR, I'll get onto updating this PR over the next week :) |
2367c8f
to
2e39762
Compare
Sorry for the long delay, overall looks good. But I'm not sure if we want check Can you fix tests? |
Happy to make the changes! Will get it done over the next week or so |
rules/prefer-number-is-integer.js
Outdated
equalsSelector, | ||
].join(''); | ||
|
||
// ParseInt(value,10) === value |
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.
// ParseInt(value,10) === value | |
// `Number.parseInt(value, 10) === value` |
Let's forget about parseInt
, only check Number.parseInt
rules/prefer-number-is-integer.js
Outdated
equalsSelector, | ||
].join(''); | ||
|
||
// _.isInteger(value) |
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.
Use methodCallSelector
, search how to use it in other rules.
rules/prefer-number-is-integer.js
Outdated
'[callee.property.name="isInteger"]', | ||
].join(''); | ||
|
||
// Math.round(value) === value |
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.
Use methodCallSelector
,
Bump :) |
@sindresorhus appreciated! I had forgot about this PR. Working on it over the next couple of days |
2e39762
to
6b4f721
Compare
|
||
default: { | ||
return ''; | ||
} |
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.
@sindresorhus what should we do here?
I've added the default case as to appease linting, but the calling code protects us from this branch being taken.
How should I approach appeasing Codecov?
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.
You could use an ignore comment:
/* c8 ignore next 3 */
@sindresorhus et al, this is ready or review :) |
return node => { | ||
const variable = variableGetter(node); | ||
|
||
if (!variable) { |
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.
We should not limit this to Identifier
and MemberExpression
, should allow anything
_.isInteger(a ? b : c)
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.
@tristanHessell Bump |
Closing for lack of response. |
Fixes #1460.
One thing to note is that I couldn't run
npm run integration
to completion as my computer only has 4GB RAM.