What this tool does
It re-indents. It does not rewrite.
# Production database — check with on-call before changing
db:
host: db.example.com # manual failover
port: 5432
Two-space indentation, and everything else exactly as you wrote it: the comment above db, the comment after host, the quoting style of each scalar.
The obvious way loses your comments
The obvious way to write a YAML formatter is to parse the file into a value and serialise the value back. It is also wrong, in two ways that leave no trace.
Every comment disappears. A value has no comments; they live in the document, not in the data. A configuration file that someone documented — why this timeout, who to call, what breaks if you change it — comes back silent, and the output is valid YAML, so nothing tells you what was lost.
Anchors are expanded. This:
base: &defaults
restart: always
logging: json
web:
<<: *defaults
worker:
<<: *defaults
becomes three copies of the same block, longer than the input, with the link between them gone. The next person to change restart has to find all three.
This formatter keeps the document and changes only its layout.
Ambiguous values are left alone
country: NO stays country: NO.
A YAML 1.2 reader sees the string NO; a YAML 1.1 reader — PyYAML — sees the boolean false. Adding quotes would settle that question, and settling it is the author’s call, not a formatter’s: a file written for PyYAML may well have meant false.
The conversion tools do add quotes there, and they are right to: they start from a value they know to be a string. A formatter starts from a file, and a file does not say.
Several documents in one file
--- separates YAML documents, and a file may hold any number of them. Each is formatted in place and the separators stay. That is the shape of most Kubernetes manifests, and it is a stream, not an error.
The options
Indentation — two spaces by default, or whatever you set.
Sort keys — alphabetical, recursively, with each comment following the entry it was attached to. Useful for comparing two files that drifted; leave it off if the order of your keys means something, which in a configuration file it often does.
Private by design
Everything runs locally in your browser with JavaScript. Your data is never uploaded, which makes the tool safe for sensitive content, and it keeps working offline.