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

Fix #72: --grouped handling when reording the first entry in a group. #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Calsign
Copy link

@Calsign Calsign commented Dec 20, 2024

#72

Currently cargo-sort is broken with --grouped for situations where the first entry in a group gets reordered within the group, such as the following example:

[package]
name = "foobar"
version = "0.1.0"
edition = "2021"

[dependencies]
a = { workspace = true }
b = { workspace = true }

d = { workspace = true }
c = { workspace = true }

Current behavior produces the following output:

[package]
name = "foobar"
version = "0.1.0"
edition = "2021"

[dependencies]
a = { workspace = true }
b = { workspace = true }
c = { workspace = true }

d = { workspace = true }

This is because the newline separating the groups is attached to the decor for d, and it stays with d even as c and d change places.

This doesn't apply to the example above, but it's also possible for this behavior to introduce non-idempotency since the new first item gets attached to the previous group and it may get resorted within that group the next time cargo-sort is run.

I added a test for the correct behavior.

@Calsign Calsign force-pushed the fix-group-sorting-first-item branch 2 times, most recently from 82e8287 to 54c1a6e Compare December 20, 2024 18:24
…in a group.

DevinR528#72

Currently cargo-sort is broken with `--grouped` for situations where the first entry
in a group gets reordered within the group, such as the following example:

```toml
[package]
name = "foobar"
version = "0.1.0"
edition = "2021"

[dependencies]
a = { workspace = true }
b = { workspace = true }

d = { workspace = true }
c = { workspace = true }
```

Current behavior produces the following output:

```toml
[package]
name = "foobar"
version = "0.1.0"
edition = "2021"

[dependencies]
a = { workspace = true }
b = { workspace = true }
c = { workspace = true }

d = { workspace = true }
```

This is because the newline separating the groups is attached to the decor for `d`,
and it stays with `d` even as `c` and `d` change places.

This doesn't apply to the example above, but it's also possible for this behavior
to introduce non-idempotency since the new first item gets attached to the previous
group and it may get resorted within that group the next time cargo-sort is run.

I added a test for the correct behavior.
@Calsign Calsign force-pushed the fix-group-sorting-first-item branch from 54c1a6e to 614dbe6 Compare December 20, 2024 19:01
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

Successfully merging this pull request may close these issues.

1 participant