zig fmt: Fix regression not covered by testing

This commit is contained in:
Lachlan Easton 2020-09-01 13:19:34 +10:00
parent 029ec456bc
commit bc24b86d82
2 changed files with 14 additions and 1 deletions

View File

@ -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

View File

@ -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;