all files / eslint-plugin-angular/rules/ module-setter.js

100% Statements 12/12
80% Branches 8/10
100% Functions 3/3
100% Lines 12/12
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                          11×                                
/**
 * disallow to assign modules to variables
 *
 * Declare modules without a variable using the setter syntax.
 *
 * @linkDescription disallow to assign modules to variables (linked to [module-getter](docs/module-getter.md)
 * @styleguideReference {johnpapa} `y021` Module - Definitions (aka Setters)
 * @version 0.1.0
 * @category possibleError
 */
'use strict';
 
var utils = require('./utils/utils');
 
module.exports = function(context) {
    return {
 
        VariableDeclaration: function(node) {
            var variableDeclarator = node.declarations[0];
            var rightExpression;
 
            Eif (variableDeclarator.init) {
                rightExpression = variableDeclarator.init;
 
                Eif (rightExpression.arguments && utils.isAngularModuleDeclaration(rightExpression)) {
                    context.report(rightExpression, 'Declare modules without a variable using the setter syntax.');
                }
            }
        },
        AssignmentExpression: function(node) {
            if (node.right.arguments && utils.isAngularModuleDeclaration(node.right)) {
                context.report(node.right, 'Declare modules without a variable using the setter syntax.');
            }
        }
    };
};
 
module.exports.schema = [
    // JSON Schema for rule options goes here
];