Skip to content

Commit

Permalink
fix: allow decorated properties with class fields
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
43081j committed May 14, 2024
1 parent ab2fb54 commit ecf3469
Show file tree
Hide file tree
Showing 6 changed files with 606 additions and 405 deletions.
6 changes: 3 additions & 3 deletions docs/rules/no-classfield-shadowing.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Disallows class fields with same name as static properties
# Disallows class fields with same name as reactive properties

Class fields set with same names as static properties will not trigger updates as expected. They will overwrite
Class fields set with same names as reactive properties will not trigger updates as expected. They will overwrite
accessors used for detecting changes. See https://lit.dev/msg/class-field-shadowing for more information.

## Rule Details

This rule disallows class fields with same name as static properties.
This rule disallows class fields with same name as reactive properties.

The following patterns are considered warnings:

Expand Down
Loading

0 comments on commit ecf3469

Please sign in to comment.