| ... | @@ -2512,7 +2512,7 @@ const Space = enum { | ... | @@ -2512,7 +2512,7 @@ const Space = enum { |
| 2512 | /// In either case, a newline will be inserted afterwards. | 2512 | /// In either case, a newline will be inserted afterwards. |
| 2513 | semicolon, | 2513 | semicolon, |
| 2514 | /// Skip rendering whitespace and comments. If this is used, the caller | 2514 | /// Skip rendering whitespace and comments. If this is used, the caller |
| 2515 | /// *must* handle handle whitespace and comments manually. | 2515 | /// *must* handle whitespace and comments manually. |
| 2516 | skip, | 2516 | skip, |
| 2517 | }; | 2517 | }; |
| 2518 | | 2518 | |
| ... | @@ -2702,7 +2702,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void { | ... | @@ -2702,7 +2702,7 @@ fn renderIdentifierContents(writer: anytype, bytes: []const u8) !void { |
| 2702 | } | 2702 | } |
| 2703 | }, | 2703 | }, |
| 2704 | 0x00...('\\' - 1), ('\\' + 1)...0x7f => { | 2704 | 0x00...('\\' - 1), ('\\' + 1)...0x7f => { |
| 2705 | const buf = [1]u8{@intCast(u8, byte)}; | 2705 | const buf = [1]u8{byte}; |
| 2706 | try std.fmt.format(writer, "{}", .{std.zig.fmtEscapes(&buf)}); | 2706 | try std.fmt.format(writer, "{}", .{std.zig.fmtEscapes(&buf)}); |
| 2707 | pos += 1; | 2707 | pos += 1; |
| 2708 | }, | 2708 | }, |
| ... | @@ -2782,7 +2782,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool { | ... | @@ -2782,7 +2782,7 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool { |
| 2782 | const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.whitespace); | 2782 | const comment_content = mem.trimLeft(u8, trimmed_comment["//".len..], &std.ascii.whitespace); |
| 2783 | if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) { | 2783 | if (ais.disabled_offset != null and mem.eql(u8, comment_content, "zig fmt: on")) { |
| 2784 | // Write the source for which formatting was disabled directly | 2784 | // Write the source for which formatting was disabled directly |
| 2785 | // to the underlying writer, fixing up invaild whitespace. | 2785 | // to the underlying writer, fixing up invalid whitespace. |
| 2786 | const disabled_source = tree.source[ais.disabled_offset.?..comment_start]; | 2786 | const disabled_source = tree.source[ais.disabled_offset.?..comment_start]; |
| 2787 | try writeFixingWhitespace(ais.underlying_writer, disabled_source); | 2787 | try writeFixingWhitespace(ais.underlying_writer, disabled_source); |
| 2788 | // Write with the canonical single space. | 2788 | // Write with the canonical single space. |
| ... | @@ -2799,7 +2799,10 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool { | ... | @@ -2799,7 +2799,10 @@ fn renderComments(ais: *Ais, tree: Ast, start: usize, end: usize) Error!bool { |
| 2799 | } | 2799 | } |
| 2800 | | 2800 | |
| 2801 | if (index != start and mem.containsAtLeast(u8, tree.source[index - 1 .. end], 2, "\n")) { | 2801 | if (index != start and mem.containsAtLeast(u8, tree.source[index - 1 .. end], 2, "\n")) { |
| 2802 | try ais.insertNewline(); | 2802 | // Don't leave any whitespace at the end of the file |
| | 2803 | if (end != tree.source.len) { |
| | 2804 | try ais.insertNewline(); |
| | 2805 | } |
| 2803 | } | 2806 | } |
| 2804 | | 2807 | |
| 2805 | return index != start; | 2808 | return index != start; |