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] Inconsistent formatting of multi-line function calls #805

Open GPla opened 9 months ago

GPla commented 9 months ago

System Info

Issue

There are two problems when splitting a function call inside an expression to multiple lines:

  1. The arguments are indented to the same level as the expression relative to the {{. Strangely, this behavior is affected by comments (maybe other things) above the expression, but this is inconsistent. When this happens, then everything will only be indented to the first level relative to {{.
  2. Calling another function as part of a function call adds a space behind the function and resets the indentation level for arguments below it.

How To Reproduce

Create a issue.html.jinja2 and set indentation to spaces: 2.

{{ render_partial('components/button.html.jinja2',
content='Press me!',
color='forest-green',
icon=render_partial('components/icon.html.jinja2', icon='icon') ,
some_other_arg='my indentation is reset') }}

<div>
  {{ render_partial('components/button.html.jinja2',
    content='Press me!',
    color='forest-green',
    icon=render_partial('components/icon.html.jinja2', icon='icon') ,
  some_other_arg='my indentation is reset') }}
</div>

<div>
  <div>
    {{ render_partial('components/button.html.jinja2',
        content='Press me!',
        color='forest-green',
        icon=render_partial('components/icon.html.jinja2', icon='icon') ,
    some_other_arg='my indentation is reset') }}
  </div>
</div>