1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.exports = {
|
13 | meta: {
|
14 | docs: {
|
15 | description: "require calls to `isNaN()` when checking for `NaN`",
|
16 | category: "Possible Errors",
|
17 | recommended: true,
|
18 | url: "https://eslint.org/docs/rules/use-isnan"
|
19 | },
|
20 |
|
21 | schema: []
|
22 | },
|
23 |
|
24 | create(context) {
|
25 |
|
26 | return {
|
27 | BinaryExpression(node) {
|
28 | if (/^(?:[<>]|[!=]=)=?$/.test(node.operator) && (node.left.name === "NaN" || node.right.name === "NaN")) {
|
29 | context.report({ node, message: "Use the isNaN function to compare with NaN." });
|
30 | }
|
31 | }
|
32 | };
|
33 |
|
34 | }
|
35 | };
|