]> git.proxmox.com Git - pve-eslint.git/blob - eslint/lib/rules/no-eq-null.js
import 8.23.1 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 /** @type {import('../shared/types').Rule} */
14 module.exports = {
15 meta: {
16 type: "suggestion",
17
18 docs: {
19 description: "Disallow `null` comparisons without type-checking operators",
20 recommended: false,
21 url: "https://eslint.org/docs/rules/no-eq-null"
22 },
23
24 schema: [],
25
26 messages: {
27 unexpected: "Use '===' to compare with null."
28 }
29 },
30
31 create(context) {
32
33 return {
34
35 BinaryExpression(node) {
36 const badOperator = node.operator === "==" || node.operator === "!=";
37
38 if (node.right.type === "Literal" && node.right.raw === "null" && badOperator ||
39 node.left.type === "Literal" && node.left.raw === "null" && badOperator) {
40 context.report({ node, messageId: "unexpected" });
41 }
42 }
43 };
44
45 }
46 };