Taplo: A Fast TOML Formatter & LinterΒΆ
IntroductionΒΆ
Taplo is used to automatically format and validate project files like pyproject.toml and cog.toml, ensuring consistent structure and preventing syntax errors across the codebase.
Key Benefits:
π High Performance: Built in Rust, Taplo formats TOML files extremely fast.
π Highly Configurable: Supports options like entry alignment, array expansion, and comment alignment.
β Formatter + Linter: Formats and validates TOML files.
π§© Editor Integration: Works with editors through
taplo-lsp.π€ CI/CD Friendly: Use
taplo formatto fix andtaplo checkto enforce formatting in CI.
βοΈ Getting StartedΒΆ
Installation Install Taplo CLI (requires Rust):
just install-taplo
Quick Example Create a sample TOML file and format it:
echo '[table]\nkey = "value" # Needs formatting' > example.toml
taplo format example.toml
cat example.toml
Expected output will show aligned key/value and comment (based on config).
π UsageΒΆ
Example Use Case:
During continuous integration (CI), you want to enforce consistent TOML formatting. With taplo check in your CI pipeline, you can automatically reject pull requests that donβt follow the formatting standards, saving time on manual code review for formatting issues.
Format TOML files:
just format-toml
Check TOML formatting (without modifying files):
just check-toml
Run it manually:
just pre-commit-run
π Recommended ConfigurationΒΆ
.taplo.toml:
[formatting]
respect-ignores = true
line-width = 80
indent-width = 4
align-entries = true
align-comments = true
array-auto-expand = true
array-auto-collapse = false
compact-arrays = false
compact-inline-tables = false
newline-style = "LF"
β‘οΈ Full option list here
π Disabling TaploΒΆ
To temporarily skip formatting:
Disable specific rules in
.taplo.toml:
[formatting]
respect-ignores = true
line-width = 80
indent-width = 4
align-entries = true
align-comments = true
array-auto-expand = true
array-auto-collapse = false
compact-arrays = false
compact-inline-tables = false
newline-style = "LF"
To completely remove Taplo:
Delete
.taplo.tomlRemove Taplo commands from your
Justfile