Skip to content

Conversation

orf
Copy link

@orf orf commented Nov 8, 2024

Quite often you want to keep the overall structure of a TOML file, but sort the keys within. For example, a Cargo.toml file:

[package]
name = "xyz"

[dependencies]
tokio = {version = "1.38.0", features = ["full"]}
clap = {version = "4.5.4", features = ["derive", "env"]}

Right now this will be re-formatted as

[dependencies]
clap = {version = "4.5.4", features = ["derive", "env"]}
tokio = {version = "1.38.0", features = ["full"]}

[package]
name = "xyz"

Which is annoying - I'd like to keep the [package] table at the top, but just sort the keys (dependencies, mostly) within:

[package]
name = "xyz"

[dependencies]
clap = {version = "4.5.4", features = ["derive", "env"]}
tokio = {version = "1.38.0", features = ["full"]}

This MR adds a flag to support this.

@thclark
Copy link

thclark commented Jun 18, 2025

Would love to see this merged! Usually there's only one you want at the top; typically [package] (rust) or [project] (for pyproject.toml) that by convention you want to have access to right at the top of the file.

@macisamuele macisamuele enabled auto-merge June 24, 2025 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants