Skip to content

Commit 5942797

Browse files
shriteshandrewrk
authored andcommitted
fmt: check for extra newline at end of file
`anything_changed` checks if `source_index` == `source.len` Fixes #2074
1 parent 51be449 commit 5942797

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

std/zig/parser_test.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,18 @@ test "zig fmt: no trailing comma on struct decl" {
517517
);
518518
}
519519

520+
test "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+
520532
test "zig fmt: simple asm" {
521533
try testTransform(
522534
\\comptime {

std/zig/render.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ pub fn render(allocator: *mem.Allocator, stream: var, tree: *ast.Tree) (@typeOf(
5959

6060
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+
6266
return anything_changed;
6367
}
6468

0 commit comments

Comments
 (0)