djLint icon indicating copy to clipboard operation
djLint copied to clipboard

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

Open Sahabial opened this issue 1 year ago • 0 comments

System Info

  • OS: windown 10
  • Python Version (3.12.1)
  • djLint Version (1.34.1)
  • template language: nunjucks

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>

Sahabial avatar Jan 25 '24 23:01 Sahabial