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
Bug: use-isnan
doesn't report NaN in indexOf
or lastIndexOf
when fromIndex is given
#18161
Comments
use-insane
doesn't report NaN in indexOf
or lastIndexOf
when fromIndex is givenuse-isnan
doesn't report NaN in indexOf
or lastIndexOf
when fromIndex is given
The rule does report Note that the Playground is using ESLint v8.57.0. |
got it! but following tests are valid in {
code: "foo.lastIndexOf(NaN, 2)",
options: [{ enforceForIndexOf: true }]
},
{
code: "foo.indexOf(NaN, 4)",
options: [{ enforceForIndexOf: true }]
}, |
As for not reporting cases with multiple arguments, it seems to be intentional: Line 185 in e37153f
eslint/tests/lib/rules/use-isnan.js Lines 265 to 268 in e37153f
I believe this is because we don't know for sure if I think it's fine to update this rule to report cases with two arguments, and treat this as a semver-minor bug fix. Curious what others think. |
So, the question is whether these cases should be reported: /*eslint use-isnan: ["error", {"enforceForIndexOf": true}]*/
var foo = myArray.indexOf(NaN, 2) // output will be -1
var foo = myArray.lastIndexOf(NaN, 2) // output will be -1 |
Makes sense to me 👍🏻 The logic to check |
@eslint/eslint-team are we up for implementing this? |
Yes, PR is welcome. |
Environment
Node version: latest
npm version: latest
Local ESLint version: v8.57.0
Global ESLint version:
Operating System: windows
What parser are you using?
Default (Espree)
What did you do?
i tried it in playground
What did you expect to happen?
I expected that
use-isnan
rule will report these cases as all have the output-1
.What actually happened?
the rule doesn't report these cases.
Link to Minimal Reproducible Example
https://eslint.org/play/#eyJ0ZXh0IjoiLyplc2xpbnQgdXNlLWlzbmFuOiBbXCJlcnJvclwiLCB7XCJlbmZvcmNlRm9ySW5kZXhPZlwiOiB0cnVlfV0qL1xuXG52YXIgZm9vID0gbXlBcnJheS5pbmRleE9mKChkb1N0dWZmKCksIE5hTikpOyAvLyBvdXRwdXQgd2lsbCBiZSAtMVxudmFyIGZvbyA9IG15QXJyYXkuaW5kZXhPZihOYU4sIDIpIC8vIG91dHB1dCB3aWxsIGJlIC0xXG52YXIgZm9vID0gbXlBcnJheS5sYXN0SW5kZXhPZigoZG9TdHVmZigpLCBOYU4pKTsgLy8gb3V0cHV0IHdpbGwgYmUgLTFcbnZhciBmb28gPSBteUFycmF5Lmxhc3RJbmRleE9mKE5hTiwgMikgLy8gb3V0cHV0IHdpbGwgYmUgLTEiLCJvcHRpb25zIjp7ImVudiI6e30sInJ1bGVzIjp7fSwicGFyc2VyT3B0aW9ucyI6eyJlY21hRmVhdHVyZXMiOnt9LCJlY21hVmVyc2lvbiI6ImxhdGVzdCIsInNvdXJjZVR5cGUiOiJtb2R1bGUifX19
Participation
Additional comments
No response
The text was updated successfully, but these errors were encountered: