eslint-plugin-angular icon indicating copy to clipboard operation
eslint-plugin-angular copied to clipboard

False positive for angular/di: [2, "array"] rule

Open reupen opened this issue 9 years ago • 5 comments

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"]*/.

reupen avatar Feb 29 '16 14:02 reupen

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

sukrosono avatar Mar 02 '16 06:03 sukrosono

That (correctly) fails with angular/di: [2, "array"]

Yes, I would've expected the original example to pass under array and fail under function.

reupen avatar Mar 02 '16 10:03 reupen

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


sukrosono avatar Mar 02 '16 11:03 sukrosono

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) {
}

EmmanuelDemey avatar Sep 19 '16 10:09 EmmanuelDemey

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

EmmanuelDemey avatar Sep 19 '16 12:09 EmmanuelDemey