Giter VIP home page Giter VIP logo

cargo-machete's Introduction

cargo-machete

Remove unused Rust dependencies with this one weird trick!

build status matrix chat supported rustc stable

Introduction

cargo-machete is a Cargo tool that detects unused dependencies in Rust projects, in a fast (yet imprecise) way.

See also the blog post for a detailed writeup.

Installation

Install cargo-machete with cargo:

cargo install cargo-machete

Usage

Run cargo-machete in a directory that contains one or more Rust projects (using Cargo for dependency management):

cd my-directory && cargo machete

# alternatively

cargo machete /absolute/path/to/my/directory

The return code gives an indication whether unused dependencies have been found:

  • 0 if machete 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).

This can be used in CI situations.

False positives

To ignore a certain set of dependencies in a crate, add package.metadata.cargo-machete to Cargo.toml, and specify an ignored array:

For example:

[dependencies]
prost = "0.10" # Used in code generated by build.rs output, which cargo-machete cannot check

[package.metadata.cargo-machete]
ignored = ["prost"]

If there are too many false positives, consider using the --with-metadata CLI flag, which will call cargo metadata --all-features to find final dependency names, more accurate dependencies per build type, etc. โš  This may modify the Cargo.lock files in your projects.

Contributing

Contributor Covenant

We welcome community contributions to this project.

License

MIT license.

cargo-machete's People

Contributors

bnjbvr avatar tottoto avatar dependabot[bot] avatar tgnottingham avatar daniel5151 avatar bromeon avatar lorenzschueler avatar realkc avatar spenserblack avatar 0xdeafbeef avatar nanocryk avatar xxchan avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.