1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | "use strict";
|
13 |
|
14 | function isTypeOf(node) {
|
15 | return [node.left, node.right].some(function(node) {
|
16 | return node.type === "UnaryExpression" && node.operator === "typeof";
|
17 | });
|
18 | }
|
19 |
|
20 | function bothAreSameTypeLiterals(node) {
|
21 | return node.left.type === "Literal" && node.right.type === "Literal" && typeof node.left.value === typeof node.right.value;
|
22 | }
|
23 |
|
24 | return {
|
25 | "BinaryExpression": function(node) {
|
26 | var operator = node.operator;
|
27 |
|
28 | if (context.options[0] === "smart" && (isTypeOf(node) || bothAreSameTypeLiterals(node))) {
|
29 | return;
|
30 | }
|
31 |
|
32 | if (operator === "==") {
|
33 | context.report(node, "Expected '===' and instead saw '=='.");
|
34 | } else if (operator === "!=") {
|
35 | context.report(node, "Expected '!==' and instead saw '!='.");
|
36 | }
|
37 | }
|
38 | };
|
39 | }; |
\ | No newline at end of file |