Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Curlylint complains about split anchor tags introduces by Prettier #16

Open
tunetheweb opened this issue Aug 11, 2020 · 3 comments
Open
Labels
bug Something isn't working parser This issue relates to Curlylint’s templates parser

Comments

@tunetheweb
Copy link

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 tunetheweb added the bug Something isn't working label Aug 11, 2020
@thibaudcolas
Copy link
Owner

thibaudcolas commented Aug 23, 2020

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

return (
style
| script
| void_element
| svg_self_closing_element
| container_element
)
.

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 thibaudcolas added the parser This issue relates to Curlylint’s templates parser label Sep 8, 2020
@thibaudcolas
Copy link
Owner

thibaudcolas commented Mar 13, 2021

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

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

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!

@riodw
Copy link

riodw commented Aug 30, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser This issue relates to Curlylint’s templates parser
Projects
None yet
Development

No branches or pull requests

3 participants