Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dottet keys support #26

Open
sokyrko opened this issue Oct 28, 2021 · 5 comments
Open

Add dottet keys support #26

sokyrko opened this issue Oct 28, 2021 · 5 comments

Comments

@sokyrko
Copy link

sokyrko commented Oct 28, 2021

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

@DevinR528
Copy link
Owner

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-sorts version is behind. Here is the commit in toml_edit that added support for dotted keys toml-rs/toml@0ef4700. I did try to quickly update but it isn't going to be a quick thing 😢. 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?

@sokyrko
Copy link
Author

sokyrko commented Oct 28, 2021

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?

@DevinR528
Copy link
Owner

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.

@DevinR528
Copy link
Owner

#29 should resolve this issue.

Sorry it has taken me so long.

sancane added a commit to sancane/precis that referenced this issue Oct 5, 2023
There is an issue with dotted key support
DevinR528/cargo-sort#26
@kyrias
Copy link

kyrias commented Jun 14, 2024

The main branch seems to work as expected to me, so is there anything currently blocking getting a release out? It's especially annoying now with cargo new defaulting to using this style for new workspace member crates.

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

No branches or pull requests

3 participants