Skip to content

Commit c224914

Browse files
committed
Merge master
2 parents aa10d30 + 2c47277 commit c224914

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ We provide also three samples :
8181
| 'ng_deferred':0 | When you want to create a new promise, you should not use the $q.deferred anymore. Prefer the new syntax : $q(function(resolve, reject){})
8282
| 'ng_definedundefined': 2 | You should use the angular.isUndefined or angular.isDefined methods instead of using the keyword undefined. We also check the use of !angular.isUndefined and !angular.isDefined (should prefer the reverse function)|
8383
| 'ng_di': [2, 'function'] | All your DI should use the same syntax : the Array or function syntaxes ("ng_di": [2, "function or array"])|
84-
| 'ng_di_order': 0 | Injected dependencies should be sorted alphabetically. |
85-
| 'ng_di_unused': 0 | Unused dependencies should not be injected. |
84+
| 'ng_di_order': [0, true] | Injected dependencies should be sorted alphabetically. If the second parameter is set to false, values which start and end with an underscore those underscores are stripped. This means for example that `_$httpBackend_` goes before `_$http_`. |
8685
| 'ng_directive_name': 0 | All your directives should have a name starting with the parameter you can define in your config object. The second parameter can be a Regexp wrapped in quotes. You can not prefix your directives by "ng" (reserved keyword for AngularJS directives) ("ng_directive_name": [2, "ng"]) [Y073](https://github.com/johnpapa/angular-styleguide#style-y073), [Y126](https://github.com/johnpapa/angular-styleguide#style-y126) |
8786
| 'ng_document_service': 2 | Instead of the default document object, you should prefer the AngularJS wrapper service $document. [Y180](https://github.com/johnpapa/angular-styleguide#style-y180) |
8887
| 'ng_empty_controller': 0 | If you have one empty controller, maybe you have linked it in your Router configuration or in one of your views. You can remove this declaration because this controller is useless |

rules/ng_di_order.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,13 @@ module.exports = function(context) {
1818
];
1919

2020
function checkOrder(fn) {
21+
if(!fn || !fn.params) {
22+
return;
23+
}
2124
var args = fn.params.map(function(arg) {
25+
if(context.options[0] !== false) {
26+
return arg.name.replace(/^_(.+)_$/, '$1')
27+
}
2228
return arg.name;
2329
});
2430
var sortedArgs = args.slice().sort();

test/ng_di_order.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ eslintTester.run('ng_di_order', rule, {
2424
'inject(function($http, $q){});',
2525
'it(inject(function($http, $q){}));',
2626
'this.$get = function($http, $q){};',
27+
'this.$get = get;',
28+
'it(inject(function(_$http_, _$httpBackend_){}));',
29+
{
30+
code: 'it(inject(function(_$httpBackend_, _$http_){}));',
31+
options: [false],
32+
}
2733
],
2834
invalid: [{
2935
code: 'app.controller("", function($q, $http){});',
@@ -55,6 +61,13 @@ eslintTester.run('ng_di_order', rule, {
5561
}, {
5662
code: 'it(inject(function($q, $http){}));',
5763
errors: [{message: 'Injected values should be sorted alphabetically'}]
64+
}, {
65+
code: 'it(inject(function(_$http_, _$httpBackend_){}));',
66+
options: [false],
67+
errors: [{message: 'Injected values should be sorted alphabetically'}]
68+
}, {
69+
code: 'it(inject(function(_$httpBackend_, _$http_){}));',
70+
errors: [{message: 'Injected values should be sorted alphabetically'}]
5871
}, {
5972
code: 'this.$get = function($q, $http){};',
6073
errors: [{message: 'Injected values should be sorted alphabetically'}]

0 commit comments

Comments
 (0)