Skip to content

Commit 0df0524

Browse files
Merge pull request #463 from Gillespie59/development
2.2.0
2 parents 12cfb2e + 1995dc8 commit 0df0524

File tree

6 files changed

+42
-37
lines changed

6 files changed

+42
-37
lines changed

docs/no-services.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,45 @@ The following patterns are **not** considered problems with default config;
3434
// ...
3535
});
3636

37-
The following patterns are considered problems when configured `["$http","$q"]`:
37+
The following patterns are considered problems when configured `["http","q"]`:
3838

39-
/*eslint angular/no-services: [2,["$http","$q"]]*/
39+
/*eslint angular/no-services: [2,["http","q"]]*/
4040

4141
// invalid
4242
app.directive('helloWorld', function($q) {
4343
// ...
4444
}); // error: REST API calls should be implemented in a specific service ($q in directive)
4545

46-
The following patterns are **not** considered problems when configured `["$http","$q"]`:
46+
The following patterns are **not** considered problems when configured `["http","q"]`:
4747

48-
/*eslint angular/no-services: [2,["$http","$q"]]*/
48+
/*eslint angular/no-services: [2,["http","q"]]*/
4949

5050
// valid
5151
app.directive('helloWorld', function($resource) {
5252
// ...
5353
});
5454

55-
The following patterns are considered problems when configured `["$http","$q"]` and `["directive"]`:
55+
The following patterns are considered problems when configured `["http","q"]` and `["directive"]`:
5656

57-
/*eslint angular/no-services: [2,["$http","$q"],["directive"]]*/
57+
/*eslint angular/no-services: [2,["http","q"],["directive"]]*/
5858

5959
// invalid
6060
app.directive('MyController', function($http) {
6161
// ...
6262
}); // error: REST API calls should be implemented in a specific service ($http in directive)
6363

64-
The following patterns are **not** considered problems when configured `["$http","$q"]` and `["directive"]`:
64+
The following patterns are **not** considered problems when configured `["http","q"]` and `["directive"]`:
6565

66-
/*eslint angular/no-services: [2,["$http","$q"],["directive"]]*/
66+
/*eslint angular/no-services: [2,["http","q"],["directive"]]*/
6767

6868
// valid
6969
app.controller('MyController', function($http) {
7070
// ...
7171
});
7272

73-
The following patterns are considered problems when configured `{"directive":["$http","$q"],"controller":["$resource"]}`:
73+
The following patterns are considered problems when configured `{"directive":["http","q"],"controller":["resource"]}`:
7474

75-
/*eslint angular/no-services: [2,{"directive":["$http","$q"],"controller":["$resource"]}]*/
75+
/*eslint angular/no-services: [2,{"directive":["http","q"],"controller":["resource"]}]*/
7676

