all files / eslint-plugin-angular/rules/ deferred.js

100% Statements 7/7
87.5% Branches 7/8
100% Functions 2/2
100% Lines 7/7
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                      11×                  
/**
 * use `$q(function(resolve, reject){})` instead of `$q.deferred`
 *
 * When you want to create a new promise, you should not use the $q.deferred anymore.
 * Prefer the new syntax : $q(function(resolve, reject){})
 * @version 0.1.0
 * @category bestPractice
 */
'use strict';
 
var utils = require('./utils/utils');
 
module.exports = function(context) {
    return {
 
        MemberExpression: function(node) {
            if (node.object.type === 'Identifier' && utils.isAngularServiceImport(node.object.name, '$q')) {
                Eif (node.property.type === 'Identifier' && node.property.name === 'defer') {
                    context.report(node, 'You should not create a new promise with this syntax. Use the $q(function(resolve, reject) {}) syntax.', {});
                }
            }
        }
    };
};
 
module.exports.schema = [];