UNPKG

1.26 kBJavaScriptView Raw
1/**
2 * require and specify consistent use `$scope.digest()` or `$scope.apply()`
3 *
4 * For the execution of the watchers, the $digest method will start from the scope in which we call the method.
5 * This will cause an performance improvement comparing to the $apply method, who start from the $rootScope
6 *
7 * @version 0.4.0
8 * @category conventions
9 * @sinceAngularVersion 1.x
10 */
11'use strict';
12
13module.exports = {
14 meta: {
15 schema: [{
16 enum: ['$apply', '$digest']
17 }]
18 },
19 create: function(context) {
20 var method = context.options[0] || '$digest';
21 var methods = ['$apply', '$digest'];
22 return {
23
24 MemberExpression: function(node) {
25 var forbiddenMethod = methods.filter(function(m) {
26 return m !== method;
27 });
28 if (forbiddenMethod.length > 0 && node.property.type === 'Identifier' && forbiddenMethod.indexOf(node.property.name) >= 0) {
29 context.report(node, 'Instead of using the {{forbidden}}() method, you should prefer {{method}}()', {
30 forbidden: node.property.name,
31 method: method
32 });
33 }
34 }
35 };
36 }
37};