From faba4f488df998abd6a042aaadd8006ac0d4cf7a Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 22 May 2023 09:36:51 -0500 Subject: [PATCH] fix(formatter): fix extra parenth being added in a function call closes #660 --- src/djlint/formatter/indent.py | 9 ++++++++- tests/test_nunjucks/test_set.py | 6 ++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/djlint/formatter/indent.py b/src/djlint/formatter/indent.py index c6fde824..a062f08d 100644 --- a/src/djlint/formatter/indent.py +++ b/src/djlint/formatter/indent.py @@ -337,9 +337,16 @@ def format_data(config: Config, contents: str, tag_size: int, leading_space) -> except: # was not json.. try to eval as set try: - contents = str(eval(contents)) + evaluated = str(eval(contents)) + # need to unwrap the eval + contents = ( + evaluated[1:-1] + if contents[:1] != "(" and evaluated[:1] == "(" + else evaluated + ) except: contents = contents.strip() + return (f"\n{leading_space}").join(contents.splitlines()) def format_set(config: Config, html: str, match: re.Match) -> str: diff --git a/tests/test_nunjucks/test_set.py b/tests/test_nunjucks/test_set.py index 4e92a6b2..d8abfecb 100644 --- a/tests/test_nunjucks/test_set.py +++ b/tests/test_nunjucks/test_set.py @@ -163,6 +163,12 @@ ({}), id="set", ), + pytest.param( + ("
  • {{ foo(1,2) }}
  • "), + ("
  • {{ foo(1, 2) }}
  • \n"), + ({}), + id="don't add parenth to lists", + ), ]