rust-lang / rust-lang/rust-clippy
Workspace dependencies
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the workspace Cargo.toml, foo/Cargo.toml, and bar/Cargo.toml examples in the issue, then review how Clippy lints inspect Cargo workspace metadata. Define the detection, configurability, default category, and inverse-case behavior before implementation. Done means a lint can identify repeated dependencies and provide appropriate workspace-dependency suggestions with tests covering the stated examples.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100