all files / eslint-plugin-angular/rules/ empty-controller.js

100% Statements 13/13
100% Branches 8/8
100% Functions 3/3
100% Lines 13/13
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                                12×     17×                      
/**
 * disallow empty controllers
 *
 * If you have one empty controller, maybe you have linked it in your Router configuration or in one of your views.
 * You can remove this declaration because this controller is useless
 *
 * @version 0.1.0
 * @category bestPractice
 */
'use strict';
 
var utils = require('./utils/utils');
 
module.exports = function(context) {
    function report(node, name) {
        context.report(node, 'The {{ctrl}} controller is useless because empty. You can remove it from your Router configuration or in one of your view', {
            ctrl: name
        });
    }
 
    return {
 
        CallExpression: function(node) {
            if (utils.isAngularControllerDeclaration(node)) {
                var name = node.arguments[0].value;
 
                var fn = node.arguments[1];
                if (utils.isArrayType(node.arguments[1])) {
                    fn = node.arguments[1].elements[node.arguments[1].elements.length - 1];
                }
                if (utils.isFunctionType(fn) && utils.isEmptyFunction(fn)) {
                    report(node, name);
                }
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];