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

100% Statements 6/6
100% Branches 4/4
100% Functions 2/2
100% Lines 6/6
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                      16× 16×     17×            
/**
 * use `$window` instead of `window`
 *
 * Instead of the default window object, you should prefer the AngularJS wrapper service $window.
 *
 * @styleguideReference {johnpapa} `y180` Angular $ Wrapper Services - $document and $window
 * @version 0.1.0
 * @category angularWrapper
 */
'use strict';
 
module.exports = function(context) {
    var restrict = ['document', 'setInterval', 'setTimeout'];
    return {
 
        MemberExpression: function(node) {
            if (node.object.name === 'window' && restrict.indexOf(node.property.name) < 0) {
                context.report(node, 'You should use the $window service instead of the default window object', {});
            }
        }
    };
};
 
module.exports.schema = [];