1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | module.exports = function(context) {
|
12 |
|
13 | var VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function"],
|
14 | OPERATORS = ["==", "===", "!=", "!=="];
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | return {
|
21 |
|
22 | "UnaryExpression": function(node) {
|
23 | var parent, sibling;
|
24 |
|
25 | if (node.operator === "typeof") {
|
26 | parent = context.getAncestors().pop();
|
27 |
|
28 | if (parent.type === "BinaryExpression" && OPERATORS.indexOf(parent.operator) !== -1) {
|
29 | sibling = parent.left === node ? parent.right : parent.left;
|
30 |
|
31 | if (sibling.type === "Literal" && VALID_TYPES.indexOf(sibling.value) === -1) {
|
32 | context.report(sibling, "Invalid typeof comparison value");
|
33 | }
|
34 | }
|
35 | }
|
36 | }
|
37 |
|
38 | };
|
39 |
|
40 | };
|
41 |
|
42 | module.exports.schema = [];
|