Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

angular/module-getter and angular/di: false positive when calling providers' config method #223

Closed
Jbelmonte opened this issue Sep 20, 2015 · 7 comments
Assignees
Milestone

Comments

@Jbelmonte
Copy link

I'm getting both angular/module-getter and angular/di errors when validating a file containing config call of a module.

Here's the snippet:

(function () {
  'use strict';

  angular
    .module('app')
    .config(moduleConfig);

  moduleConfig.$inject = ['$breadcrumbProvider', 'ngTableHelperProvider'];
  function moduleConfig($breadcrumbProvider, ngTableHelperProvider) {
    $breadcrumbProvider.setOptions({
      prefixStateName: 'app',
      templateUrl: 'app/widgets/breadcrumb/breadcrumb.template.html'
    });

    ngTableHelperProvider.config({count: 10}, {});
  }
})();

And here the error in terminal:

[...]/src/app/app.config.js
  15:5  error  Avoid using a variable and instead use chaining with the getter syntax  angular/module-getter
  15:5  error  You should use the function syntax for DI                               angular/di

Rule is failing in line 15 because of (I guess) a call to a method named config, but not in line 10 where provider's method is named setOptions.

None of them refers to a module variable.

@gitnik
Copy link

gitnik commented Nov 11, 2015

+1 for angular/di failing on config

@EmmanuelDemey
Copy link
Owner

I think the angular/di is normal.
The problem is the ngTableHelperProvider provider that is detect as a angular module in the module-getter rule.
We have other use-cases : $router.config, $ocLazyLoadProvider.config, and $localForageProvider.config

@maksimr
Copy link
Collaborator

maksimr commented Nov 20, 2015

Have the same problem. @Gillespie59 what I should do to fix this problem? Why ngTableHelperProvider is detected as a angular module?

@Jbelmonte
Copy link
Author

@Gillespie59 may it be caused by a .config(...) call? May some code assume that config method calls are always associated to a module definition?

@remcohaszing
Copy link
Collaborator

Currently there is no angular module detection at all. To solve this problem in a more generic way I created angularRule.

I suggest the following:

  • Let angularRule pass the resolved variable resolved by ESLint into the angular:* functions.
  • The rule implementation is now as simple as:
    • If the second argument passed to the CallExpression node is an array, the array syntax is used.
    • If there are any references to the variable setting it's $inject property, it's $inject syntax
    • Otherwise it's function syntax

@OzzieOrca
Copy link

Any updates?

@SadiSofiane
Copy link

Same problem, no fix planned ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants