1717 TupleRule ,
1818)
1919from hcl2 .rules .expressions import ExprTermRule
20+ from hcl2 .rules .functions import FunctionCallRule
2021from hcl2 .rules .for_expressions import (
2122 ForTupleExprRule ,
2223 ForObjectExprRule ,
@@ -33,7 +34,7 @@ class FormatterOptions:
3334
3435 indent_length : int = 2
3536 open_empty_blocks : bool = True
36- open_empty_objects : bool = True
37+ open_empty_objects : bool = False
3738 open_empty_tuples : bool = False
3839
3940 vertically_align_attributes : bool = True
@@ -125,6 +126,10 @@ def format_tuple_rule(self, rule: TupleRule, indent_level: int = 0):
125126 if isinstance (child , (COMMA , LSQB )): # type: ignore[misc]
126127 new_children .append (self ._build_newline (indent_level ))
127128
129+ # If no trailing comma, add newline before closing bracket
130+ if not isinstance (new_children [- 2 ], NewLineOrCommentRule ):
131+ new_children .insert (- 1 , self ._build_newline (indent_level ))
132+
128133 self ._deindent_last_line ()
129134 self ._set_children (rule , new_children )
130135
@@ -175,9 +180,19 @@ def format_expression(self, rule: ExprTermRule, indent_level: int = 0):
175180 elif isinstance (rule .expression , ForObjectExprRule ):
176181 self .format_forobjectexpr (rule .expression , indent_level )
177182
183+ elif isinstance (rule .expression , FunctionCallRule ):
184+ self .format_function_call (rule .expression , indent_level )
185+
178186 elif isinstance (rule .expression , ExprTermRule ):
179187 self .format_expression (rule .expression , indent_level )
180188
189+ def format_function_call (self , rule : FunctionCallRule , indent_level : int = 0 ):
190+ """Format a function call by recursively formatting its arguments."""
191+ if rule .arguments is not None :
192+ for arg in rule .arguments .arguments :
193+ if isinstance (arg , ExprTermRule ):
194+ self .format_expression (arg , indent_level )
195+
181196 def format_fortupleexpr (self , expression : ForTupleExprRule , indent_level : int = 0 ):
182197 """Format a for-tuple expression with newlines around clauses."""
183198 for child in expression .children :
0 commit comments