all files / eslint-plugin-angular/rules/ timeout-service.js

100% Statements 8/8
100% Branches 6/6
100% Functions 3/3
100% Lines 8/8
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                      15×   15×             18×                
/**
 * use `$timeout` instead of `setTimeout`
 *
 * Instead of the default setTimeout function, you should use the AngularJS wrapper service $timeout
 **
 * @styleguideReference {johnpapa} `y181` Angular $ Wrapper Services - $timeout and $interval
 * @version 0.1.0
 * @category angularWrapper
 */
'use strict';
 
module.exports = function(context) {
    var message = 'You should use the $timeout service instead of the default window.setTimeout method';
 
    return {
 
        MemberExpression: function(node) {
            if (node.object.name === 'window' && node.property.name === 'setTimeout') {
                context.report(node, message, {});
            }
        },
 
        CallExpression: function(node) {
            if (node.callee.name === 'setTimeout') {
                context.report(node, message, {});
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];