mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
zig fmt ignores "zig fmt: off" directive for whitespace fixes
This commit is contained in:
parent
4f43a4b30f
commit
9471f16c79
@ -9,10 +9,13 @@ test "zig fmt: change use to usingnamespace" {
|
||||
}
|
||||
|
||||
test "zig fmt: whitespace fixes" {
|
||||
try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}",
|
||||
try testTransform("test \"\" {\r\n\tconst hi = x;\r\n}\n// zig fmt: off\ntest \"\"{\r\n\tconst a = b;}\r\n",
|
||||
\\test "" {
|
||||
\\ const hi = x;
|
||||
\\}
|
||||
\\// zig fmt: off
|
||||
\\test ""{
|
||||
\\ const a = b;}
|
||||
\\
|
||||
);
|
||||
}
|
||||
|
||||
@ -108,14 +108,15 @@ fn renderRoot(
|
||||
Token.Id.LineComment => {},
|
||||
Token.Id.Eof => {
|
||||
const start = tree.tokens.at(start_token_index + 1).start;
|
||||
try stream.write(tree.source[start..]);
|
||||
try copyFixingWhitespace(stream, tree.source[start..]);
|
||||
return;
|
||||
},
|
||||
else => continue,
|
||||
}
|
||||
if (mem.eql(u8, mem.trim(u8, tree.tokenSlicePtr(end_token)[2..], " "), "zig fmt: on")) {
|
||||
const start = tree.tokens.at(start_token_index + 1).start;
|
||||
try stream.print("{}\n", tree.source[start..end_token.end]);
|
||||
try copyFixingWhitespace(stream, tree.source[start..end_token.end]);
|
||||
try stream.writeByte('\n');
|
||||
while (tree.tokens.at(decl.firstToken()).start < end_token.end) {
|
||||
decl = (it.next() orelse return).*;
|
||||
}
|
||||
@ -2121,3 +2122,11 @@ const FindByteOutStream = struct {
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
fn copyFixingWhitespace(stream: var, slice: []const u8) @typeOf(stream).Child.Error!void {
|
||||
for (slice) |byte| switch (byte) {
|
||||
'\t' => try stream.write(" "),
|
||||
'\r' => {},
|
||||
else => try stream.writeByte(byte),
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user