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

bug: nested arrays are flattened #167

Open
timruffles opened this issue Apr 9, 2024 · 3 comments
Open

bug: nested arrays are flattened #167

timruffles opened this issue Apr 9, 2024 · 3 comments
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.

Comments

@timruffles
Copy link

timruffles commented Apr 9, 2024

nested arrays are flattened:

$ cat test.yml
- - one
  - two
$ yamlfmt -formatter indent=4 test.yml
$ git diff
diff --git a/test.yml b/test.yml
index 9ff9c3253f..8c71a9deb8 100644
--- a/test.yml
+++ b/test.yml
@@ -1,2 +1,3 @@
-- - one
-  - two
+-
+- one
+- two
$ cat test.yml
-
- one
- two

tested with v0.11.0

@braydonk braydonk added the yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix. label Apr 10, 2024
@braydonk
Copy link
Collaborator

Thanks for opening an issue! Unfortunately this falls under problems with the underlying yaml parser, which I can't easily address in the near future for reasons explained in this post.

@timruffles
Copy link
Author

I think in this case yaml/v3 parses it fine:

package main

import (
	"fmt"

	"gopkg.in/yaml.v3"
)

const input = `
- - one
  - two`

func main() {
	var parsed any
	err := yaml.Unmarshal([]byte(input), &parsed)
	fmt.Println(parsed, err) // [[one two]] <nil>
}

digging into a parse into a yaml.Node, we get the AST you'd expect: Document > Sequence > Sequence

Screenshot 2024-04-10 at 14 49 34

@braydonk
Copy link
Collaborator

braydonk commented Apr 10, 2024

To clarify, the issues I have tagged with this label are all around the way the yaml library is used. It isn't necessarily designed for the way yamlfmt uses it, which is putting yaml in and right back out, so there are a number of cases where the emitter decides to output things in weird ways. I've fixed a few of those types of issues in my fork but they are tricky and take a lot of time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
yaml_v3_problem A bug in the underlying yaml library. These issues are vastly harder to fix.
Projects
None yet
Development

No branches or pull requests

2 participants