UNPKG

1.87 kBJavaScriptView Raw
1/**
2 * require to use `angular.mock` methods directly
3 *
4 * All methods defined in the angular.mock object are also available in the object window.
5 * So you can remove angular.mock from your code
6 *
7 * @version 0.2.0
8 * @category angularWrapper
9 *
10 * NOTE: While this rule does enforce the use of `angular.mock` methods to be used
11 * in the object window, the `eslint` rule no-undef (http://eslint.org/docs/rules/no-undef.html)
12 * may prevent you from using undefined global variables such as those provided by
13 * `angular.mock`. The current fix for this is to simply add all of the `angular.mock`
14 * object methods to your `eslint` globals:
15 *
16 * "globals": {
17 * "angular": false,
18 * "module": false,
19 * "inject": false
20 * }
21 *
22 * At this time (01/06/2016), there is no way to add globals for a specific environment
23 * in `eslint`, although it is an accepted feature (https://github.com/eslint/eslint/issues/4782)
24 * and should exist sometime in the future.
25 *
26 * Check here(https://github.com/Gillespie59/eslint-plugin-angular/issues/330)
27 * for more information on this topic.
28 *
29 * @sinceAngularVersion 1.x
30 */
31'use strict';
32
33module.exports = {
34 meta: {
35 schema: []
36 },
37 create: function(context) {
38 return {
39
40 MemberExpression: function(node) {
41 if (node.object.type === 'Identifier' && node.object.name === 'angular' &&
42 node.property.type === 'Identifier' && node.property.name === 'mock') {
43 if (node.parent.type === 'MemberExpression' && node.parent.property.type === 'Identifier') {
44 context.report(node, 'You should use the "{{method}}" method available in the window object.', {
45 method: node.parent.property.name
46 });
47 }
48 }
49 }
50 };
51 }
52};