cargo-sort
cargo-sort copied to clipboard
Add dottet keys support
Hi! Thanks for the crate, it is really helpful.
I've found an issue: the app panics is there is a dotted keys
defined in Cargo.toml
.
Example:
Cargo.toml
:
[package]
name = "testt"
version = "0.1.0"
edition = "2021"
metadata.key = "test"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Actual behavior:
$ cargo sort ./Cargo.toml 1 ↵
Checking ....
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: TomlError { message: "TOML parse error at line 5, column 9\n |\n5 | metadata.key = \"test\"\n | ^\nUnexpected `.`\nExpected `=`\n" }', /home/andreyons/.cargo/registry/src/github.com-1ecc6299db9ec823/cargo-sort-1.0.5/src/sort.rs:113:46
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Expected behavior:
- The file is sorted.
Dotted keys are mentioned in TOML docs
Yeah, this is a problem, thanks for the detailed report!
Unfortunately this is a rather large effort because I vendored toml_edit
(I think that's the right term for copying a dependency into your own package) I haven't kept up with updates so cargo-sort
s version is behind. Here is the commit in toml_edit that added support for dotted keys https://github.com/ordian/toml_edit/commit/0ef47005ca5a835a28015d228fbd82535f1c841f. I did try to quickly update but it isn't going to be a quick thing :cry:. I would imagine updating the parsing
module and then adding support where it's needed in the files for the affected toml item kinds (array, item, inline-table, etc.) would be the least work and most straightforward way to do it.
I may have time in the next few weeks, or I could help if you were interested in a PR?
I would imagine updating the parsing module and then adding support where it's needed in the files for the affected toml item kinds (array, item, inline-table, etc.) would be the least work and most straightforward way to do it.
Do you mean update a parsing
module of the vendored toml_edit
or start using it from cargo?
I mean updating the vendored module with the latest toml_edit
. cargo-sort
needed too many weird specific changes to toml_edit
to upstream the changes which is why I copied and changed it as a module in cargo-sort.
Alternatively, it may be easier to just add this feature to the existing cargo-sort toml_edit module, but an update would be nice.
#29 should resolve this issue.
Sorry it has taken me so long.