Skip to content

Commit 2c47277

Browse files
committed
2 parents 17df044 + 8a7683a commit 2c47277

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +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. |
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_`. |
8585
| '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) |
8686
| '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) |
8787
| '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 |
@@ -136,7 +136,7 @@ Here are the things you should do before sending a Pull Request with a new Rule
136136
* Update the main index.js file, in order to add the new rule in the 'rules' property, and set the default configuration in the rulesConfig property
137137
* Update the "Rules" part of the README.md file with a small description of the rule and its default configuration.
138138

139-
We can use a property, defined in the ESLint configuration file, in order to know which version is used : Angular 1 or Angular 2. based on this property, you can create rules for each version.
139+
We can use a property, defined in the ESLint configuration file, in order to know which version is used : Angular 1 or Angular 2. based on this property, you can create rules for each version.
140140

141141
```yaml
142142
plugins:
@@ -154,7 +154,7 @@ settings:
154154
angular: 2
155155
```
156156

157-
And in your rule, you can access to this property thanks to the `context` object :
157+
And in your rule, you can access to this property thanks to the `context` object :
158158

159159
```javascript
160160
//If Angular 2 is used, we disabled the rule

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)