profile
viewpoint

Ask questionsv3: dumps indenting not coherent with v2

The way v3 indents dumps by default is different from v2 and I think it shouldn't be:

  • default indenting is now 4 spaces instead of 2
  • list items are now shifted right instead of being vertically aligned with the key
a: Easy! v2
b:
  c: 2
  d:
  - 3
  - 4
a: Easy! v3
b:
    c: 2
    d:
        - 3
        - 4

I know it won't matter but I personally prefer the looks of the first dump.

Also I've seen this change break tests that rely on yaml string equality.

go-yaml/yaml

Answer questions niemeyer

Yes, in v3 we've fixed the indentation so that each level is coherently aligned across all elements and nesting levels. Note in your example how the second output is perfectly aligned according to its depth, while the first is not.

Tests expecting an exact format will indeed break. That's why this was done between v2 and v3 and not inside the release.

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