forked from EmmanuelDemey/eslint-plugin-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathno-http-callback.js
46 lines (43 loc) · 1.33 KB
/
no-http-callback.js
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
39
40
41
42
43
44
45
46
/**
* disallow the `$http` methods `success()` and `error()`
*
* Disallow the $http success and error function.
* Instead the standard promise API should be used.
*
* @version 0.12.0
* @category deprecatedAngularFeature
*/
'use strict';
module.exports = function(context) {
var httpMethods = [
'delete',
'get',
'head',
'jsonp',
'patch',
'post',
'put'
];
function isHttpCall(node) {
if (node.callee.type === 'MemberExpression') {
return httpMethods.indexOf(node.callee.property.name) !== -1 ||
(node.callee.object.type === 'CallExpression' && isHttpCall(node.callee.object));
}
if (node.callee.type === 'Identifier') {
return node.callee.name === '$http';
}
}
return {
CallExpression: function(node) {
if (node.callee.type !== 'MemberExpression') {
return;
}
if (node.callee.property.name === 'success' && isHttpCall(node)) {
return context.report(node, '$http success is deprecated. Use then instead');
}
if (node.callee.property.name === 'error' && isHttpCall(node)) {
context.report(node, '$http error is deprecated. Use then or catch instead');
}
}
};
};