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

Created on 24 Mar 2016  路  6Comments  路  Source: palantir/tslint

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
}
P2 Fixed Accepting PRs Rule Suggestion

Most helpful comment

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.

All 6 comments

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

@HamletDRC, that would be nice :)

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.

@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).

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cateyes99 picture cateyes99  路  3Comments

adidahiya picture adidahiya  路  3Comments

zewa666 picture zewa666  路  3Comments

denkomanceski picture denkomanceski  路  3Comments

ypresto picture ypresto  路  3Comments