VINYL formats yaml files into a canonical format retaining comments and setting the indentation by default to two spaces, including for sequences, e.g.:
# List of recipes
recipies:
# todo
- pizza: {}
# todo
- lasagna: {}
- barley soup:
ingredients:
- barley
- onions
- beef
serves: 4
It uses code from gofmt and go-yaml does the heavy lifting of parsing the yaml and formatting the output
$ ./vinyl --help
usage: vinyl [flags] [path ...]
-cpuprofile string
write cpu profile to this file
-d display diffs instead of rewriting files
-i uint
number of spaces to indent (default 2)
-l list files whose formatting differs from vinyl's
-m don't error on duplicate keys in mappings
-w write result to (source) file instead of stdout
Without an explicit path, it processes from standard input. Given a file, it operates on that file; given a directory, it operates on all .yaml and .yml files in that directory, recursively.
By default, vinyl prints the reformatted sources to standard output.