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

di-order does not work with DI-enabled ES Class constructors

Open jrencz opened this issue 8 years ago • 1 comments

Example (expected outcome: angular/di-order error):

/*eslint angular/di-order: [2, false, "case_insensitive]*/

class FooCtrl {
  constructor(
    c,
    b,
    a
  ) {
    'ngInject';

    this.a = a;
    this.b = b;
    this.c = c;
  }
}

angular.module('foo', []).component('foo', {
  controller: FooCtrl
});

Class constructor is not matched by the rule although it's matched by olov/ng-annotate with 'ngInject' statement at the beginning.

ng-annotate follows references so I believe it would match this example anyway since after transpilation it's just a function and annotate follows function references. In case class was defined in a distinct ES module (which is a bit more complex example and off course there would be no way to follow a reference) ng-annotate would require 'ngInject' statement. But let's stick to what annotate README states:

ng-annotate supports ES5 as input so run it with the output from Babel, Traceur, TypeScript (tsc) and the likes. Use "ngInject" on functions you want annotated.

I suggest angular/di-order should apply to all functions having 'ngInject' statement and assume they are DI-enabled.

jrencz avatar Jan 20 '17 15:01 jrencz

I have the same problem with di-unused.

floriangosse avatar Jul 18 '17 14:07 floriangosse