eslint-plugin-angular
eslint-plugin-angular copied to clipboard
False positive for angular/di: [2, "array"] rule
In version 1.0.0, the following does not pass linting:
'use strict';
/*eslint angular/di: [2,"array"]*/
angular.module('myApp.myService')
.factory('myService', ['myDep', myService]);
function myService(myDep) {
}
$ ./node_modules/.bin/eslint test.js
test.js
9:1 error You should use the array syntax for DI angular/di
✖ 1 problem (1 error, 0 warnings)
It was OK under 0.15.0. Also it passes under /*eslint angular/di: [2,"function"]*/.
Could you try use like so :
angular.module('myApp.myService')
.factory('myService', myService);
myService.$inject = ['myDep'];
function myService(myDep) {
...
}
For angular/di: [2, "array"]
Let me know if it pass or even fail.
IMO using array more understandable than func for this rule
That (correctly) fails with angular/di: [2, "array"]
Yes, I would've expected the original example to pass under array and fail under function.
Sorry for that, i just notice that we have 3 possible configuration. When i compare your code and example. I found that your code use named function but the example use anonymous function.
According to the test not listed on valid one. CMIIW
Let's wait the contributor :smile: , If require a PR maybe sorting the test by it's configOption will be more readable code ie :
{
code: ...,
options: ['array']
},{
code: ...,
options: ['array']
},{
code: ...,
options: ['fucntion']
},{
code: ...,
options: ['function']
},
etc
I think with the "function" parameter, it should fail, because you use the array syntax. But should succeed with the "array" parameter.
'use strict';
/*eslint angular/di: [2,"array"]*/
angular.module('myApp.myService')
.factory('myService', ['myDep', myService]);
function myService(myDep) {
}
I think the problem come from the way we detect AngularJS elements in our rules. can find for the moment a good approach in order to solve this issue :s