Skip to content

Commit 834019e

Browse files
committed
Merge 0.1.2
2 parents 4bea47a + a79dbfc commit 834019e

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "eslint-plugin-angular",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "ESLint rules for AngularJS projects",
55
"main": "index.js",
66
"repository": {

rules/ng_on_watch.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module.exports = function(context) {
1414
* named '$on' or '$watch' on an object named '$scope', '$rootScope' or
1515
* 'scope'.
1616
*/
17-
function isScopeOnOrWatch(node) {
17+
function isScopeOnOrWatch(node, scopes) {
1818
if (node.type !== 'CallExpression') {
1919
return false;
2020
}
@@ -39,9 +39,7 @@ module.exports = function(context) {
3939
var objectName = parentObject.name;
4040
var functionName = accessedFunction.name;
4141

42-
return (objectName === '$rootScope' ||
43-
objectName === '$scope' ||
44-
objectName === 'scope') && (functionName === '$on' ||
42+
return scopes.indexOf(objectName) >= 0 && (functionName === '$on' ||
4543
functionName === '$watch');
4644
}
4745

@@ -64,10 +62,10 @@ module.exports = function(context) {
6462
return {
6563

6664
'CallExpression': function(node) {
67-
if (isScopeOnOrWatch(node) && !isFirstArgDestroy(node)) {
65+
if (isScopeOnOrWatch(node, ['$rootScope']) && !isFirstArgDestroy(node)) {
6866
if (node.parent.type !== 'VariableDeclarator' &&
6967
node.parent.type !== 'AssignmentExpression' &&
70-
!(isScopeOnOrWatch(node.parent) &&
68+
!(isScopeOnOrWatch(node.parent, ['$rootScope', '$scope', 'scope']) &&
7169
isFirstArgDestroy(node.parent))) {
7270
report(node, node.callee.property.name);
7371
}

test/ng_on_watch.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ eslintTester.addRuleTest('rules/ng_on_watch', {
2323
'$scope.$on("$destroy", $scope.$on())',
2424
'$rootScope.$on("$destroy", $scope.$on())',
2525
'$scope.$on("$destroy", $rootScope.$on())',
26-
'$rootScope.$on("$destroy", $rootScope.$on())'
26+
'$rootScope.$on("$destroy", $rootScope.$on())',
27+
'scope.$on()',
28+
'scope.$watch()',
29+
'$scope.$on()',
30+
'$scope.$watch()'
31+
2732
],
2833
invalid: [
29-
{ code: 'scope.$on()', errors: [{ message: 'The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
30-
{ code: 'scope.$watch()', errors: [{ message: 'The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
31-
{ code: '$scope.$on()', errors: [{ message: 'The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
32-
{ code: '$scope.$watch()', errors: [{ message: 'The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
3334
{ code: '$rootScope.$on()', errors: [{ message: 'The "$on" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] },
3435
{ code: '$rootScope.$watch()', errors: [{ message: 'The "$watch" call should be assigned to a variable, in order to be destroyed during the $destroy event'}] }
3536
]

0 commit comments

Comments
 (0)