1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | var utils = require('./utils/utils');
|
14 |
|
15 | module.exports = {
|
16 | meta: {
|
17 | docs: {
|
18 | url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/empty-controller.md'
|
19 | },
|
20 | schema: []
|
21 | },
|
22 | create: function(context) {
|
23 | function report(node, name) {
|
24 | context.report(node, 'The {{ctrl}} controller is useless because empty. You can remove it from your Router configuration or in one of your view', {
|
25 | ctrl: name
|
26 | });
|
27 | }
|
28 |
|
29 | return {
|
30 |
|
31 | CallExpression: function(node) {
|
32 | if (utils.isAngularControllerDeclaration(node)) {
|
33 | var name = node.arguments[0].value;
|
34 |
|
35 | var fn = node.arguments[1];
|
36 | if (utils.isArrayType(node.arguments[1])) {
|
37 | fn = node.arguments[1].elements[node.arguments[1].elements.length - 1];
|
38 | }
|
39 | if (utils.isFunctionType(fn) && utils.isEmptyFunction(fn)) {
|
40 | report(node, name);
|
41 | }
|
42 | }
|
43 | }
|
44 | };
|
45 | }
|
46 | };
|