Any auto formatter for toml?

  1. Do people use auto formatter for Cargo.toml?
  2. Any good formatter that do not make toml less readable?
  3. Any toml formatter that preserve comments?

Searched on crates.io, one way is to call toml::ser::to_string,
which generates less readable toml like this

[dependencies.serde]
workspace = true

[dependencies.serde_json]
workspace = true

While I prefer to

[dependencies]
serde.workspace = true
serde_json.workspace = true
1 Like

I use GitHub - tamasfe/taplo: A TOML toolkit written in Rust with the following configuration

[formatting]
align_comments = false
reorder_keys = true

[[rule]]
include = ["**/Cargo.toml"]
keys = ["package"]

[rule.formatting]
reorder_keys = false
3 Likes

in addition to the standalone cli tool, there's a vscode extension too: Even Better TOML

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.