Urara-Blog/node_modules/.pnpm-store/v3/files/8d/7cf1a64bff6507ff241e28f528dc724d45a14767c334442be54d729ce0a888fbb41be6f9d0ba1ca1214e8789506f9bc1c5847ee85a5d995e99c12894c10f62
2022-08-14 01:14:53 +08:00

46 lines
1.2 KiB
Text

/**
* @fileoverview Rule to flag comparisons to null without a type-checking
* operator.
* @author Ian Christian Myers
*/
"use strict";
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('../shared/types').Rule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "Disallow `null` comparisons without type-checking operators",
recommended: false,
url: "https://eslint.org/docs/rules/no-eq-null"
},
schema: [],
messages: {
unexpected: "Use '===' to compare with null."
}
},
create(context) {
return {
BinaryExpression(node) {
const badOperator = node.operator === "==" || node.operator === "!=";
if (node.right.type === "Literal" && node.right.raw === "null" && badOperator ||
node.left.type === "Literal" && node.left.raw === "null" && badOperator) {
context.report({ node, messageId: "unexpected" });
}
}
};
}
};