profile
viewpoint

Ask questionsFirst level is indented twice?

Since https://github.com/go-yaml/yaml/commit/a5ece683394c3b88d90572e44d36c93aea492c2c, the first level of my YAML documents is indented with 4 spaces, yet every other level stays at 2: https://play.golang.org/p/UFEafwZx1Wk yields

users:
    - name: Foo
      lastname: Bar
      emails:
        - foo@bar.org
      friends:
        - name: Friend
          lastname: ""
          emails: []
          friends: []
names:
    - test

When i was expecting

users:
  - name: Foo
    lastname: Bar
    emails:
      - foo@bar.org
    friends:
      - name: Friend
        lastname: ""
        emails: []
        friends: []
names:
  - test
go-yaml/yaml

Answer questions niemeyer

Orderly and aestheticly pleasing are often subjective, and it's easy to confuse something aestheticly pleasing with something that we're used to because that's how it's been for a while. In practice here, although the configuration says 4, the first output has inconsistent indentations at 6 spaces. That sounds hard to justify as pleasing or orderly, and easy to argue it makes it harder for people to read the input properly. The second output has indentations matching exactly the depth of the data represented at that level. That's why I've accepted the complaints received and fixed this in v3.

useful!

Related questions

v3 panics on bad input hot 1
v3 equivalent of v2's MapSlice and MapItem? hot 1
unmarshal with comments provide wrong structure hot 1
Head comments in list elements misplaced hot 1
source:https://uonfu.com/
Github User Rank List