43081j / eslint-plugin-lit

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

`lit/no-this-assign-in-render` seems to false positive when you assign a local variable with the value of this.property #170

Closed halkeye closed 1 year ago

halkeye commented 1 year ago

fine:

const _twitter: TemplateResult | symbol = this.twitter ? html`<li><a href=${`https://twitter.com/${this.twitter}`} target="_blank" rel="noreferrer noopener">Twitter</a></li>` : nothing;

fails:

let _twitter: TemplateResult | symbol = nothing;
if (this.twitter) {
  _twitter = html`<li><a href=${`https://twitter.com/${this.twitter}`} target="_blank" rel="noreferrer noopener">Twitter</a></li>`; // eslint warns
}
43081j commented 1 year ago

sorry only just getting to this!

that definitely seems like a bug, ill see if i can reproduce it in a test 👍

43081j commented 1 year ago

it passes locally in tests, can you give me information on the error you get from eslint?

maybe the console output of eslint path/to/the/file.ts?

halkeye commented 1 year ago

https://gist.github.com/halkeye/d89a183a92f082ccd76ea313a98c81c4

 npx eslint src/jio-socialmedia-buttons.ts

/home/halkeye/go/src/github.com/jenkins-infra/jenkins-io-components/src/jio-socialmedia-buttons.ts
  27:7  error  Members of `this` should not be assigned to in the render method. It is likely you should do this elsewhere instead (e.g. in `updated`)  lit/no-this-assign-in-render

✖ 1 problem (1 error, 0 warnings)