UNPKG

942 BJavaScriptView Raw
1/**
2 * use `$q(function(resolve, reject){})` instead of `$q.deferred`
3 *
4 * When you want to create a new promise, you should not use the $q.deferred anymore.
5 * Prefer the new syntax : $q(function(resolve, reject){})
6 * @version 0.1.0
7 * @category bestPractice
8 * @sinceAngularVersion 1.x
9 */
10'use strict';
11
12var utils = require('./utils/utils');
13
14module.exports = {
15 meta: {
16 schema: []
17 },
18 create: function(context) {
19 return {
20
21 MemberExpression: function(node) {
22 if (node.object.type === 'Identifier' && utils.isAngularServiceImport(node.object.name, '$q')) {
23 if (node.property.type === 'Identifier' && node.property.name === 'defer') {
24 context.report(node, 'You should not create a new promise with this syntax. Use the $q(function(resolve, reject) {}) syntax.', {});
25 }
26 }
27 }
28 };
29 }
30};