diff options
| author | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-15 21:59:08 -0400 |
|---|---|---|
| committer | Brad Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-08-15 21:59:08 -0400 |
| commit | a27c05b4415fa8b8eee10c134e8be6af6bbc9909 (patch) | |
| tree | 1a2b32c62fdd04e3b1246ce639dccd2ce27b7a3d | |
| parent | 3b71481c7b2583dcdca3ca9fd9fcc8e0de22f62b (diff) | |
Remove trailing whitespace when using Allman style braces
| -rw-r--r-- | src/odin/printer/document.odin | 4 | ||||
| -rw-r--r-- | tools/odinfmt/tests/allman/.snapshots/switch.odin | 6 | ||||
| -rw-r--r-- | tools/odinfmt/tests/allman/.snapshots/when.odin | 4 |
3 files changed, 9 insertions, 5 deletions
diff --git a/src/odin/printer/document.odin b/src/odin/printer/document.odin index 5fdec78..f3ef61e 100644 --- a/src/odin/printer/document.odin +++ b/src/odin/printer/document.odin @@ -446,6 +446,10 @@ format :: proc(width: int, list: ^[dynamic]Tuple, builder: ^strings.Builder, p: case Document_Newline: if v.amount > 0 { flush_line_suffix(builder, &suffix_builder) + // ensure we strip any misplaced trailing whitespace + for builder.buf[len(builder.buf)-1] == ' ' { + pop(&builder.buf) + } for i := 0; i < v.amount; i += 1 { strings.write_string(builder, p.newline) } diff --git a/tools/odinfmt/tests/allman/.snapshots/switch.odin b/tools/odinfmt/tests/allman/.snapshots/switch.odin index 10f6faf..9e73da7 100644 --- a/tools/odinfmt/tests/allman/.snapshots/switch.odin +++ b/tools/odinfmt/tests/allman/.snapshots/switch.odin @@ -1,16 +1,16 @@ package allman -main :: proc() +main :: proc() { num := 1 - switch num + switch num { case 0: case 1: } - switch num + switch num { case 0: case 1: diff --git a/tools/odinfmt/tests/allman/.snapshots/when.odin b/tools/odinfmt/tests/allman/.snapshots/when.odin index f34307f..1f489a3 100644 --- a/tools/odinfmt/tests/allman/.snapshots/when.odin +++ b/tools/odinfmt/tests/allman/.snapshots/when.odin @@ -1,10 +1,10 @@ package allman -main :: proc() +main :: proc() { TEST_BOOL := false - when TEST_BOOL + when TEST_BOOL { } } |