thibaudcolas / curlylint

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

Stumbles over… I don't know what ;) #62

Closed Natureshadow closed 3 years ago

Natureshadow commented 3 years ago

Describe the bug

I tried curlylint on our set of Django templates, and it stumbled over some things I cannot really explain. One example is this template:

https://edugit.org/AlekSIS/official/AlekSIS-Core/-/blob/d579eec21675787347c7e7d4c2862d9d75030b0a/aleksis/core/templates/dynamic_preferences/sections.html

curlyprint complains:

aleksis/core/templates/dynamic_preferences/sections.html
12:2    Parse error: expected 'li' at 12:2      parse_error

It shows similar errors for other templates, but this is a very simple one.

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

"parse", mainly.

Environment

I am not sure what Draft.js has to do with this, neither what relevance my browser has to do with it, as I run curlylint on the shell.

I use curlylint 0.12.0 from PyPI under Python 3.9 on Debian bullseye/sid.

Steps to reproduce

  1. pip3 install curlylint
  2. wget https://edugit.org/AlekSIS/official/AlekSIS-Core/-/raw/d579eec21675787347c7e7d4c2862d9d75030b0a/aleksis/core/templates/dynamic_preferences/sections.html
  3. curlylint sections.html

Expected behavior

Template is lint-clean.

Actual behavior

curlylint throws above parse error.

Reproducible demo

{% load i18n %}
<ul class="tabs">
  <li class="tab ">
    {% for section in registry.section_objects.values %}
      <li class="tab">
        <a class="{% if active_section == section.name %}active{% endif %}"
           href="{% url registry_url section.name %}"
           target="_self">
          {{ section.verbose_name }}
        </a>
      </li>
    {% endfor %}
</ul>
thibaudcolas commented 3 years ago

Hey @Natureshadow, thank you for the detailed report!

Draft.js has nothing to do with this :) I just forgot to change that part of the issue template when setting up the repository.

Looking at your example, this looks like it might just be due to the extra li on line 3?

{% load i18n %}
<ul class="tabs">
-  <li class="tab ">
    {% for section in registry.section_objects.values %}
      <li class="tab">
        <a class="{% if active_section == section.name %}active{% endif %}"
           href="{% url registry_url section.name %}"
           target="_self">
          {{ section.verbose_name }}
        </a>
      </li>
    {% endfor %}
</ul>

The parser is quite strict and will fail on templates that have mismatched start and end tags, which is usually what you want, but makes for cryptic error messages.

Natureshadow commented 3 years ago

Oh dear. You are absolutely correct. I was focused too much on what the error explicitly said.

Sorry for the noise ;)!

thibaudcolas commented 3 years ago

Great, no problem at all.