mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
12.36k stars 602 forks source link

yq line operator ignores head comment and therefore reports wrong line numbers #2157

Closed ba3n3 closed 2 months ago

ba3n3 commented 2 months ago

Describe the bug yq doesn't count the head comment(s) and its following newlines when reporting line numbers

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

Input Yaml data1.yml:

---
# head comment

bar:
  # i can put many
  # comments here
  foo: bar

# extra mid file comment

baz: bam
...

data2.yml:

---
bar:
  # i can put many
  # comments here
  foo: bar

# extra mid file comment

baz: bam
...

Command The command you ran:

yq eval '".bar.foo: " + (.bar.foo | line) + ", .baz: " + (.baz | line)' data1.yml data2.yml

(just for demonstration, same result when just evaluating .bar | line)

Actual behavior

.bar.foo: 4, .baz: 8
.bar.foo: 4, .baz: 8

Expected behavior

.bar.foo: 6, .baz: 10
.bar.foo: 4, .baz: 8

The 2 lines from the head comment count.

Additional context It doesn't matter how many following newlines are there.

felixboehm commented 2 months ago

https://github.com/mikefarah/yq/issues/1354