commit bc24b86d82ec3b8d7d6e7e5d2d3dceb82d7b53dc (tree)
parent 029ec456bce5fc6c57eea496db1cebed55e31ede
Author: Lachlan Easton <lachlan@lakebythewoods.xyz>
Date: Tue, 1 Sep 2020 13:19:34 +1000
zig fmt: Fix regression not covered by testing
Diffstat:
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/lib/std/io/auto_indenting_stream.zig b/lib/std/io/auto_indenting_stream.zig
@@ -106,7 +106,9 @@ pub fn AutoIndentingStream(comptime WriterType: type) type {
pub fn popIndent(self: *Self) void {
assert(self.indent_count != 0);
self.indent_count -= 1;
- self.indent_next_line = std.math.min(self.indent_count, self.indent_next_line); // Tentative indent may have been popped before there was a newline
+
+ if (self.indent_next_line > 0)
+ self.indent_next_line -= 1;
}
/// Writes ' ' bytes if the current line is empty
diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig
@@ -3310,6 +3310,17 @@ test "zig fmt: Only indent multiline string literals in function calls" {
);
}
+test "zig fmt: Don't add extra newline after if" {
+ try testCanonical(
+ \\pub fn atomicSymLink(allocator: *Allocator, existing_path: []const u8, new_path: []const u8) !void {
+ \\ if (cwd().symLink(existing_path, new_path, .{})) {
+ \\ return;
+ \\ }
+ \\}
+ \\
+ );
+}
+
const std = @import("std");
const mem = std.mem;
const warn = std.debug.warn;