Fix superfluous comma in flow style mappings - #323
Draft
sidsri14 wants to merge 1 commit into
Draft
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
sidsri14
force-pushed
the
fix/flow-mapping-trailing-comma-110
branch
from
August 27, 2026 09:50
0d63beb to
f955917
Compare
The flow-mapping MAPPING_END branch of the emitter wrote a separator
comma whenever a comment buffer was non-empty, matching yaml.v3's
original logic. Comments on or below a flow mapping attach to the
mapping and arrive with the FLOW_MAPPING_END event, producing output
like "- {foo: bar,}".
Interior flow-map comments always flow through the TRAIL path, so a
comma is never legitimately needed at MAPPING_END. Align with the
flow-sequence END branch, which writes the comma only in canonical
mode.
Fixes google#110
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #110 — a flow-style mapping that carries a comment (e.g. a comment line below a flow mapping sequence item, which
retain_line_breaksinjects) was emitted with a superfluous trailing comma:- {foo: bar,}.The flow-mapping
MAPPING_ENDbranch inyaml_emitter_emit_flow_mapping_keywrote a separator comma whenever any comment buffer was non-empty (!first && !trail). Comments on/below a flow mapping attach to the mapping node and arrive with theFLOW_MAPPING_ENDevent, so that condition produced a comma before the closing brace even though no separator was needed.Interior flow-map comments always flow through the TRAIL path (
yaml_emitter_emit_flow_mapping_value), so a comma is never legitimately required atMAPPING_END. This change aligns the flow-mapping branch with the flow-sequence END branch, which already writes the comma only in canonical mode.Test plan
Added a regression case to
TestFormatterusing the exact reporter scenario (include_document_start+retain_line_breaks, blank line below- {foo: bar}):---\n- {foo: bar,}\n→ test fails---\n- {foo: bar}\n→ test passesVerified the full
go test ./...failure set is identical with/without the change (no regressions), andgofmt/go vetare clean.Notes
go.yaml.in/yaml/v3), not introduced by the yamlfmt fork.