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

When using the curlylint linter in Django templates it generates a false positive parse error #127

Closed brammittendorff closed 2 years ago

brammittendorff commented 2 years ago

Describe the bug

When using the following template code in Django templates:

templates/test.html

<input type="{{ field.field.widget.input_type }}" {% for key, value in field.field.widget.attrs.items %}{{ key }}="{{ value }}" {% endfor %}>

or

<input type="{{ field.field.widget.input_type }}" {% for key, value in field.field.widget.attrs.items %} {{ key }}="{{ value }}" {% endfor %}>

It gives a parse error:

❯ curlylint ~/templates/test.html
~/templates/test.html
0:114   Parse error: expected one of '/', '>', 'attribute', 'space(s) between attributes', '{#', '{%', '{{' at 0:114    parse_error

Oh no! 💥 💔 💥
1 error reported

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

I searched for in the issue tracker for:

Django error
Django parse_error

But i couldn't find the same kind of issue.

Environment

Version

❯ curlylint --version
curlylint, version 0.13.0

OS

Windows 10

And also:

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:    20.04
Codename:   focal

Steps to reproduce

(Write your steps here:)

  1. Create a test.html file with the following contents:
<input type="{{ field.field.widget.input_type }}" {% for key, value in field.field.widget.attrs.items %} {{ key }}="{{ value }}" {% endfor %}>
  1. Then run curlylint
curlylint test.html

Expected behavior

It shouldn't complain about a parse_error because this is regular Django template language.

Actual behavior

It gives a parse_error:

❯ curlylint test.html
test.html
0:114   Parse error: expected one of '/', '>', 'attribute', 'space(s) between attributes', '{#', '{%', '{{' at 0:114    parse_error

Oh no! 💥 💔 💥
1 error reported
thibaudcolas commented 2 years ago

Hi @brammittendorff, thank you for taking the time to report this with so many details! I believe this is the same issue as #23, so I’ll close in favour of that older entry.