-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
Labels
Description
What it does
I'm not sure if it is a Clippy responsibility, but I think it would be nice to suggest to use "workspace dependencies" if some library is used in multiple workspace crates.
Perhaps the opposite changes can be suggested if a dependency is used only once or less than some threshold value, though this logic should probably be a separate lint. Ideally both values should be configurable.
Lint Name
workspace_dependencies
Category
pedantic
Advantage
- It is much more convenient to change the dependency version in one place.
Drawbacks
The only disadvantage I can see is that such lint can be noisy for small workspaces, so it probably should be disabled by default.
Example
I don't think this example is needed, but nevertheless:
# [PROJECT_DIR]/Cargo.toml
[workspace]
members = ["foo", "bar"]
# [PROJECT_DIR]/foo/Cargo.toml
[package]
name = "foo"
[dependencies]
rand = "0.8.5"
# [PROJECT_DIR]/bar/Cargo.toml
[package]
name = "bar"
[dependencies]
rand = "0.8.5"
Could be written as:
# [PROJECT_DIR]/Cargo.toml
[workspace]
members = ["foo", "bar"]
[workspace.dependencies]
rand = "0.8.5"
# [PROJECT_DIR]/foo/Cargo.toml
[package]
name = "foo"
[dependencies]
rand.workspace = true
# [PROJECT_DIR]/bar/Cargo.toml
[package]
name = "bar"
[dependencies]
rand.workspace = true
kraktus, Mathieu-Lala, extrawurst, heaths, 0xJepsen and 1 more