curlylint icon indicating copy to clipboard operation
curlylint copied to clipboard

Curlylint complains about split anchor tags introduces by Prettier

Open tunetheweb opened this issue 3 years ago • 3 comments

Describe the bug

Prettier sometimes splits lines like this:

Really long line<a href="example.com">Really long line</a>

Into this:

Really long line<a href="example.com">Really long line</a
>

This is valid HTML, even if it looks a little weird. It's done because white space in between elements can mean something whereas whitespace in elements is safe.

Curlylint does not recognise this as valid and complains.

Which terms did you search for in the documentation and issue tracker?

prettier

Environment

Curlylint 0.12.0

Steps to reproduce

  1. Create a test.html file with the contents of the split line:
Really long line<a href="example.com">Really long line</a
>
  1. Run curlylint on it
curylint test.html

Expected behavior

File should pass linting

Actual behavior

% curlylint test.html 
test.html
0:57	Parse error: expected '>' at 0:57	parse_error

Oh no! 💥 💔 💥
1 error reported

Removing the newline resolves the error and file lints correctly.

Reproducible demo

Given above

tunetheweb avatar Aug 11 '20 18:08 tunetheweb

Hey @bazzadp, thanks for the report. I wouldn’t be surprised if the parser was overly strict in that respect, having had to fix issues with it failing to parse self-closing SVG tags (#4), or uppercase HTML tags.

If you’re keen to look into this I think the fix would likely be to allow whitespace for all of the cases in https://github.com/thibaudcolas/curlylint/blob/35a14129cc1a76bd1b0e71e36a3f78b9ab65d608/curlylint/parse.py#L693-L699.

Looking at the potential implementation, there might be a fair bit of duplication, since parsing for all of those different types of tags is separated out.

In the meantime, it might help to set Prettier to htmlWhitespaceSensitivity: ignore. I’d also happily accept a PR to document this issue on the website (perhaps a new "Known issues" page either at the end of the "Introduction" section, or under "References").


Can I ask what language or Prettier plugin you’re using for your templates? I think I ran into this issue before but didn’t really make much of it since Prettier doesn’t support the template syntax of Jinja / Django Templates I most commonly work with.

thibaudcolas avatar Aug 23 '20 22:08 thibaudcolas

Finally spending time to look into this further, the issue is here:

https://github.com/thibaudcolas/curlylint/blob/c144fc6b1bdd3843e9aaaf1b1750ece6febe36d8/curlylint/parse.py#L450

This assumes the tag name on closing tags is directly followed with >. I think the fix could be as simple as:

-P.string("</").then(tag_name_parser).skip(P.string(">")) 
+P.string("</").then(tag_name_parser).skip(whitespace + P.string(">")) 

However I’m a bit hesitant to make parser changes like this until there is a better test suite in place. Any help towards this would be much appreciated!

thibaudcolas avatar Mar 13 '21 22:03 thibaudcolas

Upvote for this from me.

Is there a way to tell curly to ignore these types of errors in the meantime?

  • 220:12 Parse error: expected one of '>', 'attribute', '{#', '{%', '{{' at 220:12 parse_error

riodw avatar Aug 30 '22 02:08 riodw