UNPKG

1.45 kBJavaScriptView Raw
1/**
2 * disallow empty controllers
3 *
4 * If you have one empty controller, maybe you have linked it in your Router configuration or in one of your views.
5 * You can remove this declaration because this controller is useless
6 *
7 * @version 0.1.0
8 * @category bestPractice
9 * @sinceAngularVersion 1.x
10 */
11'use strict';
12
13var utils = require('./utils/utils');
14
15module.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};