aboutsummaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/no-eq-null.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/no-eq-null.js')
-rw-r--r--tools/eslint/lib/rules/no-eq-null.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-eq-null.js b/tools/eslint/lib/rules/no-eq-null.js
new file mode 100644
index 0000000000..deee40c36a
--- /dev/null
+++ b/tools/eslint/lib/rules/no-eq-null.js
@@ -0,0 +1,27 @@
+/**
+ * @fileoverview Rule to flag comparisons to null without a type-checking
+ * operator.
+ * @author Ian Christian Myers
+ */
+
+"use strict";
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = function(context) {
+
+ return {
+
+ "BinaryExpression": function(node) {
+ var 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, "Use ‘===’ to compare with ‘null’.");
+ }
+ }
+ };
+
+};