Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evaluate command moves comments to a different line #2176

Open
guymeron opened this issue Oct 16, 2024 · 1 comment
Open

evaluate command moves comments to a different line #2176

guymeron opened this issue Oct 16, 2024 · 1 comment
Labels

Comments

@guymeron
Copy link

guymeron commented Oct 16, 2024

Describe the bug
evaluate command moves comments to a different line

Version of yq: 4.44.3
Operating system: mac
Installed via: homebrew

Input Yaml
data1.yml:

line1: "aaa"
line2:
  - name: foo
    array:
      # comment1
      - key1: val1
        key2: val2
      # comment2

      # comment3
      - key1: val10
        key2: val20

Command

cat data1.yml |  yq eval .line2

Actual behavior

- name: foo
  array:
    # comment1
    - key1: val1
      key2: val2
    # comment3
    - key1: val10
      # comment2

      key2: val20

Expected behavior

- name: foo
  array:
    # comment1
    - key1: val1
      key2: val2
    # comment2

    # comment3
    - key1: val10        
      key2: val20

Additional context
It works OK when there is no empty line between the comments (line number 9).

@felicijus
Copy link

felicijus commented Nov 14, 2024

I have a similar Issue, if there are multiple comment line a blank line is inserted.

global:
    # BUG: Elasticsearch does not support network file systems (NFS). Usage of NFS may cause data corruption.

    # NOTE: xxxxx by default, use 'xxxxx' instead
    defaultStorageClass: "xxx" # TEMPLATE: default "storageClass: """

should still be:

global:
    # BUG: Elasticsearch does not support network file systems (NFS). Usage of NFS may cause data corruption.
    # NOTE: xxxxx by default, use 'xxxxx' instead
    defaultStorageClass: "xxx" # TEMPLATE: default "storageClass: """

Edit:
I tested a bit around and this part of the documentation does not work
https://mikefarah.gitbook.io/yq/operators/comment-operators#get-head-comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants
@guymeron @felicijus and others