Skip to content

use-isnan options for implicit Strict Equality Comparison #12207

@mdjermanovic

Description

@mdjermanovic

What rule do you want to change?

use-isnan

This rule targets foo === NaN (Strict Equality Comparison)

(also targets !==, == and !=)

Currently, the rule checks only BinaryExpression nodes, i.e. only explicit comparisons.

This is a proposal to also check the following:

Does this change cause the rule to produce more or fewer warnings?

More if an option is set to true. Defaults are false.

How will the change be implemented? (New option, new default behavior, etc.)?

2 options, enforceForSwitchCase and enforceForIndexOf.

Please provide some example code that this change will affect:

/*eslint use-isnan: "error"*/

switch (foo) {
    case NaN:
        bar();
        break;
}

foo.indexOf(NaN);
foo.lastIndexOf(NaN);

What does the rule currently do for this code?

Nothing.

What will the rule do after it's changed?

/*eslint use-isnan: ["error", {"enforceForSwitchCase": true}]*/

switch (foo) {
    case NaN: // error
        bar();
        break;
}
/*eslint use-isnan: ["error", {"enforceForIndexOf": true}]*/

foo.indexOf(NaN); // error
foo.lastIndexOf(NaN); // error

Are you willing to submit a pull request to implement this change?

Yes. (there is PR #12106 for enforceForSwitchCase)

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionenhancementThis change enhances an existing feature of ESLintruleRelates to ESLint's core rules

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions