Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow decorated properties with class fields #201

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

43081j
Copy link
Owner

@43081j 43081j commented May 14, 2024

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
Copy link
Owner Author

43081j commented May 14, 2024

@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)

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:

```ts
// 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 43081j merged commit 9fb7b66 into master May 14, 2024
3 checks passed
@43081j 43081j deleted the shadowing-whoops branch May 14, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False negative lit/no-classfield-shadowing
1 participant