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
feat: use-isnan report NaN in indexOf
and lastIndexOf
with fromIndex
#18225
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
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.
Code and docs LGTM.
tests/lib/rules/use-isnan.js
Outdated
* code: "foo.lastIndexOf(NaN, b)", | ||
* options: [{ enforceForIndexOf: true }] | ||
* }, | ||
*/ |
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.
Can you uncomment these tests and add 3rd argument that would make them valid?
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.
Done!
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.
@mdjermanovic, in this rule following code
myArray.indexOf(NaN)
fixes to
myArray.findIndex(Number.isNaN)
but both cases return -1
so is this fix correct or there is something i am not aware of?
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.
The fix is correct. For example:
const myArray = [0, 1, 2, NaN, 4, 5];
console.log(myArray.indexOf(NaN)); // -1
console.log(myArray.findIndex(Number.isNaN)); // 3
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.
Got it, thanks!
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!
indexOf
and lastIndexOf
with fromIndexindexOf
and lastIndexOf
with fromIndex
indexOf
and lastIndexOf
with fromIndexindexOf
and lastIndexOf
with fromIndex
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[x] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
made the rule
use-isnan
to report NaN inindexOf
andlastIndexOf
with fromIndexnow rule will report following code-
Is there anything you'd like reviewers to focus on?
Fixes: #18161