mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
zig fmt: fix tracking of applied indentation
This commit is contained in:
parent
8d4531bff5
commit
15d830fd15
2 changed files with 19 additions and 2 deletions
|
|
@ -4075,8 +4075,8 @@ const AutoIndentingStream = struct {
|
||||||
/// Writes ' ' bytes if the current line is empty
|
/// Writes ' ' bytes if the current line is empty
|
||||||
fn applyIndent(ais: *AutoIndentingStream) Error!void {
|
fn applyIndent(ais: *AutoIndentingStream) Error!void {
|
||||||
const current_indent = ais.currentIndent();
|
const current_indent = ais.currentIndent();
|
||||||
if (ais.current_line_empty and current_indent > 0) {
|
if (ais.current_line_empty) {
|
||||||
if (ais.disabled_offset == null) {
|
if (current_indent > 0 and ais.disabled_offset == null) {
|
||||||
try ais.underlying_writer.splatByteAll(' ', current_indent);
|
try ais.underlying_writer.splatByteAll(' ', current_indent);
|
||||||
}
|
}
|
||||||
ais.applied_indent = current_indent;
|
ais.applied_indent = current_indent;
|
||||||
|
|
|
||||||
|
|
@ -6742,6 +6742,23 @@ test "zig fmt: doc comments on fn parameters" {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "zig fmt: proper tracking of indentation" {
|
||||||
|
try testCanonical(
|
||||||
|
\\const a = {
|
||||||
|
\\ {}
|
||||||
|
\\};
|
||||||
|
\\const b = if (x) {};
|
||||||
|
\\const c = .{
|
||||||
|
\\ {
|
||||||
|
\\ {}
|
||||||
|
\\ } //
|
||||||
|
\\ ,
|
||||||
|
\\ if (x) {},
|
||||||
|
\\};
|
||||||
|
\\
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
test "zig fmt: canonicalize stray backslashes in identifiers" {
|
test "zig fmt: canonicalize stray backslashes in identifiers" {
|
||||||
try testTransform(
|
try testTransform(
|
||||||
\\const @"\x" = undefined;
|
\\const @"\x" = undefined;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue