curlylint
curlylint copied to clipboard
dynamic attributes cause parse error
Describe the bug
template:
<div {{ name }}="value"></div>
0:15 Parse error: expected one of '>', '\\s+', '{#', '{%', '{{' at 0:15 parse_error
This seems like a reasonable (albeit slightly unusual) template.
Which terms did you search for in the documentation and issue tracker?
looked at all open and closed issues
(Write your answer here if relevant.)
Environment
$ curlylint --version
curlylint, version 0.12.0
Hey @davidszotten, thank you for the detailed report! That’s definitely a reasonable template, and a case that the parser currently doesn’t support. I think the logic for "template syntax in opening tags" simply needs implementing.
If you or anyone else is interested in helping with this – well, this might make for a tough first contribution, but as a starter I’d love to have unit tests written for this. The parser is in need of much better tests, so we can make additions like this without risking regressions.
Here is the code for future reference:
https://github.com/thibaudcolas/curlylint/blob/f2b448f92de14c6c9535b5e7071d38175b0dae1c/curlylint/parse.py#L380-L422
Another example of a parse_error
for reference.
Template
<a class="govuk-button"href="/cookies">Set cookie preferences</a>
0:23 Parse error: expected one of '>', '\\s+', '{#', '{%', '{{' at 0:23 parse_error
Throwing an error makes sense, there is a missing space between the attributes but parse_error
does seem like the right error and message.
Environment
$ curlylint --version
curlylint, version 0.12.0
👍 good to know about @colmjude. I think that one would be much simpler to address – by the looks of it the problem is that the parser expects attributes to always be separated by whitespace, which as you say feels like a reasonable thing to enforce, but it probably shouldn’t be a (cryptic) parse error:
https://github.com/thibaudcolas/curlylint/blob/1cb1e336a474e660829d3b1a808cfda749f8f375/curlylint/parse.py#L385-L396