UNPKG

1.39 kBJavaScriptView Raw
1/**
2 * disallow to assign modules to variables
3 *
4 * Declare modules without a variable using the setter syntax.
5 *
6 * @linkDescription disallow to assign modules to variables (linked to [module-getter](docs/module-getter.md)
7 * @styleguideReference {johnpapa} `y021` Module - Definitions (aka Setters)
8 * @version 0.1.0
9 * @category possibleError
10 * @sinceAngularVersion 1.x
11 */
12'use strict';
13
14var utils = require('./utils/utils');
15
16module.exports = {
17 meta: {
18 schema: []
19 },
20 create: function(context) {
21 return {
22
23 VariableDeclaration: function(node) {
24 var variableDeclarator = node.declarations[0];
25 var rightExpression;
26
27 if (variableDeclarator.init) {
28 rightExpression = variableDeclarator.init;
29
30 if (rightExpression.arguments && utils.isAngularModuleDeclaration(rightExpression)) {
31 context.report(rightExpression, 'Declare modules without a variable using the setter syntax.');
32 }
33 }
34 },
35 AssignmentExpression: function(node) {
36 if (node.right.arguments && utils.isAngularModuleDeclaration(node.right)) {
37 context.report(node.right, 'Declare modules without a variable using the setter syntax.');
38 }
39 }
40 };
41 }
42};