43081j / eslint-plugin-lit

lit-html support for ESLint
116 stars 21 forks source link

add support for parsing HTML documents #117

Closed 43081j closed 2 years ago

43081j commented 2 years ago

Fixes #115

This is another utility one really, adding the ability for template analyzer to parse HTML documents.

It always parses as a fragment at the min, which means something like this:

<html><body>Foo</body></html>

would be parsed as Foo essentially.

by adding this switch in the constructor, we'll parse it as a document instead, maintaining the html/body tags.

cc @stramel

Part im not sure of is if the condition is strong enough, i.e. checking for includes('<html'). seems incredibly unlikely anyone can ever have a <html-something-else tag so maybe its ok?

Also looks like prettier being bumped now decided to re-format URLs

43081j commented 2 years ago

one thing to consider maybe is people doing stuff like this:

<div><!-- <html> --></div>

i suppose that'd make it fall over... but without an absurd amount of pre-parsing im not sure how we can catch such things

andrico1234 commented 2 years ago

@43081j , if you like i can checkout this branch, link it to the lit-a11y eslint repo, and run the test suite?

Will that provide any assurance that everything still works as expected?

43081j commented 2 years ago

Sure that would be useful. I think I just need to add some more tests here too for the edge cases, will probably have time tomorrow

43081j commented 2 years ago

@stramel i've updated it, could you give it another quick look? just changed from an includes to a regex