Skip to content

Commit

Permalink
added formatter support to trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
AshishMahendra committed Sep 25, 2024
1 parent f94c39a commit 0308a01
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion jac/jaclang/compiler/passes/tool/jac_formatter_pass.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ def exit_func_call(self, node: ast.FuncCall) -> None:
indented = True
for count, j in enumerate(i.kid):
if j.gen.jac == ",":
if i.kid[count + 1].gen.jac.startswith("#"):
if len(i.kid) > count + 1 and i.kid[
count + 1
].gen.jac.startswith("#"):
self.indent_level -= 1
self.emit(node, f"{j.gen.jac} ")
self.indent_level += 1
Expand Down
8 changes: 4 additions & 4 deletions jac/jaclang/tests/fixtures/trailing_comma.jac
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ with entry {
tuple_2_2 = ("foo", "bar", "baz", );

foo_instance1 = foo11(val=90);
foo_instance1_2 = foo11(val=90,); # TODO: FORMATTER: trailing comma is not supported
foo_instance1_2 = foo11(val=90, );

foo_instance3 = foo11(2, 34, val3=90);
foo_instance3_2 = foo11(2,34,val3=90,); # TODO: FORMATTER: trailing comma is not supported
foo_instance3_2 = foo11(2, 34, val3=90, );

foo_instance4 = foo11(2, 34,val3=90, val4=90);
foo_instance4_2 = foo11(2, 34,val3=90, val4=90,); # TODO: FORMATTER: trailing comma is not supported
foo_instance4 = foo11(2, 34, val3=90, val4=90);
foo_instance4_2 = foo11(2, 34, val3=90, val4=90, );

func_tuple = (foo_instance1, foo_instance3_2, len(tuple1_2));
func_tuple_with_trail_comma = (foo_instance1, foo_instance3_2, len(tuple1_2), );
Expand Down

0 comments on commit 0308a01

Please sign in to comment.