]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-eq-null.js
import 8.3.0 source
[pve-eslint.git] / eslint / lib / rules / no-eq-null.js
1 /**
2 * @fileoverview Rule to flag comparisons to null without a type-checking
3 * operator.
4 * @author Ian Christian Myers
5 */
6
7 "use strict";
8
9 //------------------------------------------------------------------------------
10 // Rule Definition
11 //------------------------------------------------------------------------------
12
13 module.exports = {
14 meta: {
15 type: "suggestion",
16
17 docs: {
18 description: "disallow `null` comparisons without type-checking operators",
19 recommended: false,
20 url: "https://eslint.org/docs/rules/no-eq-null"
21 },
22
23 schema: [],
24
25 messages: {
26 unexpected: "Use '===' to compare with null."
27 }
28 },
29
30 create(context) {
31
32 return {
33
34 BinaryExpression(node) {
35 const badOperator = node.operator === "==" || node.operator === "!=";
36
37 if (node.right.type === "Literal" && node.right.raw === "null" && badOperator ||
38 node.left.type === "Literal" && node.left.raw === "null" && badOperator) {
39 context.report({ node, messageId: "unexpected" });
40 }
41 }
42 };
43
44 }
45 };