diff options
Diffstat (limited to 'tools/node_modules/eslint/lib/rules/no-eq-null.js')
-rw-r--r-- | tools/node_modules/eslint/lib/rules/no-eq-null.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/lib/rules/no-eq-null.js b/tools/node_modules/eslint/lib/rules/no-eq-null.js new file mode 100644 index 0000000000..7e915a8c72 --- /dev/null +++ b/tools/node_modules/eslint/lib/rules/no-eq-null.js @@ -0,0 +1,39 @@ +/** + * @fileoverview Rule to flag comparisons to null without a type-checking + * operator. + * @author Ian Christian Myers + */ + +"use strict"; + +//------------------------------------------------------------------------------ +// Rule Definition +//------------------------------------------------------------------------------ + +module.exports = { + meta: { + docs: { + description: "disallow `null` comparisons without type-checking operators", + category: "Best Practices", + recommended: false + }, + + schema: [] + }, + + 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, message: "Use ‘===’ to compare with ‘null’." }); + } + } + }; + + } +}; |