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: add suggestions to use-isnan
in indexOf
& lastIndexOf
calls
#18063
feat: add suggestions to use-isnan
in indexOf
& lastIndexOf
calls
#18063
Conversation
✅ Deploy Preview for docs-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Marking as a draft so we don't accidentally merge. |
I don't think it's worth the extra effort to give more than one suggestion for this. |
@nzakas Ready for review 😄 |
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.
Overall LGTM, just a question around naming.
lib/rules/use-isnan.js
Outdated
* To retain side effects, it's essential to address `NaN` beforehand, which | ||
* is not possible with fixes like `arr.findIndex(Number.isNaN)`. | ||
*/ | ||
const isFixable = node.arguments[0].type !== "SequenceExpression"; |
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 isFixable
actually means isSuggestable
? (To disambiguate between fixes and suggestions, it's probably better to keep the naming in line.)
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.
ugh... I always mix them up...
fixed (pun intended 😄)
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! Leaving open for @nzakas to verify.
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. Thank you!
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[X] 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)
This PR adds suggestions to
use-isnan
when usingindexOf
andlastIndexOf
.The current fix changes them to
findIndex
&findLastIndex
respectively.I wanted to suggest also
includes
andsome
as second and third suggestions, but I got into a rabbit hole of checking whether the parent node is aBinaryExpression
and whether the developer usedindexOf() !== -1
,indexOf() > 0
, etc.We can probably do that, just need to find all the cases. Do you think it's worth the effort?
(Probably?) Closes #17978
NOTE
Let's wait until #18059 is merged before merging this one, because it'll require me to extend the new tests that were added there.