7777
// invalid
7878
app.controller('MyController', function($resource, $log) {
@@ -84,9 +84,9 @@ The following patterns are considered problems when configured `{"directive":["$
8484
// ...
8585
}); // error: REST API calls should be implemented in a specific service ($http in directive)
8686

87-
The following patterns are **not** considered problems when configured `{"directive":["$http","$q"],"controller":["$resource"]}`:
87+
The following patterns are **not** considered problems when configured `{"directive":["http","q"],"controller":["resource"]}`:
8888

89-
/*eslint angular/no-services: [2,{"directive":["$http","$q"],"controller":["$resource"]}]*/
89+
/*eslint angular/no-services: [2,{"directive":["http","q"],"controller":["resource"]}]*/
9090

9191
// valid
9292
app.controller('MyController', function($http, $q, $log) {

examples/no-services.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ app.controller('MyController', function(myService) {
33
// ...
44
});
55

6+
67
// example - valid: false, errorMessage: "REST API calls should be implemented in a specific service ($http in controller)"
78
app.controller('MyController', function($http) {
89
// ...
@@ -13,43 +14,43 @@ app.directive('helloWorld', function($resource) {
1314
// ...
1415
});
1516

16-
// example - valid: true, options: [["$http","$q"]]
17+
// example - valid: true, options: [["http","q"]]
1718
app.directive('helloWorld', function($resource) {
1819
// ...
1920
});
2021

21-
// example - valid: false, options: [["$http","$q"]], errorMessage: "REST API calls should be implemented in a specific service ($q in directive)"
22+
// example - valid: false, options: [["http","q"]], errorMessage: "REST API calls should be implemented in a specific service ($q in directive)"
2223
app.directive('helloWorld', function($q) {
2324
// ...
2425
});
2526

26-
// example - valid: true, options: [["$http","$q"],["directive"]]
27+
// example - valid: true, options: [["http","q"],["directive"]]
2728
app.controller('MyController', function($http) {
2829
// ...
2930
});
3031

31-
// example - valid: false, options: [["$http","$q"],["directive"]], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
32+
// example - valid: false, options: [["http","q"],["directive"]], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
3233
app.directive('MyController', function($http) {
3334
// ...
3435
});
3536

3637

37-
// example - valid: true, options: [{"directive":["$http","$q"],"controller":["$resource"]}]
38+
// example - valid: true, options: [{"directive":["http","q"],"controller":["resource"]}]
3839
app.controller('MyController', function($http, $q, $log) {
3940
// ...
4041
});
4142

42-
// example - valid: true, options: [{"directive":["$http","$q"],"controller":["$resource"]}]
43+
// example - valid: true, options: [{"directive":["http","q"],"controller":["resource"]}]
4344
app.directive('helloWorld', function($resource, $log) {
4445
// ...
4546
});
4647

47-
// example - valid: false, options: [{"directive":["$http","$q"],"controller":["$resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($resource in controller)"
48+
// example - valid: false, options: [{"directive":["http","q"],"controller":["resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($resource in controller)"
4849
app.controller('MyController', function($resource, $log) {
4950
// ...
5051
});
5152

52-
// example - valid: false, options: [{"directive":["$http","$q"],"controller":["$resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
53+
// example - valid: false, options: [{"directive":["http","q"],"controller":["resource"]}], errorMessage: "REST API calls should be implemented in a specific service ($http in directive)"
5354
app.directive('helloWorld', function($http, $log) {
5455
// ...
5556
});

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

rules/module-dependency-order.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ module.exports = {
6060
];
6161

6262
function checkLiteral(node) {
63-
if (node && node.type !== 'Literal') {
64-
context.report(node, 'Unexpected non-literal value');
63+
if (node && node.type !== 'Literal' && node.type !== 'Identifier') {
64+
context.report(node, 'Unexpected non-literal or identifier value' + node.type);
6565
return false;
6666
}
6767
if (!node) {
@@ -76,7 +76,7 @@ module.exports = {
7676
if (!checkLiteral(node)) {
7777
return;
7878
}
79-
var value = node.value;
79+
var value = node.value || node.name;
8080
if (lastCorrect === undefined || lastCorrect.localeCompare(value) < 0) {
8181
lastCorrect = value;
8282
} else {
@@ -103,7 +103,7 @@ module.exports = {
103103
if (!checkLiteral(node)) {
104104
return;
105105
}
106-
var value = node.value;
106+
var value = node.value || node.name;
107107
if (lastCorrect === undefined) {
108108
lastCorrect = value;
109109
if (isCustomModule(value)) {

rules/no-services.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = {
3838
}
3939

4040
if (context.options[0] === undefined) {
41-
badServices = ['/\$http/', '/\$resource/', 'Restangular', '/\$q/', '/\$filter/'];
41+
badServices = [/\$http/, /\$resource/, /Restangular/, /\$q/, /\$filter/];
4242
}
4343

4444
if (isArray(context.options[0])) {

test/module-dependency-order.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,19 @@ eslintTester.run('module-dependency-order', rule, {
2323
code: 'angular.module("", ["app.filters","ngCordova","ngMaterial","ui.router"])',
2424
options: [{grouped: false}]
2525
},
26+
{
27+
code: 'angular.module("", [appFilters,ngCordova,ngMaterial,uiRouter])',
28+
options: [{grouped: false}]
29+
},
30+
{
31+
code: 'angular.module("", [appFilters,"ngCordova",ngMaterial,uiRouter])',
32+
options: [{grouped: false}]
33+
},
2634
// grouped mode
2735
'angular.module("", ["ng","ngAnimate","ngAria","ngCookies","ngLocale","ngMaterial","ngMessageFormat","ngMessages","ngMock","ngNewRouter","ngResource","ngRoute","ngSanitize","ngTouch"])',
2836
'angular.module("", ["ngAnimate","ngResource","ngCordova"])',
37+
'angular.module("", [ngAnimate,ngResource,ngCordova])',
38+
'angular.module("", [ngAnimate,"ngResource",ngCordova])',
2939
{
3040
code: 'angular.module("", ["ngAnimate","ngResource","ngCordova","app.filters"])',
3141
options: [{prefix: 'app'}]
@@ -38,14 +48,6 @@ eslintTester.run('module-dependency-order', rule, {
3848
{message: 'Dependencies should be a literal array'}
3949
]
4050
},
41-
// combined mode
42-
{
43-
code: 'angular.module("", [dep])',
44-
options: [{grouped: false}],
45-
errors: [
46-
{message: 'Unexpected non-literal value'}
47-
]
48-
},
4951
{
5052
code: 'angular.module("", ["ngCordova","app.filters","app.resources","ngMaterial","app.user","ui.router"])',
5153
options: [{grouped: false}],
@@ -55,11 +57,13 @@ eslintTester.run('module-dependency-order', rule, {
5557
{message: 'app.user should be sorted before ngMaterial'}
5658
]
5759
},
58-
// grouped mode
5960
{
60-
code: 'angular.module("", [dep])',
61+
code: 'angular.module("", [ngCordova,"app.filters","app.resources",ngMaterial,"app.user","ui.router"])',
62+
options: [{grouped: false}],
6163
errors: [
62-
{message: 'Unexpected non-literal value'}
64+
{message: 'app.filters should be sorted before ngCordova'},
65+
{message: 'app.resources should be sorted before ngCordova'},
66+
{message: 'app.user should be sorted before ngMaterial'}
6367
]
6468
},
6569
{

0 commit comments

Comments
 (0)