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

Handling <!doctype html> #86

Open PaulMarcantonio opened 2 years ago

PaulMarcantonio commented 2 years ago

Describe the bug

When running curlylint on a basic html template I noticed that the "<!doctype html>" was causing false positive Bad indentation and parent inline element issues. Once I commented out the "<!doctype html>" all tests passed.

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

"<!doctype html>" Notices other blogs were taking the same steps I did

https://github.com/motet-a/jinjalint/issues/16

Environment

Windows 2012R2 Curlylint ver => 0.13.0 Python ver 3.7.6

Steps to reproduce

(Write your steps here:)

  1. create a simple html doc with <!doctype html> tag
  2. add some html items
  3. test with tag in place then with out

Expected behavior

You should see different results based on the state of the <!doctype html> tag

Actual behavior

Scotchester commented 2 years ago

I think I may have just run into the same (or a related) issue.

I wanted to comment my Django load tags to keep track of what they were, like so:

{% load static %} {# Django #}
{% load wagtailsettings_tags wagtailuserbar %} {# Wagtail #}
{% load compress %} {# Third-party #}
{% load custom_filters django_setting feature_flags %} {# Custom #}
{% get_settings %} {# make Wagtail settings objects available in the template #}

<!DOCTYPE html>

Adding the comments seen above triggered the "An inline parent element must only contain inline children" error on the DOCTYPE line and a whole slew of "Bad indentation" errors throughout the rest of the file. I tried with and without a space between the tag and the comment, and tried the comments before and after the tags. Same results each time.

Simply moving them under the DOCTYPE fixed the curlylint errors, like so:

<!DOCTYPE html>
{% load static %} {# Django #}
{% load wagtailsettings_tags wagtailuserbar %} {# Wagtail #}
{% load compress %} {# Third-party #}
{% load custom_filters django_setting feature_flags %} {# Custom #}
{% get_settings %} {# make Wagtail settings objects available in the template #}