boshen / cargo-shear Goto Github PK
View Code? Open in Web Editor NEWDetect and remove unused dependencies from Cargo.toml
License: MIT License
Detect and remove unused dependencies from Cargo.toml
License: MIT License
Hi Boshen. I mean this library is so awesome!
I'm now working on removing unused dependencies using cargo-shear
, and found a bug. I hope you'll check it.
Tisis the issue im working on: biomejs/biome#2136
cargo-shear
removes quickcheck
even if it is checked
log
error[E0433]: failed to resolve: could not find `quickcheck` in the list of imported crates
--> crates/biome_json_parser/src/lexer/tests.rs:63:1
|
63 | #[quickcheck]
| ^^^^^^^^^^^^^ could not find `quickcheck` in the list of imported crates
|
= note: this error originates in the attribute macro `quickcheck` (in Nightly builds, run with -Z macro-backtrace for more info)
For more information about this error, try `rustc --explain E0433`.
error: could not compile `biome_json_parser` (lib test) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
In the "Prior Arts" section you mention two alternatives, how they differ?
Thanks for this nice project, we are using a dirty script for checking it:
https://github.com/nervosnetwork/ckb/blob/develop/devtools/ci/check-cargotoml.sh
I have a try on cargo-shear
, seems there are 3 false positive warnings, here is how to reproduce it:
git clone https://github.com/nervosnetwork/ckb.git
cd ckb
cargo shear --fix
make check [here we will see the compiling error after fix]
Some crates defines their module names in [lib] name
.
e.g.
Found in https://github.com/getsentry/sentry-cli
We need to extend the manifest to include the lib name https://docs.rs/cargo_toml/latest/cargo_toml/struct.Manifest.html#method.complete_from_path_and_workspace
From cargo-machette:
Analyzing dependencies of crates in this directory...
cargo-machete found the following unused dependencies in .:
rspack_binding_values -- ./crates/rspack_binding_values/Cargo.toml:
rspack_identifier
Done!
If you believe cargo-machete has detected an unused dependency incorrectly,
you can add the dependency to the list of dependencies to ignore in the
`[package.metadata.cargo-machete]` section of the appropriate Cargo.toml.
For example:
[package.metadata.cargo-machete]
ignored = ["prost"]
if a package is only used to build an example, not the main library, it should be in the dev-dependencies section so that users of that library don't download it unnecessarily.
cargo-shear should be able to warn of and fix such dependencies.
I only considered normal dependencies
Lines 140 to 141 in fbe33ba
When performing with success a fix cargo shear --fix
the exit code is 1, even if the fix is successful and there is no unused dependencies at the end.
When performing with success a fix cargo shear --fix
the exit code is 0 when there is no unused dependencies at the end.
We can have automatic hooks that will fail even though the fix operation is successful. It's the behavior of other tools like eslint or biome.
Thanks for your work!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.