From 703e2626dd7afc5d4c729c11808b6c720010c0af Mon Sep 17 00:00:00 2001 From: Gregor Niehl Date: Sat, 4 Nov 2023 13:51:22 +0100 Subject: [PATCH] Formatter: Close empty objects on same line --- blueprintcompiler/formatter.py | 3 +++ tests/formatting/correct1.blp | 9 +++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/blueprintcompiler/formatter.py b/blueprintcompiler/formatter.py index 0f09679..c907adb 100644 --- a/blueprintcompiler/formatter.py +++ b/blueprintcompiler/formatter.py @@ -153,6 +153,9 @@ class Formatter: current_line = current_line[:-1] commit_current_line() current_line = "]" + elif str(last_not_whitespace) in OPENING_TOKENS: + end_str = end_str.strip() + commit_current_line(LineType.BLOCK_CLOSE, True, 0) indent_levels -= 1 commit_current_line(LineType.BLOCK_CLOSE, True) diff --git a/tests/formatting/correct1.blp b/tests/formatting/correct1.blp index 2cb4f23..42d55fa 100644 --- a/tests/formatting/correct1.blp +++ b/tests/formatting/correct1.blp @@ -20,12 +20,10 @@ template $MyTemplate: Label { flags: a | b; [child] - Label { - } + Label {} [child] - Label label2 { - } + Label label2 {} // Single line comment. @@ -40,8 +38,7 @@ template $MyTemplate: Label { Dialog { [action response=ok] - $MyButton { - } + $MyButton {} } menu menu {