authorgravatar for shritesh@shritesh.comShritesh Bhattarai <shritesh@shritesh.com> 2019-03-26 11:21:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-26 13:26:00-04:00
log5942797000936394a7ed68806df56c02ca5d2b44
tree3391f0e5b08b79c89103819ea561d123fdb9d808
parent51be449a57010a27382cb8104740b34f7863876b

fmt: check for extra newline at end of file

`anything_changed` checks if `source_index` == `source.len` Fixes #2074

2 files changed, 16 insertions(+), 0 deletions(-)

std/zig/parser_test.zig+12
...@@ -517,6 +517,18 @@ test "zig fmt: no trailing comma on struct decl" {...@@ -517,6 +517,18 @@ test "zig fmt: no trailing comma on struct decl" {
517 );517 );
518}518}
519519
520test "zig fmt: extra newlines at the end" {
521 try testTransform(
522 \\const a = b;
523 \\
524 \\
525 \\
526 ,
527 \\const a = b;
528 \\
529 );
530}
531
520test "zig fmt: simple asm" {532test "zig fmt: simple asm" {
521 try testTransform(533 try testTransform(
522 \\comptime {534 \\comptime {
std/zig/render.zig+4
...@@ -59,6 +59,10 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(...@@ -59,6 +59,10 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(
5959
60 try renderRoot(allocator, &my_stream.stream, tree);60 try renderRoot(allocator, &my_stream.stream, tree);
6161
62 if (!anything_changed and my_stream.source_index != my_stream.source.len) {
63 anything_changed = true;
64 }
65
62 return anything_changed;66 return anything_changed;
63}67}
6468