Keep your cargo workspace neat
A command to complement existing tools like cargo-machete when working with a Cargo workspace.
Features:
- detect unused dependencies in
workspace.dependencieswhen working with a cargo workspace - optionally enforce using only workspace dependency in your project (
-moption) - optionally enforce using only workspace metadata for some sections in workspace packages (
-poption). Metadata section values can be customized and currently defaults to--package-workspace-meta-values "rust-version,edition,license,homepage,repository"
Install with cargo:
cargo install cargo-neat --lockedcd my-directory && cargo neator alternatively
cargo neat my-directorycargo neat -m -p my-workspace
Unused workspace dependencies :
└── /home/user/my-workspace/Cargo.toml
├── anyhow
└── clappen
Non workspace dependencies :
├── /home/user/my-workspace/crate1/Cargo.toml
│ ├── argh
│ └── futures-lite
└── /home/user/my-workspace/crate2/Cargo.toml
└── clap
Non workspace metadata :
├── /home/user/my-workspace/crate1/Cargo.toml
└── editionThe return code gives an indication whether unused dependencies have been found:
- 0 if it found no unused dependencies,
- 1 if it found at least one unused dependency,
- 2 if there was an error during processing (in which case there's no indication whether any unused dependency was found or not).
A lot of the code structure is drawn from the great cargo-machete. If you don't already use it, you probably should.
- est31/cargo-udeps: slow and requires Nightly rust, has no workspace features
- bnjbvr/cargo-machete: fast but does not remove unused workspace dependencies
- Boshen/cargo-shear: removes unused workspace dependencies, and can fix wrong dependency section, but cannot enforce using workspace dependencies only
I would need a mix of cargo-machete/shear and cargo-neat. However cargo-shear is marked feature complete and not accepting new features, so here is cargo-neat.