forked from EmmanuelDemey/eslint-plugin-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
module-getter.js
50 lines (45 loc) · 2.11 KB
/
module-getter.js
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
43
44
45
46
47
48
49
50
/**
* enforce to reference modules with the getter syntax
*
* When using a module, avoid using a variable and instead use chaining with the getter syntax
*
* @linkDescription disallow to reference modules with variables and require to use the getter syntax instead `angular.module('myModule')`
* @styleguideReference {johnpapa} `y022` Module - Getters
* @version 0.1.0
* @category possibleError
* @sinceAngularVersion 1.x
*/
'use strict';
var utils = require('./utils/utils');
module.exports = {
meta: {
docs: {
url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/module-getter.md'
},
schema: []
},
create: function(context) {
return {
ExpressionStatement: function(node) {
if ((utils.isAngularControllerDeclaration(node.expression) ||
utils.isAngularFilterDeclaration(node.expression) ||
utils.isAngularServiceDeclaration(node.expression) ||
utils.isAngularFactoryDeclaration(node.expression) ||
utils.isAngularConstantDeclaration(node.expression) ||
utils.isAngularValueDeclaration(node.expression) ||
utils.isAngularDirectiveDeclaration(node.expression) ||
utils.isAngularRunSection(node.expression) ||
utils.isAngularConfigSection(node.expression)) &&
!utils.isAngularModuleDeclaration(node.expression)) {
var calleeObject = node.expression.callee.object;
while (calleeObject !== undefined && calleeObject.type === 'CallExpression' && !utils.isAngularModuleGetter(calleeObject)) {
calleeObject = calleeObject.callee.object;
}
if (!(calleeObject !== undefined && calleeObject.type === 'CallExpression' && utils.isAngularModuleGetter(calleeObject))) {
context.report(node, 'Avoid using a variable and instead use chaining with the getter syntax.');
}
}
}
};
}
};