43081j / eslint-plugin-lit

lit-html support for ESLint
120 stars 22 forks source link

False positive when using static expressions #211

Open hampoelz opened 3 weeks ago

hampoelz commented 3 weeks ago

The following minimal code triggers the rules "lit/binding-positions" and "lit/no-invalid-html", although it should be completely valid according to the lit documentation (https://lit.dev/docs/templates/expressions/#static-expressions).

import { html, literal, StaticValue } from 'lit/static-html.js';

const tag: StaticValue = literal`header`;
return html`<${tag} class="classes">Content</${tag}>`
43081j commented 3 weeks ago

good catch

we explicitly don't allow tag bindings (from before lit allowed them)

this is a tough one to fix though. if we remove that, we'll be allowing all tag name bindings even though lit only supports ones which use literal

we can't easily detect if you're using literal either since we're only linting syntax, i.e. we don't have hold of the type checker etc. we could, but it'd then make this rule a typed rule (requires typescript to run)

would be good to get some opinions on this. i'd be tempted to just allow them all and hope the user knows what they're doing

hampoelz commented 1 week ago

The best solution would of course be to add typescript support as an optional config (for example lit/typescript), especially if there are other rules that would benefit from typescript.

Otherwise it would probably be enough to add a note to the docs stating that in this case the rules can be ignored and can be configured as warning.

43081j commented 1 week ago

I agree

I wonder how easy it will be to check for the existence of tseslint in the parser services. Then if it exists, we do a more thorough check. Otherwise we allow all tag bindings