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

False negative lit/no-classfield-shadowing #193

Closed
tpluscode opened this issue Mar 6, 2024 · 4 comments · Fixed by #201
Closed

False negative lit/no-classfield-shadowing #193

tpluscode opened this issue Mar 6, 2024 · 4 comments · Fixed by #201

Comments

@tpluscode
Copy link

As I updated the plugin to v1.11, I now have lit/no-classfield-shadowing everywhere, for properties declared with lit@2 decorators

@43081j
Copy link
Owner

43081j commented Mar 10, 2024

do you have an example?

may be that the rule just doesn't make sense with new decorators, but would have to see an example to be sure

@tpluscode
Copy link
Author

Here's the smallest I could quickly concoct by extracting the setup from my project: https://gist.github.com/tpluscode/149377e20f27a47ae0e02fdd453f10a7

@tpluscode
Copy link
Author

tpluscode commented Mar 18, 2024

npx eslint element.ts --quiet will give you one error from the propety

@steverep
Copy link

We have the same problem with Home Assistant, except it occurs when upgrading to 1.12.0. We went from 0 errors to over 6000:

https://github.com/home-assistant/frontend/actions/runs/9081979074/job/24957190667?pr=20775

There was no change to config and deleting cache has no effect. Note the breakage also affects the lit/attribute-names rule.

43081j added a commit that referenced this issue 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:

```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 added a commit that referenced this issue 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:

```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 added a commit that referenced this issue 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:

```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.
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 a pull request may close this issue.

3 participants