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

module-getter/module-setter: reversed settings

Open jrencz opened this issue 8 years ago • 0 comments

My use case: I'm preparing an ES6+ starter for Angular 1. I'm using ES modules in it.

I'm assigning Angular module to a variable:

const module = angular.module('myModule', [])

and that's why I don't want angular/module-setter rule on.

I do export default module.name so in another module I can

import MyModule from './my-module'

and that's why I don't need angular/module-getter on.

But keeping those rules off is not best I can get to express my intentions. It came to my mind that I'd like not only not to check if getters are used or module is assigned, but actively disallow that. IMO ES Modules are a valid use case of why would one want to do it.


I suggest that configuration of both angular/module-setter and angular/module-getter should be extended from no 2nd argument (as it is now) to 'always'and 'never' keywords.

Now:

{
  "rules": {
    "angular/module-getter": "error",
    "angular/module-setter": "error"
  }
}

What I suggest:

To express current configuration (that rules are on):

{
  "rules": {
    "angular/module-getter": ["error", "always"],
    "angular/module-setter": ["error", "never"]
  }
}

The choice of keywords: If one has angular/module-getter enabled he "wants getter syntax to always be used" If one has angular/module-setter enabled he "wants angular modules to never be assigned to variables"

(BTW: I think having angular/module-setter rule renamed to angular/no-module-variable-assignment or so will make configuration more straightforward because now name is far from self-explainatory because "angular/no-module-variable-assignment": ["error", "always"] seems to read a bit better than "angular/module-setter": ["error", "never"])

The opposite (outcome I'd like to achieve for my ES Modules NG1 configuration) would be:

{
  "rules": {
    "angular/module-getter": ["error", "never"],
    "angular/module-setter": ["error", "always"]
  }
}

Which states that: I'd like to enforce NOT using angular module getter syntax and I'd like to enforce assigning newly created angular module to a variable.

jrencz avatar Jan 17 '17 11:01 jrencz