Skip to content

Commit

Permalink
use-isnan fixed to ignore assignments to NaN (palantir#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
HamletDRC authored and jkillian committed Apr 29, 2016
1 parent d4e227a commit d133c0c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/rules/useIsnanRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class Rule extends Lint.Rules.AbstractRule {
class UseIsnanRuleWalker extends Lint.RuleWalker {

protected visitBinaryExpression(node: ts.BinaryExpression): void {
if (this.isExpressionNaN(node.left) || this.isExpressionNaN(node.right)) {
if (this.isExpressionNaN(node.left) || this.isExpressionNaN(node.right)
&& node.operatorToken.kind !== ts.SyntaxKind.EqualsToken) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING + node.getText()));
}
super.visitBinaryExpression(node);
Expand Down
3 changes: 3 additions & 0 deletions test/rules/use-isnan/test.ts.lint
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ if (isNaN(NaN)) {
// no violation for correctly checking for isNaN
if (isNaN(something)) { }

// no violation for assignments
let x = 0;
x = NaN;

// do not use equality operators to compare for NaN
if (foo == NaN) { }
Expand Down

0 comments on commit d133c0c

Please sign in to comment.