UNPKG

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