Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] [Linter] false positives for orphan tags when django templating is used #874

Open
3 tasks done
thacoon opened this issue Jul 25, 2024 · 0 comments
Open
3 tasks done
Labels
🔍 linter 🦠 bug Something isn't working

Comments

@thacoon
Copy link

thacoon commented Jul 25, 2024

System Info

  • OS: macOS Sonoma
  • Python Version 3.11.9
  • djLint Version 1.34.1
  • template language: django default templating language

Issue

djlint reports false positives orphan tags for a snippet in which django templating is used. If I remove the django templating no more orphan tags are reported.

How To Reproduce

Detects two orphan tags for this snippet:

{% load tailwind_filters %}

<div class="relative flex items-center">
  <div class="flex h-6 items-center">
    <input id="{{ field.id_for_label }}" name="{{ field.html_name }}" {% if field.value %}checked{% endif %} type="checkbox" class="h-5 w-5 rounded border-gray-300 text-primary-black focus:ring-primary-black" {{ field|build_attrs }} />
  </div>
  <label for="{{ field.id_for_label }}" class="ml-3 text-sm font-normal text-typography-default">
    {{ field.label|safe }}
    {% if field.field.required %}<span>*</span>{% endif %}
  </label>
</div>

For this snippet it displays the following error:

H025 3:0 Tag seems to be an orphan. <div class="relative
H025 11:2 Tag seems to be an orphan. </label>

No orphan tags are reported when django templating is not used:

<div class="relative flex items-center">
  <div class="flex h-6 items-center">
    <input type="checkbox" class="h-5 w-5 rounded border-gray-300 text-primary-black focus:ring-primary-black" />
  </div>
  <label class="ml-3 text-sm font-normal text-typography-default">
    Label
    <span>*</span>
  </label>
</div>

Contents of .djlintrc/pyproject.toml [tool.djlint]

[tool.djlint]
ignore = "H006,H030,H031"
include = "H017,H035"
indent = 2
blank_line_after_tag = "load,extends"
profile = "django"
max_line_length = 120
format_attrite_template_tags = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔍 linter 🦠 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant