diff --git a/std/zig/parser_test.zig b/std/zig/parser_test.zig index bc50b8ab87..3be6b88063 100644 --- a/std/zig/parser_test.zig +++ b/std/zig/parser_test.zig @@ -517,6 +517,18 @@ test "zig fmt: no trailing comma on struct decl" { ); } +test "zig fmt: extra newlines at the end" { + try testTransform( + \\const a = b; + \\ + \\ + \\ + , + \\const a = b; + \\ + ); +} + test "zig fmt: simple asm" { try testTransform( \\comptime { diff --git a/std/zig/render.zig b/std/zig/render.zig index de4a2cd365..1179eaa419 100644 --- a/std/zig/render.zig +++ b/std/zig/render.zig @@ -59,6 +59,10 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf( try renderRoot(allocator, &my_stream.stream, tree); + if (!anything_changed and my_stream.source_index != my_stream.source.len) { + anything_changed = true; + } + return anything_changed; }