UNPKG

620 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag comparisons to the value NaN
3 * @author James Allardice
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 return {
15 "BinaryExpression": function(node) {
16
17 if (!/^[|&^]$/.test(node.operator) && node.left.name === "NaN" || node.right.name === "NaN") {
18 context.report(node, "Use the isNaN function to compare with NaN.");
19 }
20 }
21 };
22
23};