NullVoxPopuli / eslint-plugin-decorator-position

ESLint plugin for enforcing decorator position

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a way to define () or not

Alonski opened this issue · comments

It is possible to use certain decorators with () or not:
@service someService;
or
@service() someService;

Would be nice to have a way to define these to be consistent

any thoughts on how the configuration would be?

'decorator-position/redundant-invocation': ['error', { 
  require: ['@computed'],
  omit: ['@service'],
}],

meaning:

// bad
@computed
get foo() {}

@service() someService;

// good
@computed()
get foo() {}

@service someService;
@service('some-service') someService;

I don't think we should call it redundant invocation. () is super important. A called decorator is behaving as factory and this usage is very case-specific. Some decorators may handle that and support, some can require them always and some can treat them as usual decorators.

I think that's a very ember specific use-case. As usual, we have no way to predict if the imported decorator is a factory or not. 🤔

() is super important.
called decorator is behaving as factory and this usage is very case-specific.
I think that's a very ember specific use-case.

it's not ember specific, it's implementation specific. It just so happens that ember uses that pattern on all computed properties and services. Like, I've written generic decorators that allow both forms (like for optional optionals / config)

Some decorators may handle that and support, some can require them always and some can treat them as usual decorators.

don't worry, I in no way would make that assumption ;)
this plugin is meant for all of JS

Anywho, idk how often this comes up in real apps, so idk how much of a priority it is, but by default it would certainly need to have no configuration whatsoever (same with the decorator-position rule).

if someone were to submit a PR that implements this rule and defines some defaults for the ember configuration, I'd be happy to accept it.