Detect and remove unused dependencies from Cargo.toml
in Rust projects.
cargo install cargo-shear
cargo shear --fix
- use the
cargo_metadata
crate to list all dependencies specified in[workspace.dependencies]
and[dependencies]
- iterate through all package targets to locate all Rust files
- use
syn
to parse these Rust files and extract imports - identify the difference between the imports and the package dependencies
- make the reporting more granular for
[dependencies]
,[dev-dependencies]
and[build-dependencies]
-
--fix
the root Cargot.toml - add tests
- exit codes
- error recovery
- print things more nicely