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

Trailing comment affecting yamlfmt.Printer #911

Closed
prnvbn opened this issue Apr 28, 2024 · 3 comments
Closed

Trailing comment affecting yamlfmt.Printer #911

prnvbn opened this issue Apr 28, 2024 · 3 comments
Labels
bug This issue describes a defect or unexpected behavior carvel accepted This issue should be considered for future work and that the triage process has been completed

Comments

@prnvbn
Copy link

prnvbn commented Apr 28, 2024

What steps did you take:
I have the following Go program and YAML file. The Go file integrates with the ytt API and reads the ytt yaml file and just prints it put to standard output. I would expect the file to be printed out with no semantic differences. However, that is not the case!

  • Go program that reads the file andd prints it to stdout
package main

import (
	"os"

	"carvel.dev/ytt/pkg/yamlfmt"
	"carvel.dev/ytt/pkg/yamlmeta"
)

func main() {
	bs, _:= os.ReadFile("example.yaml")
	docset, _:= yamlmeta.NewDocumentSetFromBytes(bs, yamlmeta.DocSetOpts{})
	printer := yamlfmt.NewPrinter(os.Stdout)
	printer.Print(docset)
}
  • YAML file: I have provided a very minimal YAML file
hello: world
# test

What happened:
I see the following in my standard out.

hello: world

# test
---

What did you expect:
I expected the following in my stdout

hello: world

# test

Anything else you would like to add:
I am pretty sure the trailing comment is causing this issue.

Environment:

  • ytt version is v0.49.0. I have pasted my go.mod file below
module issue

go 1.22

toolchain go1.22.2

require carvel.dev/ytt v0.49.0

Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help to work on this issue.

@prnvbn prnvbn added bug This issue describes a defect or unexpected behavior carvel triage This issue has not yet been triaged for relevance labels Apr 28, 2024
@praveenrewar
Copy link
Member

@prnvbn Apologies for the late reply.
Could you please share some more context around what you are trying to achieve here?
By default ytt would remove this comment (ytt -f example.yaml) as this is not a template file (doesn't have any ytt comments). You can achieve the same result by passing WithoutComments as true in DocSetOpts if the comment is not required.

@renuy renuy moved this to To Triage in Carvel May 17, 2024
@renuy renuy added carvel accepted This issue should be considered for future work and that the triage process has been completed and removed carvel triage This issue has not yet been triaged for relevance labels May 17, 2024
@renuy renuy moved this from To Triage to Prioritized Backlog in Carvel May 17, 2024
@renuy
Copy link

renuy commented May 17, 2024

@prnvbn Thanks for raising this.
We are adding this to our backlog, however if you want to fix this please raise a PR and we will happy to review it on priority.

@renuy renuy moved this from Prioritized Backlog to Unprioritized in Carvel May 17, 2024
@joaopapereira
Copy link
Member

Released version 0.51.0 with the fix to this issue

@github-project-automation github-project-automation bot moved this from Unprioritized to Closed in Carvel Nov 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue describes a defect or unexpected behavior carvel accepted This issue should be considered for future work and that the triage process has been completed
Projects
Archived in project
Development

No branches or pull requests

4 participants