Skip to content

Commit

Permalink
Add '---' separator not after last item. (#916)
Browse files Browse the repository at this point in the history
Signed-off-by: Ernst von Oelsen <[email protected]>
  • Loading branch information
ernstvonoelsen authored Sep 20, 2024
1 parent b60ca0d commit 9ac89ff
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 5 deletions.
6 changes: 6 additions & 0 deletions pkg/yamlfmt/filetests/comment-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# comment

+++


# comment
1 change: 0 additions & 1 deletion pkg/yamlfmt/filetests/comments-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@
---

# after
---
1 change: 0 additions & 1 deletion pkg/yamlfmt/filetests/comments-extra-space.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
- test2 # inline

# after
---
1 change: 0 additions & 1 deletion pkg/yamlfmt/filetests/comments-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
- test2

# after
---
1 change: 0 additions & 1 deletion pkg/yamlfmt/filetests/comments-map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,3 @@ nested:
test4: val

# nested-after
---
2 changes: 1 addition & 1 deletion pkg/yamlfmt/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *Printer) print(val interface{}, ws whitespace, writer *writer) {
for i, item := range typedVal.Items {
// TODO deal with first empty doc
meta := p.printMeta(item, ws, writer, i == 0)
if i != 0 || len(meta.Suffix) > 0 {
if (i > 0 && i < len(typedVal.Items)-1) || len(meta.Suffix) > 0 {
writer.AddContent(writerChunk{
Indent: ws.Indent,
Content: "---" + meta.Suffix,
Expand Down

0 comments on commit 9ac89ff

Please sign in to comment.