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

Anchors formatted with unexpected merge tags #102

Closed
badouralix opened this issue Mar 29, 2023 · 2 comments · Fixed by #103
Closed

Anchors formatted with unexpected merge tags #102

badouralix opened this issue Mar 29, 2023 · 2 comments · Fixed by #103
Milestone

Comments

@badouralix
Copy link
Contributor

badouralix commented Mar 29, 2023

Considering the following yaml file :

a: &a
b:
  <<: *a

Formatting with yamlfmt returns this :

a: &a
b:
  !!merge <<: *a

The expectation here is to preserve the original file and not to add the extra !!merge tag
This results in the following error in vscode : Unresolved tag: tag:yaml.org,2002:mergeYAML

I haven't found any reference of this tag in yamlfmt, good chance it comes directly from gopkg.in/yaml.v3
About !!merge, it shows up in this reference : https://yaml.org/type/merge.html

Edit : it seems it does come from gopkg.in/yaml.v3 indeed : https://go.dev/play/p/DSNN-bUHCIh

@braydonk
Copy link
Collaborator

braydonk commented Mar 30, 2023

Thanks for bringing this to my attention! I don't really know much about this particular yaml feature.

This tag is being written by the library. This is the comment in the library that explains why this tag is included:
https://github.com/braydonk/yaml/blob/v3/encode.go#L439-L440

I think it kind of makes sense; << on its own could technically be ambiguously a literal string or a merge operator. But I think it's a pretty silly reason to always include it in the representation for that reason, because I can't imagine a scenario where someone would use << and wouldn't mean !!merge.

I'll try and add an option for this in the yaml library, not sure what I'll call it yet but probably along the lines of assume_merge_operator that will deliberately drop the merge tag from the representation. I can get it in the next release that I'm planning for this weekend.

@braydonk
Copy link
Collaborator

braydonk commented Mar 30, 2023

Merged this, release should be happening on the weekend.

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

Successfully merging a pull request may close this issue.

2 participants