15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
 * @fileoverview Rule to flag comparisons to the value NaN
 * @author James Allardice
 */
 
"use strict";
 
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
 
module.exports = {
    meta: {
        type: "problem",
 
        docs: {
            description: "require calls to `isNaN()` when checking for `NaN`",
            category: "Possible Errors",
            recommended: true,
            url: "https://eslint.org/docs/rules/use-isnan"
        },
 
        schema: [],
        messages: {
            useIsNaN: "Use the isNaN function to compare with NaN."
        }
    },
 
    create(context) {
 
        return {
            BinaryExpression(node) {
                if (/^(?:[<>]|[!=]=)=?$/u.test(node.operator) && (node.left.name === "NaN" || node.right.name === "NaN")) {
                    context.report({ node, messageId: "useIsNaN" });
                }
            }
        };
 
    }
};