EmmanuelDemey / eslint-plugin-angular

ESLint plugin for AngularJS applications
https://www.npmjs.com/package/eslint-plugin-angular
618 stars 131 forks source link

Rules `no-services` and `di-order` don't work in AngularJS components #555

Open jbanulso opened 6 years ago

jbanulso commented 6 years ago

I use it to detect $http and $resource injections like this:

"angular/no-services": [2, ["http", "resource"]]

However, it doesn't detect those injections in my components. I've even tried to configure the rule like this, with no luck either way:

"angular/no-services": [2, ["http", "resource"], ["component"]]

// or

"angular/no-services": [2, {"component": ["http", "resource"]}]

EDIT: The rule di-order does not work either. This could potentially mean that other rules related to controllers might not work inside components.

miqh commented 6 years ago

@jbanulso, component definitions (i.e. the object passed along to .component(...)) shouldn't be injectable, thus this lint shouldn't concern them.

If a component need any dependencies, they should have them injected into the controller property of the component.

How exactly are you defining your components?

jbanulso commented 6 years ago

@miqh I define my components like this (sometimes without the direct injection, either way doesn't work for me):

var DummyComponent = {
    controller: DummyController,
    templateUrl: 'dummy.component.html'
};

function DummyController($http) { }

DummyController.$inject = ['$http'];

angular
  .module('DummyModule')
  .component('dummy', DummyComponent);
jbanulso commented 6 years ago

Actually, I've just noticed that the same problem occurs with the di-order rule (and maybe with others?), so I'll update the title of the issue.