From 9d049de6d838a00a50ddbdff8bb7e8d9caf697a6 Mon Sep 17 00:00:00 2001 From: mertcandav Date: Sun, 24 Mar 2024 05:31:07 +0300 Subject: [PATCH] julefmt: improve conditional formatting --- src/format.jule | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/format.jule b/src/format.jule index 7beea03..64acf80 100644 --- a/src/format.jule +++ b/src/format.jule @@ -790,8 +790,14 @@ impl ScopeFormatter { fn conditional_case(self, mut c: &ast::If) { self.write("if ") self.fmt.format_expr(c.expr) - self.write(" ") - self.format(c.scope) + self.write(" {\n") + if c.scope.stmts.len > 0 { + self.fmt.add_indent() + self.format_stmts(c.scope.stmts) + self.fmt.done_indent() + } + self.write(self.fmt.indent) + self.write("}") } fn conditional(self, mut c: &ast::Conditional) { @@ -801,8 +807,14 @@ impl ScopeFormatter { self.conditional_case(t) } if c.default != nil { - self.write(" else ") - self.format(c.default.scope) + self.write(" else {\n") + if c.default.scope.stmts.len > 0 { + self.fmt.add_indent() + self.format_stmts(c.default.scope.stmts) + self.fmt.done_indent() + } + self.write(self.fmt.indent) + self.write("}") } }