djlint / djLint

✨ HTML Template Linter and Formatter. Django - Jinja - Nunjucks - Handlebars - GoLang
https://djLint.com
GNU General Public License v3.0
714 stars 85 forks source link

[BUG] [Formatter] Replaces kwargs with empty {} #1030

Open Diegovsky opened 5 days ago

Diegovsky commented 5 days ago

System Info

Issue

Djlint replaces kwargs with empty {} inside macro definitions.

How To Reproduce

Here's a sample from our source code:

{% macro _expand_attrs(attrs) %}
    {% for attr, val in attrs.items() -%}{{ attr }}="{{ val }}"{% endfor %}
{% endmacro %}

{% macro button(text, _tag="button", class="") %}
    <{{- _tag }} class="p-[10px] bg-[#FF7A00] rounded-[8px] text-white
    transition duration-150 transition-color disabled:opacity-50 {{class}}" {{ _expand_attrs(kwargs) }}>
    {% if caller is defined %}
        {{ caller() }}
    {% else %}
        {{ text }}
    {% endif %}
    </{{- _tag -}}>
{% endmacro %}

{% macro link_button(text, href='') %}
    {{ button(text, type="link", _="on click go to url '"~href~"'", **kwargs) }}
{% endmacro %}

Upoon formatting with djlint, it replaces kwargs uses with {}

oliverhaas commented 4 days ago

Using the online djlint formatter, I can't reproduce the issue.

Which "kwarg" do you mean? Both "kwargs"?

Do you have any other settings?

Diegovsky commented 3 days ago

Hey there, thanks for the fast response :)

I meant every kwargs use was replaced with an empty dict. Both in link_button and in button.

I haven't tried the web formatter, but it is occourring in the CLI. I'm not sure if this is relevant, but my file extension is .html.j2.