Open
Description
I actually use a very very small tool toml-fmt, I currently use it like:
toml-fmt < Cargo.toml > Cargo.toml.new && mv Cargo.toml.new Cargo.toml
That not very practical and I must remember to use it. Could rustfmt handle it too ? I think Cargo.toml
is also a part of rust file so maybe it's ok to add it.
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
calebcartwright commentedon Mar 31, 2020
That's an interesting idea @Stargateur
Formatting toml files is outside rustfmt's scope (at least currently), though I can see how having the optional/opt-in ability to format toml files would be beneficial.
prettier
also supports formatting json and yaml files in addition to JavaScript and TypeScript, so it's not completely unheard of.How would you envision the behavior when running
cargo fmt
in a multi-crate workspace? Would the expectation be thatcargo fmt
would support formatting all the detected Cargo.toml files in the workspace?Stargateur commentedon Apr 1, 2020
I guess the same that the actual behaviour, if the actual behaviour is to format all detected rust file in a workspace than yes, if no than no.
calebcartwright commentedon Apr 11, 2020
It looks like the Style Guide actually already includes a spec for Cargo.toml, so IMO formatting Cargo.toml files accordingly is something that rustfmt should indeed support.
There's a few things to think through (default behavior, cli args/opts, configurable via rustfmt.toml, etc.) but it should be a fun project if anyone is interested in working on it!
gilescope commentedon Sep 3, 2020
You could start small and gradually crank it up. Alphabetical ordering of blocks of dependencies (with newlines demarcating different blocks of dependencies) would be good.
Adding spaces around dependencies. I.e. foo = "1.2" rather than foo="1.2".
Those two would probably be 80% of the file sorted out nicely - the dependencies are going to have the most change so they are the areas that benefit the most from consistency.
srinikhil-07 commentedon Nov 8, 2020
@calebcartwright
Can I try this one following yours and @gilescope directions?
calebcartwright commentedon Nov 20, 2020
@Nikhil0487 - absolutely! I suspect this may end up being a sizeable effort, but can likely be developed iteratively. I still don't have a feel for what the end state would look like from an experience/usability perspective, nor have I really had the bandwidth to think on it.
As such I'd advise starting with the formatting logic (something that takes in an unformatted string and returns a formatted one) and we'll figure out the rest later on. Feel free to put this in a new mod under
src/formatting
thomaseizinger commentedon Nov 20, 2020
For people watching this issue, I've developed a
dprint
plugin that does some formatting ofCargo.toml
files: https://github.com/thomaseizinger/dprint-plugin-cargo-tomldprint also has a rustfmt plugin which means you can have a single tool for all your formatting needs :)
rustfmt.toml
paritytech/substrate#8982cargofmt
to clean up cargo.toml files paritytech/cargo-unleash#7gilescope commentedon Aug 12, 2021
I notice that vscode is formatting Cargo.toml if I do format on save. But I'm not sure how - is that rust-analyzer or the better-toml extension or something else?
mati865 commentedon Aug 12, 2021
@gilescope it's "Even Better TOML" extension who does that. Link to the GitHub project: https://github.com/tamasfe/taplo
56 remaining items