Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

New rule: Equals signs can't be used to check if variable is NaN (use isNaN() instead) #1054

Closed
atsu85 opened this issue Mar 24, 2016 · 6 comments

Comments

@atsu85
Copy link
Contributor

atsu85 commented Mar 24, 2016

Equals signs can't be used to check if variable is NaN, isNaN() function should be used instead.

Currently following incorrect usage doesn't raise an error

Example of incorrect usage:

const maybeNumber = parseInt("a");
if( maybeNumber === NaN || maybeNumber === NaN ) {
  // this line is never reached <- UNEXPECTED
}

Example of correct usage

const maybeNumber = parseInt("a");
if( isNaN(maybeNumber) ) {
  // this line is reached, as expected
}
@Avol-V
Copy link

Avol-V commented Mar 24, 2016

@myitcv
Copy link
Contributor

myitcv commented Mar 24, 2016

@HamletDRC - has there been any thought to contributing these Microsoft rules back to the main tslint repo?

@atsu85
Copy link
Contributor Author

atsu85 commented Mar 24, 2016

@HamletDRC, that would be nice :)

@HamletDRC
Copy link
Contributor

I am happy to move any of the rules to tslint. It is up to someone from the tslint team to go through the tslint-microsoft-contrib rulesset and tell me which ones they want. I am not going to create 60 new PR requests for tslint just to have 55 of them closed as "rule is too specific for teslint". So the ball is in Palentir's court. I am happy to do the work of porting the rules, but tslint must state which rules they want and which rules they do not want.

@adidahiya
Copy link
Contributor

@HamletDRC fair enough :) thanks for the offer. We'll take a look at the tslint-microsoft-contrib rule set. In the meantime, the new extends feature should make sharing configs easier (once the bugs are ironed out this week).

@adidahiya
Copy link
Contributor

Feel free to send a PR for this one in particular (and any others which have the "Status: Accepting PRs" label)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants