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

bug: when sorting groups, if first element wasn't sorted, it will be moved to previous group #72

Open
nappa85 opened this issue Apr 8, 2024 · 0 comments

Comments

@nappa85
Copy link

nappa85 commented Apr 8, 2024

When sorting groups, if first element wasn't sorted, it will be moved to previous group.

E.g.:

 # Logging
 tracing = { workspace = true }
 tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
+barter-integration = { workspace = true }
 
 # Service
 prost = { workspace = true }
 prost-types = { workspace = true }
-tonic = { workspace = true, features = ["transport"] }
 reqwest = { workspace = true, default-features = false }
+tonic = { workspace = true, features = ["transport"] }
 tower-http = { workspace = true, features = ["cors"] }
-barter-integration = { workspace = true }
Calsign added a commit to AutoPallet/cargo-sort that referenced this issue Dec 20, 2024
…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 added a commit to AutoPallet/cargo-sort that referenced this issue Dec 20, 2024
…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 added a commit to AutoPallet/cargo-sort that referenced this issue Dec 20, 2024
…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 added a commit to AutoPallet/cargo-sort that referenced this issue Dec 20, 2024
…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.
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

1 participant