diff --git a/pkg/yamlfmt/filetests/comment-only.yml b/pkg/yamlfmt/filetests/comment-only.yml new file mode 100644 index 00000000..3f3ed41c --- /dev/null +++ b/pkg/yamlfmt/filetests/comment-only.yml @@ -0,0 +1,6 @@ +# comment + ++++ + + +# comment diff --git a/pkg/yamlfmt/filetests/comments-doc.yml b/pkg/yamlfmt/filetests/comments-doc.yml index 37dbc29c..fb9e7e96 100644 --- a/pkg/yamlfmt/filetests/comments-doc.yml +++ b/pkg/yamlfmt/filetests/comments-doc.yml @@ -14,4 +14,3 @@ --- # after ---- diff --git a/pkg/yamlfmt/filetests/comments-extra-space.yml b/pkg/yamlfmt/filetests/comments-extra-space.yml index 504e4cc5..14889251 100644 --- a/pkg/yamlfmt/filetests/comments-extra-space.yml +++ b/pkg/yamlfmt/filetests/comments-extra-space.yml @@ -29,4 +29,3 @@ - test2 # inline # after ---- diff --git a/pkg/yamlfmt/filetests/comments-list.yml b/pkg/yamlfmt/filetests/comments-list.yml index 166befbf..3cac94b9 100644 --- a/pkg/yamlfmt/filetests/comments-list.yml +++ b/pkg/yamlfmt/filetests/comments-list.yml @@ -13,4 +13,3 @@ - test2 # after ---- diff --git a/pkg/yamlfmt/filetests/comments-map.yml b/pkg/yamlfmt/filetests/comments-map.yml index 25e11eba..a71d2716 100644 --- a/pkg/yamlfmt/filetests/comments-map.yml +++ b/pkg/yamlfmt/filetests/comments-map.yml @@ -28,4 +28,3 @@ nested: test4: val # nested-after ---- diff --git a/pkg/yamlfmt/printer.go b/pkg/yamlfmt/printer.go index 3f513b0e..7d8f5121 100644 --- a/pkg/yamlfmt/printer.go +++ b/pkg/yamlfmt/printer.go @@ -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,