1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | module.exports = {
|
14 | meta: {
|
15 | schema: []
|
16 | },
|
17 | create: function(context) {
|
18 | var httpMethods = [
|
19 | 'delete',
|
20 | 'get',
|
21 | 'head',
|
22 | 'jsonp',
|
23 | 'patch',
|
24 | 'post',
|
25 | 'put'
|
26 | ];
|
27 |
|
28 | function isHttpCall(node) {
|
29 | if (node.callee.type === 'MemberExpression') {
|
30 | return httpMethods.indexOf(node.callee.property.name) !== -1 ||
|
31 | (node.callee.object.type === 'CallExpression' && isHttpCall(node.callee.object));
|
32 | }
|
33 | if (node.callee.type === 'Identifier') {
|
34 | return node.callee.name === '$http';
|
35 | }
|
36 | }
|
37 |
|
38 | return {
|
39 | CallExpression: function(node) {
|
40 | if (node.callee.type !== 'MemberExpression') {
|
41 | return;
|
42 | }
|
43 | if (node.callee.property.name === 'success' && isHttpCall(node)) {
|
44 | return context.report(node, '$http success is deprecated. Use then instead');
|
45 | }
|
46 | if (node.callee.property.name === 'error' && isHttpCall(node)) {
|
47 | context.report(node, '$http error is deprecated. Use then or catch instead');
|
48 | }
|
49 | }
|
50 | };
|
51 | }
|
52 | };
|