Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions formatters/basic/formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,21 @@ b:`,
expect: `---
a:`,
},
{
// Regression test for https://github.com/google/yamlfmt/issues/110
// A blank line below a flow mapping sequence item (via retain_line_breaks)
// used to emit a superfluous trailing comma before the closing brace.
name: "no superfluous comma in flow style",
config: map[string]any{
"include_document_start": true,
"retain_line_breaks": true,
// DefaultConfig picks CRLF on Windows; pin LF so the
// expected output is identical across platforms.
"line_ending": "lf",
},
input: "---\n- {foo: bar}\n\n",
expect: "---\n- {foo: bar}\n\n",
},
{
name: "crlf line ending",
config: map[string]any{
Expand Down
2 changes: 1 addition & 1 deletion pkg/yaml/emitterc.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ func yaml_emitter_emit_flow_mapping_key(emitter *yaml_emitter_t, event *yaml_eve
}

if event.typ == yaml_MAPPING_END_EVENT {
if (emitter.canonical || len(emitter.head_comment)+len(emitter.foot_comment)+len(emitter.tail_comment) > 0) && !first && !trail {
if emitter.canonical && !first && !trail {
if !yaml_emitter_write_indicator(emitter, []byte{','}, false, false, false) {
return false
}
Expand Down