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] {% set var_name = { ... } %} multiline object property indentation don't seem to work properly #836

Open
3 tasks done
asolopovas opened this issue Jun 6, 2024 · 1 comment
Labels
🦠 bug Something isn't working 🧽 formatter

Comments

@asolopovas
Copy link

asolopovas commented Jun 6, 2024

System Info

  • OS: Ubuntu 22.04.4 LTS WSL
  • Python Version (python --version) === 3.10.14
  • djLint Version (djlint --version) === 1.34.1
  • template language: twig

Issue

Is it normal to have closing } %} be hanging in the middle of the line?

{#  16 ... #}   <a class="{{ itemLinkClass | default("block-link") }}"
                   href="{{ item.link }}"
                   title="Link to {{ item.title }}">
                   {#  Property Indentation from parent   24 ...    #}
                    {% set image_params = {
                                            image: item.image,
                                            imageClass: imageClass,
                                            caption: settings.pictureTag ? item.title : false,
                                            captionClass: captionClass,
                                            lazy: loop.first ? settings.firstLazy : true
                                        } %}
                    {% include "image-block.twig" with  image_params %}
                </a>

isn't it looking better this way?

{#  16 ... #}   <a class="{{ itemLinkClass | default("block-link") }}"
                   href="{{ item.link }}"
                   title="Link to {{ item.title }}">
                    {# Property Indentation from parent 4 ... #}
                    {% set image_params = {
                        image: item.image,
                        imageClass: imageClass,
                        caption: settings.pictureTag ? item.title : false,
                        captionClass: captionClass,
                        lazy: loop.first ? settings.firstLazy : true
                    } %}
                    {% include "image-block.twig" with  image_params %}
                </a>

Please note that I indented the anchor tag <a specifically by 16 spaces to demonstrate that spacing added to indent properties is not event depending on how far the parent is indented, further indentation of parent nesting, results in further indentation of all of the object. In first example above object properties got indented by 24 spaces from line above {% set.

If tag is located at root indentation like bellow:

<a class="{{ itemLinkClass | default("block-link") }}"
   href="{{ item.link }}"
   title="Link to {{ item.title }}">
    {# Property Indentation from Parent 8 ... #}
    {# Closing Tag %} Indentation 8 ... #}
    {% set image_params = {
            image: item.image,
            imageClass: imageClass,
            caption: settings.pictureTag ? item.title : false,
            captionClass: captionClass,
            lazy: loop.first ? settings.firstLazy : true
         } %}
    {% include "image-block.twig" with  image_params %}
</a>

it indents object properties by 8 spaces instead of required indentation of 4

<a class="{{ itemLinkClass | default("block-link") }}"
   href="{{ item.link }}"
   title="Link to {{ item.title }}">
   {# Property Indentation from Parent 4 ... #}
   {# Closing Tag %} Indentation 0 ... #}
    {% set image_params = {
        image: item.image,
        imageClass: imageClass,
        caption: settings.pictureTag ? item.title : false,
        captionClass: captionClass,
        lazy: loop.first ? settings.firstLazy : true
    } %}
    {% include "image-block.twig" with  image_params %}
</a>
@asolopovas asolopovas added 🦠 bug Something isn't working 🧽 formatter labels Jun 6, 2024
@anentropic
Copy link

I have some examples like:

        {% set item_kwargs = {
                  "label": label,
                  "disabled": item.disabled,
                  "selected": item.selected,
                  "two_line": two_line,
                  "callback": callback,
                  "item_attrs": item_attrs,
                  "first_unselected": (_parent and loop.first and none_selected)
                } %}
        {% if _checkboxes_name %}
          {% do item_kwargs.update({
          "checkbox_kwargs": {
          "name": _checkboxes_name,
          "value": item.value,
          "id": _checkboxes_name + "--id-" + loop.index|str,
          }
          }) %}

the indentation djlint is enforcing here seems quick wacky and inconsistent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🦠 bug Something isn't working 🧽 formatter
Projects
None yet
Development

No branches or pull requests

2 participants