Skip to content

Commit

Permalink
zig fmt: fix file ending in a multi line comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix authored and Vexu committed Jan 29, 2023
1 parent d8c3c11 commit 885d696
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 9 additions & 0 deletions lib/std/zig/parser_test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions lib/std/zig/render.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 885d696

Please sign in to comment.