use-isnan
NOTE: this rule is part of the
recommended rule set.Enable full set in
deno.json:{
"lint": {
"rules": {
"tags": ["recommended"]
}
}
}Enable full set using the Deno CLI:
deno lint --rules-tags=recommended
This rule can be explictly included to or excluded from the rules present in the current tag by adding it to the
include or exclude array in deno.json:{
"lint": {
"rules": {
"include": ["use-isnan"],
"exclude": ["use-isnan"]
}
}
}Disallows comparisons to NaN.
Because NaN is unique in JavaScript by not being equal to anything, including
itself, the results of comparisons to NaN are confusing:
NaN === NaNorNaN == NaNevaluate tofalseNaN !== NaNorNaN != NaNevaluate totrue
Therefore, this rule makes you use the isNaN() or Number.isNaN() to judge
the value is NaN or not.
Invalid:
if (foo == NaN) {
// ...
}
if (foo != NaN) {
// ...
}
switch (NaN) {
case foo:
// ...
}
switch (foo) {
case NaN:
// ...
}
Valid:
if (isNaN(foo)) {
// ...
}
if (!isNaN(foo)) {
// ...
}