DevinR528 / cargo-sort

Check if tables and items in a .toml file are lexically sorted
214 stars 29 forks source link

Feature request: normalize tables #37

Open ModProg opened 2 years ago

ModProg commented 2 years ago

I'd like an option, turning inline tables into normal tables, and vice versa.

So from

[dependencies]
serde = {version = "1", features = ["derive"]}

[dependencies.log]
version = "0.4"
features = ["std"]

to

[dependencies]
serde = {version = "1", features = ["derive"]}
log = { version = "0.4", features = ["std"]}

or

[dependencies.serde]
version = "1" 
features = ["derive"]

[dependencies.log]
version = "0.4"
features = ["std"]

Depending on the flag / config given.

DevinR528 commented 2 years ago

I would be fine with adding this with a command-line flag, I think that would be a cool addition! I don't have a whole lot of extra time but would be able to help if you were interested in opening a PR, otherwise, it might be a while till I got to it?

A question, would you specify the names like cargo sort --merge log,serde or would the merge/expand inline tables be a general thing and work on any inline table or any table with a dot in the header of dependency, dev-dep, etc?

ModProg commented 2 years ago

I would say something like a max_width, either in characters or in fields. like values below get merged into one line and those above get promoted to real tables.

And for the extremes just set it to 0 or usize::MAX.

DevinR528 commented 2 years ago

I guess this isn't really outside the scope since cargo sort has to know all about formatting because anytime you reorder something you also have to format.

I will have time to work on these few issues someday soonish hopefully.