djlint / djLint

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

[BUG] [Formatter] Nunjucks function expressions have incorrect indent #808

Open Sahabial opened 8 months ago

Sahabial commented 8 months ago

System Info

Issue

I get incorrect indentations in {{ }} expression when formatting njk files with djlint. The only workaround I have for now is keep preserve_leading_space to true but i actually want them to be formatted as well.

I also tried online version and got the same result.

Don't know is it something with my config or with djlint. Please help. Looks like this is the only solution for now to format nunjucks templates.

How To Reproduce

.djlintrc:

{
  "extension": "njk",
  "profile": "nunjucks",
  "indent": 4,
  "no_function_formatting": false,
  "preserve_leading_space": false
}

command: djlint ./src --reformat --configuration .djlintrc

sample input:

<div>
    {% if apos %}
        {{ apos.singleton(data.global, "footerHead", 'apostrophe-rich-text', {
            toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink' ],
            styles: [
                {
                    name: 'footerHead',
                    element: 'div',
                    attributes: { class: 'footer--title-main'}
                }
            ]
        }) }}
    {% endif %}
</div>
<div>
    {{ funct({
        test: 'best',
                jest: 'test',
        fest: 'pest'}) }}
</div>

output:

<div>
    {% if apos %}
        {{ apos.singleton(data.global, "footerHead", 'apostrophe-rich-text', {
                toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink' ],
                styles: [
                {
                name: 'footerHead',
                element: 'div',
                attributes: { class: 'footer--title-main'}
                }
                ]
                }) }}
    {% endif %}
</div>
<div>{{ funct({"test": "best", "jest": "test", "fest": "pest"}) }}</div>