thibaudcolas / curlylint

Experimental HTML templates linting for Jinja, Nunjucks, Django templates, Twig, Liquid
https://www.curlylint.org/
MIT License
236 stars 25 forks source link

fix: allow whitespace before closing ">" #147

Open sfermigier opened 1 year ago

sfermigier commented 1 year ago

Don't throw up on correct HTML.

OmerFI commented 1 year ago

Normally, following HTML code is not correct:

image

curlylint right now fails (I think this is the expected behaviour):

image

If your pull request is applied, will the HTML code above pass the check?

sfermigier commented 1 year ago

I believe whitespace before > is correct. xmllint confirms.

 ~/tmp> cat toto.xml
<toto
>
</toto
>
 ~/tmp> xmllint toto.xml
<?xml version="1.0"?>
<toto>
</toto>
# Or
 ~/tmp> cat toto.xml
<toto >
</toto >
 ~/tmp> xmllint toto.xml
<?xml version="1.0"?>
<toto>
</toto>
sfermigier commented 1 year ago

See also the XML grammar:

https://www.w3.org/TR/xml/#NT-ETag

(S? stands for "whitespace" in the production rule).

OmerFI commented 1 year ago

That makes sense!

make_opening_tag_parser function already skips whitespaces:

return locate(
    P.seq(
        P.string("<"),
        tag_name_parser,
        attributes.skip(whitespace),
        slash,
        P.string(">"),
    )
).combine(_combine_opening_tag)

And the make_closing_tag_parser function should skip whitespaces too!

OmerFI commented 1 year ago

@thibaudcolas Can you review the pr