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

100% Statements 12/12
82.35% Branches 14/17
100% Functions 3/3
100% Lines 12/12
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                      16× 16×         25×     16× 16×                  
/**
 * use `angular.isNumber` instead of `typeof` comparisons
 *
 * You should use the angular.isNumber method instead of the default JavaScript implementation (typeof 3 === "[object Number]").
 *
 * @version 0.1.0
 * @category angularWrapper
 */
'use strict';
 
var utils = require('./utils/utils');
 
module.exports = function(context) {
    function recordError(node, origin) {
        Eif (node.type === 'Literal' && (node.value === 'number' || node.value === '[object Number]')) {
            context.report(origin, 'You should use the angular.isNumber method', {});
        }
    }
 
 
    return {
 
        BinaryExpression: function(node) {
            Eif (node.operator === '===' || node.operator === '!==') {
                if (utils.isTypeOfStatement(node.left) || utils.isToStringStatement(node.left)) {
                    recordError(node.right, node);
                } else Eif (utils.isTypeOfStatement(node.right) || utils.isToStringStatement(node.right)) {
                    recordError(node.left, node);
                }
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];