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] line_break_after_multiline_tag not always breaking as expected #680

Closed
3 tasks done
malo-malo opened this issue Jun 2, 2023 · 5 comments
Closed
3 tasks done
Labels

Comments

@malo-malo
Copy link

malo-malo commented Jun 2, 2023

System Info

  • OS: ubuntu 20.04
  • Python Version 3.8.10
  • djLint Version 1.30.0
  • template language: django templates

Issue

Hi ! I'm trying the new line_break_after_multiline_tag=true option, which is pretty nice.

I have run into a difference in behaviour depending on tags, and was wondering if all could behave alike (like the div in the following example). I have noticed this mostly on <a> tags.

How To Reproduce

Here is the initial situation, I would expect it to remain identical after reformatting

<div class="ds-flex ds-items-center ds-justify-center"
     style="grid-column: 3/4">
    {{ here_is_a_long_variable }}
</div>
<span class="ds-flex ds-items-center ds-justify-center"
      style="grid-column: 3/4">
    {{ here_is_a_long_variable }}
</span>

After reformating, the span gets condensed on one line, whereas the div does not :

<div class="ds-flex ds-items-center ds-justify-center"
     style="grid-column: 3/4">
    {{ here_is_a_long_variable }}
</div>
<span class="ds-flex ds-items-center ds-justify-center"
      style="grid-column: 3/4">{{ here_is_a_long_variable }}</span>
@malo-malo malo-malo added 🦠 bug Something isn't working 🧽 formatter labels Jun 2, 2023
@christopherpickering
Copy link
Contributor

Thanks :) What is your config? With the default options it seems to work as expected.

@malo-malo
Copy link
Author

Here is my current config :

[tool.djlint]
require_pragma = true
profile = "django"
custom_blocks = "stage, cache, flatblock, section, csp_compress"
ignore_blocks = "set_global_context"
custom_html = "..."
blank_line_after_tag = "extends, endblock"
max_line_length = 120
line_break_after_multiline_tag = true
ignore = "H021,H023,H030,H031"

I've just tested again and span might not be the correct example (although I'm pretty sure it did not work an hour ago ...), with an a tag however I am able to reproduce :

<a class="ds-flex ds-items-center ds-justify-center"
   style="grid-column: 3/4">
    {{ here_is_a_long_variable }}
</a>

becomes

<a class="ds-flex ds-items-center ds-justify-center"
   style="grid-column: 3/4">{{ here_is_a_long_variable }}</a>

@christopherpickering
Copy link
Contributor

christopherpickering commented Jun 2, 2023

Thanks, I see what is going on now. I updated the online demo so we can run there:

image

image

In the code, we are still condensing if the sum of the parts is less than your max line length.
image

It is a bit confusing and not exactly following the name of the flag.

We should probably update it so that if there is a break inside the tag then we ALWAYS break the tag contents as you were execting.

@christopherpickering christopherpickering changed the title [BUG] [Formatter] [BUG] [Formatter] line_break_after_multiline_tag not always breaking as expected Jun 2, 2023
@malo-malo
Copy link
Author

Thanks for the detailed explanation, always breaking the tag content does sound good to me. And thank you for updating the online demo !

christopherpickering pushed a commit that referenced this issue Jun 12, 2023
# [1.31.0](v1.30.2...v1.31.0) (2023-06-12)

### Bug Fixes

* **formatter:** fixed `line_break_after_multiline_tag` to force break in all cases ([3b37ec8](3b37ec8)), closes [#680](#680)
* **formatter:** fixed isolated quotes being deleted from attributes ([19425f9](19425f9)), closes [#652](#652)
* **formatter:** fixed wild match on template tags ([d288b78](d288b78)), closes [#686](#686)
* **linter:** fixed false positive on t001 ([1caf4c4](1caf4c4)), closes [#606](#606)

### Features

* **formatter:** added `max-blank-lines` flag to consolidate blank lines ([4a7897f](4a7897f)), closes [#675](#675)
* **formatter:** added support for symphony forms ([e716ddc](e716ddc)), closes [#476](#476)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.31.0 🎉

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