2 * @fileoverview Rule to flag comparisons to null without a type-checking
4 * @author Ian Christian Myers
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
18 description: "disallow `null` comparisons without type-checking operators",
19 category: "Best Practices",
21 url: "https://eslint.org/docs/rules/no-eq-null"
27 unexpected: "Use '===' to compare with null."
35 BinaryExpression(node) {
36 const badOperator = node.operator === "==" || node.operator === "!=";
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" });