yq icon indicating copy to clipboard operation
yq copied to clipboard

yq strips document separator when adding a comment

Open pcppcp opened this issue 1 year ago • 1 comments

Describe the bug I am trying to add a comment at the top of a multi-document yaml file. yq unfortunately strips the first document separator line that is expected by downstream yaml linters I use.

Version of yq: 4.35.2 Operating system: linux Installed via: binary release

Input Yaml

data1.yml:

---
key: a
---
key: b

Command

yq eval-all 'select(documentIndex == 0) headComment|="A comment..."' data1.yml

Actual behavior

# I am a comment

key: a
---
key: b

Expected behavior

---
# I am a comment
key: a
---
key: b

or

# I am a comment
---
key: a
---
key: b

pcppcp avatar Oct 20 '23 07:10 pcppcp

Having the same issue here, weird that it only applies to head_comment and when applied to the whole document (seems to work on a particular key)

Diaoul avatar May 20 '24 13:05 Diaoul