all files / eslint-plugin-angular/rules/ typecheck-regexp.js

100% Statements 14/14
78.57% Branches 11/14
100% Functions 4/4
100% Lines 14/14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42                              12×     17×                      
/**
 * use `angular.isRegexp` instead of other comparisons
 *
 * You should use the angular.isRegexp method instead of the default JavaScript implementation (toString.call(/^A/) === "[object RegExp]").
 *
 * @linkDescription use `angular.isRegexp` instead of other comparisons (no native angular method)
 * @version 0.1.0
 * @deprecated `angular.isRegexp` is no built-in angular method.
 */
'use strict';
 
var utils = require('./utils/utils');
 
module.exports = function(context) {
    function recordError(node, origin) {
        Eif (node.type === 'Literal' && node.value === '[object RegExp]') {
            context.report(origin, 'You should use the angular.isRegexp method', {});
        }
    }
 
    function checkNode(node) {
        return node.type === 'Identifier' || utils.isToStringStatement(node);
    }
 
    return {
 
        BinaryExpression: function(node) {
            Eif (node.operator === '===' || node.operator === '!==') {
                if (checkNode(node.left)) {
                    recordError(node.right, node);
                } else Eif (checkNode(node.right)) {
                    recordError(node.left, node);
                }
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];