1 | /**
|
2 | * @fileoverview Rule to flag comparisons to null without a type-checking
|
3 | * operator.
|
4 | * @author Ian Christian Myers
|
5 | */
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Rule Definition
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | module.exports = function(context) {
|
12 | ;
|
13 |
|
14 | return {
|
15 |
|
16 | "BinaryExpression": function(node) {
|
17 | var badOperator = node.operator === "==" || node.operator === "!=";
|
18 |
|
19 | if (node.right.type === "Literal" && node.right.raw === "null" && badOperator ||
|
20 | node.left.type === "Literal" && node.left.raw === "null" && badOperator) {
|
21 | context.report(node, "Use ‘===’ to compare with ‘null’.");
|
22 | }
|
23 | }
|
24 | };
|
25 |
|
26 | };
|