Re-indenting a config file, and the duplicate key that hid in it
Take a small server config. The first line is server:, and under it, indented four spaces, are port: 8080 with a comment "# default" a few spaces after it, and hosts: [a.example, b.example]. At the bottom is log: {level: info}, written as an inline map with extra spaces after the colon. It works, but the indents and spacing are uneven, which is how files look after several people have edited them.
With 2 spaces chosen, the output has server: on the first line and port: 8080 # default on the next, now indented two spaces, with one space before the comment. The hosts list stays inline, written as [ a.example, b.example ] with a space inside each bracket, and log: { level: info } gets the same spacing. The comment is still there. The values are unchanged. If you choose One item per line instead, hosts: becomes a block with - a.example and - b.example on their own lines, and log: becomes a block with level: info indented below it. Both versions mean exactly the same thing to any YAML parser.
Now a mistake that is easy to make in a long file. Add a second line, port: 9090, at the end of the server block, as line 4. Many YAML parsers accept this without a word and keep only the last value, so the server quietly starts on 9090. The YAML standard says keys in one map must be unique, and this tool follows it. The result disappears and the error says the map keys must be unique, at line 4, column 5, which is where the second port starts. You fix the file before anything reads it.
Values are kept as you wrote them, which matters more in YAML than in most formats. Under YAML 1.1, which some older parsers such as PyYAML still follow, an unquoted NO or yes is read as a boolean, so country: NO can turn into false. Under YAML 1.2, which this tool uses, they are strings. Either way, the formatter writes NO back as NO and does not add or remove quotes. The same goes for numbers: version: 1.10 stays 1.10 and does not become 1.1. Re-indenting your file never changes how another program reads it.
There are limits. The tool checks YAML syntax, not meaning. It does not know the keys a Kubernetes manifest, a GitHub Actions workflow or a Docker Compose file expects, so a misspelled key that is still valid YAML passes. It reports the first error only; fix it and the next appears. The exact spacing inside inline lists and before end-of-line comments is not kept. And it uses YAML 1.2 rules, so a file written for an older YAML 1.1 parser may be read slightly differently by that parser, even though the text the formatter writes is the same.