zig fmt: bypass auto indentation for // zig fmt: on
Currently an indented `// zig fmt: on` will be indented an additional time on every run of zig fmt.
This commit is contained in:
committed by
Andrew Kelley
parent
8e6865c8ee
commit
4081e0a475
@@ -1315,6 +1315,27 @@ test "zig fmt: 'zig fmt: (off|on)' works in the middle of code" {
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: 'zig fmt: on' indentation is unchanged" {
|
||||
try testCanonical(
|
||||
\\fn initOptionsAndLayouts(output: *Output, context: *Context) !void {
|
||||
\\ // zig fmt: off
|
||||
\\ try output.main_amount.init(output, "main_amount"); errdefer optput.main_amount.deinit();
|
||||
\\ try output.main_factor.init(output, "main_factor"); errdefer optput.main_factor.deinit();
|
||||
\\ try output.view_padding.init(output, "view_padding"); errdefer optput.view_padding.deinit();
|
||||
\\ try output.outer_padding.init(output, "outer_padding"); errdefer optput.outer_padding.deinit();
|
||||
\\ // zig fmt: on
|
||||
\\
|
||||
\\ // zig fmt: off
|
||||
\\ try output.top.init(output, .top); errdefer optput.top.deinit();
|
||||
\\ try output.right.init(output, .right); errdefer optput.right.deinit();
|
||||
\\ try output.bottom.init(output, .bottom); errdefer optput.bottom.deinit();
|
||||
\\ try output.left.init(output, .left); errdefer optput.left.deinit();
|
||||
\\ // zig fmt: on
|
||||
\\}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
test "zig fmt: pointer of unknown length" {
|
||||
try testCanonical(
|
||||
\\fn foo(ptr: [*]u8) void {}
|
||||
|
||||
@@ -2311,9 +2311,9 @@ fn renderComments(ais: *Ais, tree: ast.Tree, start: usize, end: usize) Error!boo
|
||||
// to the underlying writer, fixing up invaild whitespace.
|
||||
const disabled_source = tree.source[ais.disabled_offset.?..comment_start];
|
||||
try writeFixingWhitespace(ais.underlying_writer, disabled_source);
|
||||
ais.disabled_offset = null;
|
||||
// Write with the canonical single space.
|
||||
try ais.writer().writeAll("// zig fmt: on\n");
|
||||
try ais.underlying_writer.writeAll("// zig fmt: on\n");
|
||||
ais.disabled_offset = null;
|
||||
} else if (ais.disabled_offset == null and mem.eql(u8, comment_content, "zig fmt: off")) {
|
||||
// Write with the canonical single space.
|
||||
try ais.writer().writeAll("// zig fmt: off\n");
|
||||
|
||||
Reference in New Issue
Block a user