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

Support for self closing tags (HTML / XML) #84

Closed flochtililoch closed 2 years ago

flochtililoch commented 3 years ago

Describe the bug

Self closing tags which are valid HTML/XML are throwing off the linter.

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

self closing tag

Environment

Steps to reproduce

(Write your steps here:)

  1. First, create a file named my.xml with the following content
    <foo>
      <bar />
    </foo>
  2. Then, run the linter with the following command
    curlylint my.xml --rule 'indent: 2'

Expected behavior

All done! ✨ 🍰 ✨

Actual behavior

my.xml
1:7 Parse error: expected one of '>', 'attribute', '{#', '{%', '{{' at 1:7  parse_error

To be noted, if you change the file content to:

<foo>
  <bar></bar>
</foo>

the linter won't report any error (as expected).

flochtililoch commented 3 years ago

After diving into the code base, I see that self closing tags are supported / implemented, but that they are whitelisted, mostly to support SVGs and the few valid HTML ones. I wonder if if would be beneficial to allow adding more to the whitelist by configuration, or just having a config flag that allows any XML tag to be self closing.

williamjmorenor commented 2 years ago

I think I hit this same issue

       <div class="text-center">
            <p>{{ cursos.total }} cursos disponibles.
                <br>
                {% if cursos.has_prev %}
                <a class="link-dark" href="{{ url_for("home", page=cursos.prev_num) }}" <i
                    class="bi bi-arrow-left-short" aria-hidden="true"></i>
                    Anterior
                </a>
                {% endif %}
                Página {{ cursos.page }} de {{ cursos.pages }}
                {% if cursos.has_next %}
                <a class="link-dark" href="{{ url_for("home", page=cursos.next_num) }}">Siguiente <i
                        class="bi bi-arrow-right-short" aria-hidden="true"></i></a>
                {% endif %}
            </p>
        </div>

This report a error but the sintax is ok

←[4mnow_lms\templates\inicio\mooc.html←[0m
←[2m120:88←[0m  Parse error: expected one of '>', 'attribute', '{#', '{%', '{{' at 120:88       parse_error

And render as expected

image

I want to run curlylint as part of CI but I can not fix this issue with <br></br> because this is not valid html

flochtililoch commented 2 years ago

I think I hit this same issue

From the snippet you pasted, there's a missing > line 5:

...cursos.prev_num) }}" <i

should be

...cursos.prev_num) }}"><i
adamchainz commented 2 years ago

curlylint describes itself as an HTML linter. I don't think it's intended that you can lint XML files with it. That is quite a different problem since XML has many other features...