-
-
Notifications
You must be signed in to change notification settings - Fork 724
Open
Description
📄 Description
When a YAML document that contains merge‑tags << is processed with the irreduce operator, comments that precede the merge‑key are removed from the output.
In contrast, a simple yq '.' file.yaml (or yq '. * {}' file.yaml) preserves all comments in the file. Thus the issue appears only when a merge‑key is part of an irreduce operation.
🛠️ Reproduction
# file.yaml
values: &values
value: 1
v1: { <<: *values } # COMMENT
v2:
# COMMENT
<<: *values
# COMMENT
v3:
a: 1
# COMMENT
<<: *values
v: # COMMENTRun:
# 1️⃣ Simple eval – comments are kept
yq '.' file.yaml # yq '. * {}' file.yamlOutput:
values: &values
value: 1
v1: {!!merge <<: *values} # COMMENT
v2:
# COMMENT
!!merge <<: *values
# COMMENT
v3:
a: 1
# COMMENT
!!merge <<: *values
v: # COMMENTNow run the ireduce pipeline:
# 2️⃣ ireduce – comments around << are lost
yq '. as $item ireduce ({}; . * $item)' file.yamlOutput:
values: &values
value: 1
v1:
<<: *values
v2: # COMMENT
<<: *values
v3:
a: 1
<<: *values
v: # COMMENT✅ Expected Behaviour
The merge‑operator should behave like a normal node for the purposes of comment preservation. The output of the ireduce pipeline should be identical to the input, except that the mapping merge has been applied.
❌ Actual Behaviour
- Comments that precede a merge‑key are dropped.
- The comment that appears on the same line as the key (
v1) is moved to the key line. - Comments that follow a key (e.g.,
v:) are preserved.