runem / lit-analyzer

Monorepository for tools that analyze lit-html templates
MIT License
317 stars 36 forks source link

lit/no-invalid-html but template runs fine #264

Closed tpluscode closed 1 year ago

tpluscode commented 2 years ago

I am binding an image src to a dummyimage.com URL like so

render() {
  return html`<img src="https://dummyimage.com/300x200/f5f5f5/64bfdb&amp;text=${getLabel(this.resource)}">`
}

It is important that I bind to a directive because the only way is inside as lit tagged literal. Otherwise I would have been able to create a plain string template. That said, interpolating a straight value produces the same errors.

lit-analyzer complains about this template showing 3 errors at this line

ESLint: Template contained invalid HTML syntax, error was: missing-whitespace-between-attributes (lit/no-invalid-html) ESLint: Template contained invalid HTML syntax, error was: unexpected-character-in-attribute-name (lit/no-invalid-html) ESLint: Template contained invalid HTML syntax, error was: unexpected-character-in-attribute-name (lit/no-invalid-html)

The first two errors underline the directive itself. The latter underlines the closing quotation around its invocation.

rictic commented 1 year ago

I'm having trouble reproducing, what's the definition of getLabel?

Also, as an aside, you can write & instead of &amp; there, though &amp; will also work.

tpluscode commented 1 year ago

Thanks for taking a look. I tried to create a minimal repro now and also failed. I see no newer version of the analyzer since. Maybe some dependency was updated in the meanwhile (parser?)?

Let me close. I will reopen if I encounter this again