Skip to content

Commit 24ab243

Browse files
committed
Merge pull request #154 from Gillespie59/development
0.4.0
2 parents e57930e + 7f0993f commit 24ab243

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ We provide also three samples :
9494
| 'ng_module_setter':2 | Declare modules without a variable using the setter syntax.[Y021](https://github.com/johnpapa/angular-styleguide#style-y021) |
9595
| 'ng_no_angular_mock':0 | All methods defined in the angular.mock object are also available in the object window. So you can remove angular.mock from your code
9696
| 'ng_no_cookiestore':2 | In Angular 1.4, the $cookieStore service is now deprected. Please use the $cookies service instead|
97-
| 'ng_no_digest': 2 | The scope's $digest() method shouldn't be used. You should prefer the $apply method. |
97+
| 'ng_no_digest': 2 | DEPRECATED! The scope's $digest() method shouldn't be used. You should prefer the $apply method. |
9898
| 'ng_no_jquery_angularelement': 2 | You should not wrap angular.element object into jQuery(), because angular.element already return jQLite element|
9999
| 'ng_no_private_call': 2 | All scope's properties/methods starting with $$ are used internally by AngularJS. You should not use them directly. |
100100
| 'ng_no_services': [2, ['$http', '$resource', 'Restangular']] | Some services should be used only in a specific AngularJS service (Ajax-based service for example), in order to follow the separation of concerns paradigm. The second parameter specifies the services. The third parameter can be a list of angular objects (controller, factory, etc.). Or second parameter can be an object, where keys are angular object names and value is a list of services (like {controller: ['$http'], factory: ['$q']}) |
@@ -109,6 +109,7 @@ We provide also three samples :
109109
| 'ng_typecheck_object': 2 | You should use the angular.isObject method instead of the default JavaScript implementation (typeof {} === "[object Object]"). |
110110
| 'ng_typecheck_regexp': 2 | You should use the angular.isRegexp method instead of the default JavaScript implementation (toString.call(/^A/) === "[object RegExp]"). |
111111
| 'ng_typecheck_string': 2 | You should use the angular.isString method instead of the default JavaScript implementation (typeof "" === "[object String]"). |
112+
| 'ng_watchers_execution': [0, '$digest'] | For the execution of the watchers, the $digest method will start from the scope in which we call the method. This will cause an performance improvement comparing to the $apply method, who start from the $rootScope |
112113
| 'ng_window_service': 2 | Instead of the default window object, you should prefer the AngularJS wrapper service $window. [Y180](https://github.com/johnpapa/angular-styleguide#style-y180) |
113114

114115

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
'ng_typecheck_object': require('./rules/ng_typecheck_object'),
4040
'ng_typecheck_regexp': require('./rules/ng_typecheck_regexp'),
4141
'ng_typecheck_string': require('./rules/ng_typecheck_string'),
42+
'ng_watchers_execution': require('./rules/ng_watchers_execution'),
4243
'ng_window_service': require('./rules/ng_window_service')
4344
},
4445
rulesConfig: {
@@ -63,7 +64,7 @@
6364
'ng_module_setter': 2,
6465
'ng_no_angular_mock': 0,
6566
'ng_no_cookiestore': 2,
66-
'ng_no_digest': 2,
67+
'ng_no_digest': 0,
6768
'ng_no_jquery_angularelement': 2,
6869
'ng_no_private_call': 2,
6970
'ng_no_services': [2, ['$http', '$resource', 'Restangular', '$q']],
@@ -78,6 +79,7 @@
7879
'ng_typecheck_object': 2,
7980
'ng_typecheck_regexp': 2,
8081
'ng_typecheck_string': 2,
82+
'ng_watchers_execution': [0, '$destroy'],
8183
'ng_window_service': 2
8284
}
8385
};

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.3.1",
3+
"version": "0.4.0",
44
"description": "ESLint rules for AngularJS projects",
55
"main": "index.js",
66
"repository": {

rules/ng_watchers_execution.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module.exports = function(context) {
2+
3+
'use strict';
4+
5+
var methods = ['$apply', '$digest'];
6+
return {
7+
8+
'MemberExpression': function(node) {
9+
var method = context.options[0];
10+
var forbiddenMethod = methods.filter(function(m){ return m !== method; });
11+
if(forbiddenMethod.length > 0 && node.property.type === 'Identifier' && forbiddenMethod.indexOf(node.property.name) >= 0){
12+
context.report(node, 'Instead of using the {{forbidden}}() method, you should prefer {{method}}()', {
13+
forbidden: node.property.name,
14+
method: method
15+
});
16+
}
17+
}
18+
};
19+
20+
};

test/ng_watchers_executions.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//------------------------------------------------------------------------------
2+
// Requirements
3+
//------------------------------------------------------------------------------
4+
5+
var eslint = require('../node_modules/eslint/lib/eslint'),
6+
ESLintTester = require('eslint-tester');
7+
8+
//------------------------------------------------------------------------------
9+
// Tests
10+
//------------------------------------------------------------------------------
11+
12+
var eslintTester = new ESLintTester(eslint);
13+
eslintTester.addRuleTest('rules/ng_watchers_execution', {
14+
valid: [
15+
{code: '$scope.$apply(function(){})', args: [1, '$apply']},
16+
{code: '$rootScope.$apply(function(){})', args: [1, '$apply']},
17+
{code: '$scope.$digest()', args: [1, '$digest']},
18+
{code: '$rootScope.$digest()', args: [1, '$digest']}
19+
],
20+
invalid: [
21+
{code: '$scope.$apply(function(){})', args: [1, '$digest'], errors: [{ message: 'Instead of using the $apply() method, you should prefer $digest()'}]},
22+
{code: '$rootScope.$apply(function(){})', args: [1, '$digest'], errors: [{ message: 'Instead of using the $apply() method, you should prefer $digest()'}]},
23+
{code: '$scope.$digest()', args: [1, '$apply'], errors: [{ message: 'Instead of using the $digest() method, you should prefer $apply()'}]},
24+
{code: '$rootScope.$digest()', args: [1, '$apply'], errors: [{ message: 'Instead of using the $digest() method, you should prefer $apply()'}]}
25+
]
26+
});

0 commit comments

Comments
 (0)