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

headComment is added after the field instead of before #788

Open
ben-turner opened this issue Apr 21, 2021 · 2 comments
Open

headComment is added after the field instead of before #788

ben-turner opened this issue Apr 21, 2021 · 2 comments
Labels

Comments

@ben-turner
Copy link

Describe the bug
When setting headComment, the comment is added after the field or inside the object instead of being prepended above the field.

Version of yq: 4.7.0 (also failed on 4.5.1)
Operating system: mac
Installed via: homebrew

Example 1

Input Yaml

foo:
  default: bar
  description: baz

Command

yq e -P '.[] headComment |= .description | .[] |= .default'

Actual behavior

foo: bar
# baz

Expected behavior

# baz

foo: bar

Example 2:

Input Yaml

foo:
  default:
    qux: quo
  description: baz

Command

yq e -P '.[] headComment |= .description | .[] |= .default'

Actual behavior

foo:
  # baz
  qux: quo

Expected behavior

# baz

foo:
  qux: quo
@mikefarah
Copy link
Owner

This is a problem with the underlying go-yaml parser - it's not very good at placing comments correctly :(

Looks related to go-yaml/yaml#695

@mikefarah
Copy link
Owner

Possibly go-yaml/yaml#610

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

2 participants