cargo-sort icon indicating copy to clipboard operation
cargo-sort copied to clipboard

package.metadata sorting

Open glueball opened this issue 6 months ago • 3 comments

Greetings,

I don't know if this is a support ticket or a feature request...

I'd like to have package metadata at the end of the file (for instance, [package.metadata.docs.rs]). I'm trying with something like this in tomlfmt.toml:

table_order = [
    "workspace",
    "workspace.members",
    "workspace.exclude",
    "package",
    "features",
    "dependencies",
    "lints.clippy",
    "package.metadata.docs.rs",
]

But whatever I do, cargo-sort doesn't seem to match the package.metadata section. In this setup, the metadata always goes just after the package section. If I don't specify package, then it goes at the very end.

Surprisingly, something like this makes both the package header (expected) and the metadata (unexpected, to me) go to the very end.

table_order = [
    "package.metadata.docs.rs",
    "workspace",
    "workspace.members",
    "workspace.exclude",
    "package",
    "features",
    "dependencies",
    "lints.clippy",
]

I don't know if I'm doing something wrong, or maybe this is by design.

If this is something not taken into account, then please consider this as a feature request. In that case, with some guidance, specially on the feature design, and if my skill levels allow me, I might try to contribute a PR (don't know in which timeframe, maybe during summer).

glueball avatar Jun 21 '25 12:06 glueball

I don't think dotted keys do what you think they do within table_order. I would consider this a feature request ^^

jplatte avatar Jun 21 '25 14:06 jplatte

Thanks!

So, would you guys be open to a contribution of something like this? If so, I'd be happy to give it a try when time permits (don't know when). Maybe toml_edit (and the toml spec itself) don't make it very easy, but there might be a way that doesn't feel too hacky.

glueball avatar Jun 22 '25 08:06 glueball

I think it might not actually be that hard and yes, a PR would be welcome :)

jplatte avatar Jun 22 '25 09:06 jplatte