2 * @fileoverview Ensures that the results of typeof are compared against a valid string
3 * @author Ian Christian Myers
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 module.exports = function(context) {
13 var VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function"],
14 OPERATORS = ["==", "===", "!=", "!=="];
16 //--------------------------------------------------------------------------
18 //--------------------------------------------------------------------------
22 "UnaryExpression": function (node) {
25 if (node.operator === "typeof") {
26 parent = context.getAncestors().pop();
28 if (parent.type === "BinaryExpression" && OPERATORS.indexOf(parent.operator) !== -1) {
29 sibling = parent.left === node ? parent.right : parent.left;
31 if (sibling.type === "Literal" && VALID_TYPES.indexOf(sibling.value) === -1) {
32 context.report(sibling, "Invalid typeof comparison value");