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] [Formatter] Long lines inside moderately complex logic appears to confuse djLint, causing it to outdent closing tags. #398

Closed
3 tasks done
craiga opened this issue Sep 20, 2022 · 2 comments
Labels

Comments

@craiga
Copy link

craiga commented Sep 20, 2022

System Info

  • OS: macOS Monterey 12.5.1
  • Python Version: Python 3.10.5
  • djLint Version: djlint, version 1.17.0
  • template language: Django

Issue

Long lines inside moderately complex logic appears to confuse djLint, causing it to outdent closing tags.

How To Reproduce

Given this users/templates/users/password-strength.html

{% if password_strength or crack_time_display %}
    {% if password_strength %}
        Your password strength: <span class="password-strength--{{ password_strength|slugify }}">{{ password_strength|capfirst }}</span>
    {% endif %}
    {% if crack_time_display %}
        Estimated time to crack: <span class="password-strength--crack-time">{{ crack_time_display|capfirst }}</span>
    {% endif %}
{% endif %}

…when I run…

djlint --profile django --reformat users/templates/users/password-strength.html

…the file is reformatted as…

{% if password_strength or crack_time_display %}
    {% if password_strength %}
    Your password strength: <span class="password-strength--{{ password_strength|slugify }}">{{ password_strength|capfirst }}</span>
{% endif %}
{% if crack_time_display %}
Estimated time to crack: <span class="password-strength--crack-time">{{ crack_time_display|capfirst }}</span>
{% endif %}
{% endif %}
@craiga craiga added 🦠 bug Something isn't working 🧽 formatter labels Sep 20, 2022
@craiga
Copy link
Author

craiga commented Sep 20, 2022

FWIW, breaking long lines up a bit works around this issue. Once broken up, the template is formatted as you'd expect:

{% if password_strength or crack_time_display %}
    {% if password_strength %}
        Your password strength:
        <span class="password-strength--{{ password_strength|slugify }}">{{ password_strength|capfirst }}</span>
    {% endif %}
    {% if crack_time_display %}
        Estimated time to crack:
        <span class="password-strength--crack-time">{{ crack_time_display|capfirst }}</span>
    {% endif %}
{% endif %}

christopherpickering pushed a commit that referenced this issue Sep 21, 2022
## [1.17.1](v1.17.0...v1.17.1) (2022-09-21)

### Bug Fixes

* **formatter:** fixed poor indentation on span tags with leading text ([8f36fec](8f36fec)), closes [#398](#398)
* **t002:** fixed false positive in t002. Added test ([e23ee46](e23ee46)), closes [#399](#399)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.17.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants