From 9ac89ff19a3eeadf3acbe9642d1c4f6c2139c9c5 Mon Sep 17 00:00:00 2001 From: ernstvonoelsen <41431732+ernstvonoelsen@users.noreply.github.com> Date: Fri, 20 Sep 2024 16:11:24 +0200 Subject: [PATCH] Add '---' separator not after last item. (#916) Signed-off-by: Ernst von Oelsen --- pkg/yamlfmt/filetests/comment-only.yml | 6 ++++++ pkg/yamlfmt/filetests/comments-doc.yml | 1 - pkg/yamlfmt/filetests/comments-extra-space.yml | 1 - pkg/yamlfmt/filetests/comments-list.yml | 1 - pkg/yamlfmt/filetests/comments-map.yml | 1 - pkg/yamlfmt/printer.go | 2 +- 6 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 pkg/yamlfmt/filetests/comment-only.yml 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,