zig fmt: fix file ending in a multi line comment

This commit is contained in:
Techatrix
2023-01-29 17:37:48 +01:00
committed by Veikka Tuominen
parent d8c3c11c6c
commit 885d696895
2 changed files with 10 additions and 2 deletions

View File

@@ -186,6 +186,15 @@ test "zig fmt: file ends in comment" {
);
}
test "zig fmt: file ends in multi line comment" {
try testTransform(
\\ \\foobar
,
\\\\foobar
\\
);
}
test "zig fmt: file ends in comment after var decl" {
try testTransform(
\\const x = 42;

View File

@@ -2759,8 +2759,7 @@ fn tokenSliceForRender(tree: Ast, token_index: Ast.TokenIndex) []const u8 {
var ret = tree.tokenSlice(token_index);
switch (tree.tokens.items(.tag)[token_index]) {
.multiline_string_literal_line => {
assert(ret[ret.len - 1] == '\n');
ret.len -= 1;
if (ret[ret.len - 1] == '\n') ret.len -= 1;
},
.container_doc_comment, .doc_comment => {
ret = mem.trimRight(u8, ret, &std.ascii.whitespace);