question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

use-isnan options for implicit Strict Equality Comparison

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
mdjermanoviccommented, Oct 2, 2019

I’m working on this (indexOf).

1reaction
mdjermanoviccommented, Sep 4, 2019

it’d be better to make a custom rule forbidding indexOf in favor of includes, for that one.

This can be easily done with no-restricted-properties. Or probably with no-restricted-syntax to disable just === -1, >= 0 etc. for which includes is equvalent.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Equality comparisons and sameness - JavaScript | MDN
Strict equality compares two values for equality. Neither value is implicitly converted to some other value before being compared.
Read more >
TSLint core rules - Palantir Open Source
no-implicit-dependencies - Disallows importing modules that are not listed as dependency ... strict-comparisons - Only allow comparisons between primitives.
Read more >
Don't Make Javascript Equality Look Worse Than It Is - Reddit
The arguments for implicit conversion are very similar to the arguments for loosely-typed languages and I wouldn't want to decouple them. In JavaScript...
Read more >
Rules - ESLint - Pluggable JavaScript Linter
Disallow comparisons where both sides are exactly the same. Categories: ... use-isnan ... Disallow ternary operators when simpler alternatives exist.
Read more >
Note 2. ECMAScript. Equality operators. - Dmitry Soshnikov
The results of the examples above are caused by the implicit type conversion applied with using of non-strict equal == operator.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found