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

Regression: [rule.formatting] completely overrides the default outside of the specified sections #634

Closed
rami3l opened this issue Jul 14, 2024 · 6 comments

Comments

@rami3l
Copy link

rami3l commented Jul 14, 2024

Hi there, and thanks for making this wonderful project!

The Rustup team is trying to use taplo across our project, however we have encountered the following regression after trying to upgrade taplo to v0.9.2 (from v0.9.0):

With the following .taplo.toml on taplo v0.9.2:

include = ["**/*.toml"]

[[rule]]
include = ["**/Cargo.toml"]
keys = [
  "dependencies",
  "dev-dependencies",
  "build-dependencies",
  "workspace.dependencies",
]

[rule.formatting]
reorder_keys = true

... and the following (minimal reproduction) Cargo.toml:

[package]
name = "rustup"
version = "1.27.1"
edition = "2021"
description = "Manage multiple rust installations with ease"
homepage = "https://github.com/rust-lang/rustup"
keywords = ["rustup", "multirust", "install", "proxy"]
license = "MIT OR Apache-2.0"
readme = "README.md"
repository = "https://github.com/rust-lang/rustup"
build = "build.rs"

[dependencies]
chrono = { version = "0.4", default-features = false, features = ["std"] }
anyhow.workspace = true
cfg-if = "1.0"
clap = { version = "4", features = ["derive", "wrap_help"] }

... you can see that after taplo fmt, the keys in the [dependencies] section are sorted alphabetically (as expected). However, the keys in the [package] section are also reordered (which is not the case for v0.9.0):

[package]
build = "build.rs"
description = "Manage multiple rust installations with ease"
edition = "2021"
homepage = "https://github.com/rust-lang/rustup"
keywords = ["rustup", "multirust", "install", "proxy"]
license = "MIT OR Apache-2.0"
name = "rustup"
readme = "README.md"
repository = "https://github.com/rust-lang/rustup"
version = "1.27.1"

[dependencies]
anyhow.workspace = true
cfg-if = "1.0"
chrono = { version = "0.4", default-features = false, features = ["std"] }
clap = { version = "4", features = ["derive", "wrap_help"] }

Many thanks in advance!

@rami3l
Copy link
Author

rami3l commented Jul 14, 2024

There aren't many changes between these two versions, after a quick scan I suspect #527 to be problematic... But I could be wrong.

@gillyobeast
Copy link

As a workaround, adding an explicit rule to stop reordering keys in "package" seems to work:

[[rule]]
keys = ["package"]
formatting.reorder_keys = false

@panekj panekj closed this as completed in 4d08035 Jul 27, 2024
@rami3l
Copy link
Author

rami3l commented Jul 27, 2024

@panekj Thanks for the reverting action!

However, I'm not 100% sure #527 has caused this problem, so maybe adding a regression test would help? Please feel free to use the minimal reproduction data above.

@panekj
Copy link
Collaborator

panekj commented Jul 27, 2024

I bisected the problem to that commit

@rami3l
Copy link
Author

rami3l commented Jul 31, 2024

@panekj Many thanks! Do you have any plans for an upcoming taplo-cli v0.9.3 including this fix, or it's happening right now?

@panekj
Copy link
Collaborator

panekj commented Jul 31, 2024

https://github.com/tamasfe/taplo/releases/tag/0.9.3

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