EmmanuelDemey / EmmanuelDemey/eslint-plugin-angular

module-getter/module-setter: reversed settings

Open
#436 0 comments 0 reactions 0 assignees View on GitHub
Hacktoberfest
Dominant language
JavaScript
Stars
620
Forks
127
PR merge metrics
No merged PRs in 30d

Description

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:

```js
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

```js
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:
```json
{
"rules": {
"angular/module-getter": "error",
"angular/module-setter": "error"
}
}
```

What I suggest:

To express current configuration (that rules are on):
```json
{
"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:
```json
{
"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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.