43081j / eslint-plugin-lit

lit-html support for ESLint
120 stars 22 forks source link

split up no-template-bind #35

Closed LarsDenBakker closed 5 years ago

LarsDenBakker commented 5 years ago

Currently the no-template-bind rule also takes care of inline arrow functions.

Binding in templates is completely unnecessary, and should always be avoided. Arrow functions however are definitely needed in some cases, such as to pass arguments when repeating a template.

It would be nice if these were split up, so that they can be configured separately.

LarsDenBakker commented 5 years ago

An example of when you need an arrow function:

class MyElement extends LitElement {
  render() {
    return html`
      ${this.items.map((item, i)=> html`
        <my-child @something=${() => this._onSomething(item, i)}></my-child>
      `}
    `;
  }
}
43081j commented 5 years ago

It was introduced as a rule to catch all inline functions and binds essentially. To enforce the practice of separating your function out into methods or constants further up in the render method.

So I would probably prefer an option to allow arrow functions as opposed to a separate rule, something we can add quite easily.

jhpratt commented 5 years ago

@43081j Any plans to implement this? Running into the exact same issue. All I'm doing is setting a single property, so there's not really any reason to extract it into a full method.

43081j commented 5 years ago

Fixed in #41. Will go out in 1.0.0 soon