43081j / eslint-plugin-lit

lit-html support for ESLint
115 stars 20 forks source link

fix: allow decorated properties with class fields #201

Closed 43081j closed 2 months ago

43081j commented 2 months ago

Allows properties decorated with lit property decorators to have class fields alongside.

This loosens the strictness of the rule under the assumption you have set useDefineForClassFields: false in typescript.

If you use declare or accessor, those fields will already be ignored by this rule.

Examples:

// Error
class X extends LitElement {
  fieldA;
  static properties = {fieldA: {type: String}};
}

// Works now, errored before
class X extends LitElement {
  @property()
  fieldA;
}

// Worked before, works now
class X extends LitElement {
  @property()
  declare fieldA;
}

// Worked before, works now
class X extends LitElement {
  declare fieldA;
  static properties = {fieldA: {type: String}};
}

// Worked before, works now
class X extends LitElement {
  @property()
  accessor fieldA;
}

Fixes #193.

43081j commented 2 months ago

@steverep i just tried this on the renovate branch in home assistant

it seems to fix the problem, though i think you'll be hit by lit/attribute-names too

given most of your properties conflict with that rule, you may want to just disable it (once this fix lands)