Here is a TOML file that will not parse:
[package]
name = "my-app"
version= "0.2.0"
edition="2021"
[dependencies]
serde={ version = "1.0", features = ["derive"] }
See all four problems? Mixed spacing around =, an indent before [dependencies], an inline table wearing out its welcome, and a missing newline between the two tables. The formatter turns this into something a human would actually want to edit:
[package]
name = "my-app"
version = "0.2.0"
edition = "2021"
[dependencies]
serde = { version = "1.0", features = ["derive"] }
TOML's whole selling point is that a config file should be obviously correct just by glancing at it. When a hand-edited Cargo.toml or pyproject.toml drifts away from that, the formatter drags it back.
Gotcha that wastes the most time: dot-delimited keys versus section headers.
[tool]
pytest = "yes" # declares table "tool" with key "pytest"
tool.pytest = "yes" # declares flat key "tool.pytest" -- NOT the same
Both lines are valid. They define completely different data. If a [tool.pytest] section exists somewhere, flat-dot keys nearby create an ambiguous mess. The formatter does not restructure this for you -- but its validation pass flags duplicate or conflicting paths.
A few formatting decisions baked in:
- Inline tables stay inline up to a line-width threshold, then expand to multi-line. Comma position follows
cargo fmtconvention. - Arrays of tables (
[[bin]],[[test]]) get a blank line before each entry -- matches the convention used by Cargo, Poetry, and Maturin. - Trailing commas inside inline tables are added (consistent diffs); trailing commas inside arrays are stripped (the TOML spec forbids them).
- Literal strings (
'one\raw\path') are preferred over basic strings whenever no escape sequences appear. Paste a Windows path and the tool rewrites it as'C:\Users\me\project'automatically. - Datetime values (
1979-05-27T07:32:00Z,1979-05-27,07:32:00) are recognized and left untouched. The tool never stringifies or rewrites them.
TOML is the configuration format for Cargo (Rust), pyproject.toml (Python), Hugo, uv, Taplo, and a growing list of others. If you switch between two of those ecosystems on the same day, a single normalizer keeps the spacing and table style consistent.