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

ytt fmt changes yaml structure #817

Open
Zebradil opened this issue Mar 27, 2023 · 6 comments
Open

ytt fmt changes yaml structure #817

Zebradil opened this issue Mar 27, 2023 · 6 comments
Assignees
Labels
bug This issue describes a defect or unexpected behavior can be replicated A bug that has been reproduced priority/unprioritized-backlog Higher priority than priority/awaiting-more-evidence but not planned. Contributions are welcome.

Comments

@Zebradil
Copy link
Member

What steps did you take:

$ cat <<EOF > test.yaml
top-level list with empty map:
- {}
another top-level element: 42
EOF

$ diff -u test.yaml <(ytt fmt -f test.yaml)

What happened:

Notice how the empty map is replaced by another top-level element, which becomes a list element of top-level list with empty map.

--- test.yaml	2023-03-27 16:49:19.973100152 +0200
+++ /proc/self/fd/11	2023-03-27 16:49:51.349538852 +0200
@@ -1,3 +1,2 @@
 top-level list with empty map:
-- {}
-another top-level element: 42
+  - another top-level element: 42

What did you expect:

The output yaml is structurally identical to the input yaml.

Environment:

  • ytt version 0.45.0
  • OS: Linux x86

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 working on this issue.

@Zebradil Zebradil added bug This issue describes a defect or unexpected behavior carvel triage This issue has not yet been triaged for relevance labels Mar 27, 2023
@github-actions
Copy link

github-actions bot commented May 7, 2023

This issue is being marked as stale due to a long period of inactivity and will be closed in 5 days if there is no response.

@github-actions github-actions bot added the stale This issue has had no activity for a while and will be closed soon label May 7, 2023
@Zebradil
Copy link
Member Author

Zebradil commented May 7, 2023

Nah, not stale.

@github-actions github-actions bot removed the stale This issue has had no activity for a while and will be closed soon label May 8, 2023
@vmunishwar
Copy link
Contributor

@Zebradil Sorry for the delay in response. This seems to be a bug and we are able to reproduce this.
We would like to know if this is blocking your use of ytt and also understand more about your use case. Are you using ytt fmt to get the output well formatted?

@vmunishwar vmunishwar added can be replicated A bug that has been reproduced priority/unprioritized-backlog Higher priority than priority/awaiting-more-evidence but not planned. Contributions are welcome. and removed carvel triage This issue has not yet been triaged for relevance labels Jun 7, 2023
@Zebradil
Copy link
Member Author

Zebradil commented Jun 9, 2023

Hey @vmunishwar, no worries. I'll provide more context.

I have a workflow in which I want to format yaml files in a consistent way. I was using yq for that but noticed that there is ytt fmt, which would've been a good opportunity to eliminate yq in my workflow (it is not used for anything else). It's a pity that ytt fmt didn't work, so I decided to contribute to the project with this bug report :-)

However, this is not blocking me. In golang code, I format yaml files with the yaml package and outside I still use yq.

@mbbush
Copy link

mbbush commented Feb 28, 2024

I've run into this same issue. This seems like it renders ytt fmt basically unusable, unless I happen to know that none of the yaml files I'm going to process with it contain empty objects, or empty arrays, or perhaps other things that trigger this bug.

What good is a code formatting tool that changes the meaning of your code?

@prembhaskal
Copy link
Contributor

will check this issue this week.

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 can be replicated A bug that has been reproduced priority/unprioritized-backlog Higher priority than priority/awaiting-more-evidence but not planned. Contributions are welcome.
Projects
Status: No status
Development

No branches or pull requests

4 participants