Skip to content

Commit

Permalink
fix(formatter): fix extra parenth being added in a function call
Browse files Browse the repository at this point in the history
closes #660
  • Loading branch information
christopherpickering committed May 22, 2023
1 parent 5f35e75 commit faba4f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/djlint/formatter/indent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions tests/test_nunjucks/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
({}),
id="set",
),
pytest.param(
("<li>{{ foo(1,2) }}</li>"),
("<li>{{ foo(1, 2) }}</li>\n"),
({}),
id="don't add parenth to lists",
),
]


Expand Down

0 comments on commit faba4f4

Please sign in to comment.