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] Incorrect formatting on function index #693

Closed
3 tasks done
nrnvgh opened this issue Jun 14, 2023 · 2 comments
Closed
3 tasks done

[BUG] [Formatter] Incorrect formatting on function index #693

nrnvgh opened this issue Jun 14, 2023 · 2 comments
Labels

Comments

@nrnvgh
Copy link

nrnvgh commented Jun 14, 2023

System Info

  • OS: OSX 13.2.1
  • Python Version: 3.10.11, 3.11.3
  • djLint Version 1.31.0
  • template language: jinja

Issue

Formatter inserts space when directly indexing a list returned by a function. To wit:

djlint --check --profile=jinja templates/list_element.j2

Checking 1/1 files ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 00:00


templates/list_element.j2
────────────────────────────────────────────────────
@@ -1,6 +1,5 @@

 {% set item_list = ["1", "4", "9"] %}
 * Item: {{ item_list[2] }}
-
 {% set item = item_list[2] + "/cidr_thing" %}
-New Val[1]: {{ item.split("/")[1] }}
-New Val.1: {{ item.split("/").1 }}
+New Val[1]: {{ item.split("/") [1] }}  <== This
+New Val.1: {{ item.split("/") .1 }}.    <== And also this

1 file would be updated.

This doesn't break rendering, but djlint's behavior seem wrong to me; foo.function(args)[index] is, as far as I know, a valid construct.

How To Reproduce

Script:

#!/usr/bin/env python3

import sys
import argparse

import jinja2


def handle_arguments():
    parser = argparse.ArgumentParser()
    parser.add_argument('template')

    return parser.parse_args()


def main(args: argparse.Namespace):
    template = jinja2.Environment(
        loader=jinja2.FileSystemLoader("templates"),
        trim_blocks=True,
        lstrip_blocks=True,
    ).get_template(args.template)

    print(template.render())

if __name__ == '__main__':
    parsed_args = handle_arguments()

    sys.exit(main(parsed_args))

Template:

{% set item_list = ["1", "4", "9"] %}
* Item: {{ item_list[2] }}

{% set item = item_list[2] + "/cidr_thing" %}
New Val[1]: {{ item.split("/")[1] }}
New Val.1: {{ item.split("/").1 }}
@nrnvgh nrnvgh added 🦠 bug Something isn't working 🧽 formatter labels Jun 14, 2023
@christopherpickering christopherpickering changed the title [BUG] [Formatter] [BUG] [Formatter] Incorrect formatting on function index Jun 14, 2023
christopherpickering pushed a commit that referenced this issue Jun 26, 2023
## [1.31.1](v1.31.0...v1.31.1) (2023-06-26)

### Bug Fixes

* **formatter:** fixed formatter formatting ignored code ([5c75d87](5c75d87)), closes [#655](#655)
* **formatter:** fixed function formatting with nested quoted parenthesis ([6d63a6a](6d63a6a)), closes [#698](#698)
* **formatter:** fixed overgrabbing on template tag condensing ([75c3134](75c3134)), closes [#686](#686)
* **formatter:** function index was not formatted correctly ([a197200](a197200)), closes [#693](#693)
@christopherpickering
Copy link
Contributor

🎉 This issue has been resolved in version 1.31.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@nrnvgh
Copy link
Author

nrnvgh commented Jun 26, 2023

Confirmed on this end; thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants