Skip to content

Commit

Permalink
fix(fmt): fix invalid block seq indent
Browse files Browse the repository at this point in the history
when indent width is greater than 2
  • Loading branch information
g-plane committed Jul 4, 2024
1 parent 444cc16 commit 2e9e57e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pretty_yaml/src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,14 @@ impl DocGen for BlockSeqEntry {
{
let mut trivia_docs = format_trivias_after_token(&token, ctx);
docs.push(Doc::space());
docs.push(Doc::text(
" ".repeat(ctx.indent_width.checked_sub(2).unwrap_or_default()),
));
docs.append(&mut trivia_docs);
} else if self.block().is_some() || self.flow().is_some() {
docs.push(Doc::space());
docs.push(Doc::text(
" ".repeat(ctx.indent_width.checked_sub(1).unwrap_or(1)),
));
}
}

Expand Down
5 changes: 5 additions & 0 deletions pretty_yaml/tests/fmt/indent/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[2]
indentWidth = 2

[4]
indentWidth = 4
5 changes: 5 additions & 0 deletions pretty_yaml/tests/fmt/indent/flow-sequence.2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: pretty_yaml/tests/fmt.rs
---
- a: b
c: d
5 changes: 5 additions & 0 deletions pretty_yaml/tests/fmt/indent/flow-sequence.4.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: pretty_yaml/tests/fmt.rs
---
- a: b
c: d
2 changes: 2 additions & 0 deletions pretty_yaml/tests/fmt/indent/flow-sequence.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- a: b
c: d

0 comments on commit 2e9e57e

Please sign in to comment.