Skip to content

Commit 96a70c4

Browse files
committed
reset_indentation: Don't emit indentation on blank lines
This resulted in trailing whitespace in the generated file. In addition to wasting space in a file that gets served over the wire, this also gets highlighted as a problem when reviewing the generated file in an editor that highlights trailing whitespace.
1 parent 1c52fb1 commit 96a70c4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/cli-support/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,12 @@ fn reset_indentation(s: &str) -> String {
388388
indent = indent.saturating_sub(1);
389389
}
390390
let extra = if line.starts_with(':') || line.starts_with('?') { 1 } else { 0 };
391-
for _ in 0..indent + extra {
392-
dst.push_str(" ");
391+
if !line.is_empty() {
392+
for _ in 0..indent + extra {
393+
dst.push_str(" ");
394+
}
395+
dst.push_str(line);
393396
}
394-
dst.push_str(line);
395397
dst.push_str("\n");
396398
if line.ends_with('{') {
397399
indent += 1;

0 commit comments

Comments
 (0)