djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang

Home Page:https://djLint.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] [Linter] T003 should not require a name for endblock on same line

katzmo opened this issue · comments

System Info

  • OS: Debian 11.5
  • Python Version 3.9.2
  • djLint Version 1.34.0
  • template language: django

Issue

T003 requires all endblocks to have a name, even if they are on the same line as the block start. That makes it impossible to add empty blocks (or blocks with very little content) in a single line, because although the formatter would put {% block myblock %}{% endblock %} on one line, it requires a linebreak for a named endblock.

To me the formatter behavior seems sensible, I think the T003 rule should not require a name for single line blocks.

Comparison

Curently impossible:

{% block title %}{% endblock %}
{% block content %}{% endblock %}

Currently enforced (and IMHO harder to read):

{% block title %}
{% endblock title %}
{% block content %}
{% endblock content %}

How To Reproduce

  1. In a Django template, add {% block myblock %}{% endblock %}
  2. Run djlint --check → fine
  3. Run djlint→ it will trigger "T003: Endblock should have name"
  4. Fix T003 by changing the line to {% block myblock %}{% endblock myblock %}
  5. Run djlint → fine
  6. Run djlint --check → it want's to reformat the block into 2 lines

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

profile = "django"

Thanks for opening your first issue here!