-
Notifications
You must be signed in to change notification settings - Fork 131
/
avoid-scope-typos.js
38 lines (34 loc) · 1.13 KB
/
avoid-scope-typos.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
/**
* Avoid mistakes when naming methods defined on the scope object
*
* For example, you want to use $scope.$watch instead of $scope.watch
*
* @version 2.3.0
* @category possibleError
* @sinceAngularVersion 1.x
*/
'use strict';
const bad = ['new', 'watch', 'watchGroup', 'watchCollection',
'digest', 'destroy', 'eval', 'evalAsync', 'apply',
'applyAsync', 'on', 'emit', 'broadcast'];
const scope = ['scope', '$scope', '$rootScope'];
module.exports = {
meta: {
docs: {
url: 'https://github.com/Gillespie59/eslint-plugin-angular/blob/master/docs/rules/avoid-scope-typos.md'
},
schema: [ ]
},
create: function(context) {
function check(node, name) {
if (bad.indexOf(name) >= 0 && node && node.parent && node.parent.object && scope.indexOf(node.parent.object.name) >= 0) {
context.report(node, `The ${name} method should be replaced by $${name}, or you should rename it in order to avoid confusions`, {});
}
}
return {
Identifier: function(node) {
check(node, node.name);
}
};
}
};