yq icon indicating copy to clipboard operation
yq copied to clipboard

headComment is added after the field instead of before

Open ben-turner opened this issue 3 years ago • 2 comments

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

ben-turner avatar Apr 21 '21 20:04 ben-turner

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

Looks related to https://github.com/go-yaml/yaml/issues/695

mikefarah avatar May 10 '21 05:05 mikefarah

Possibly https://github.com/go-yaml/yaml/issues/610

mikefarah avatar May 10 '21 05:05 mikefarah