{"id":13671768,"url":"https://github.com/bnjbvr/cargo-machete","last_synced_at":"2025-05-15T09:00:22.527Z","repository":{"id":37096404,"uuid":"420777439","full_name":"bnjbvr/cargo-machete","owner":"bnjbvr","description":"Remove unused Rust dependencies with this one weird trick!","archived":false,"fork":false,"pushed_at":"2025-05-07T15:39:19.000Z","size":154,"stargazers_count":961,"open_issues_count":25,"forks_count":36,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-07T16:48:23.723Z","etag":null,"topics":["cargo","cargo-subcommand","rust","rust-lang"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bnjbvr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"liberapay":"bnjbvr"}},"created_at":"2021-10-24T19:33:47.000Z","updated_at":"2025-05-07T15:39:23.000Z","dependencies_parsed_at":"2023-02-12T22:31:21.380Z","dependency_job_id":"307cf861-6752-47e3-9fcf-f70990fe416a","html_url":"https://github.com/bnjbvr/cargo-machete","commit_stats":{"total_commits":80,"total_committers":10,"mean_commits":8.0,"dds":"0.19999999999999996","last_synced_commit":"d7532050f5d60321286883521a0b6b3bab55bccf"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjbvr%2Fcargo-machete","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjbvr%2Fcargo-machete/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjbvr%2Fcargo-machete/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bnjbvr%2Fcargo-machete/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bnjbvr","download_url":"https://codeload.github.com/bnjbvr/cargo-machete/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254310509,"owners_count":22049467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cargo","cargo-subcommand","rust","rust-lang"],"created_at":"2024-08-02T09:01:18.221Z","updated_at":"2025-05-15T09:00:22.498Z","avatar_url":"https://github.com/bnjbvr.png","language":"Rust","funding_links":["https://liberapay.com/bnjbvr"],"categories":["\u003ca name=\"Rust\"\u003e\u003c/a\u003eRust","Rust","Cargo Subcommands"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e\u003ccode\u003ecargo-machete\u003c/code\u003e\u003c/h1\u003e\n\n  \u003cp\u003e\n    \u003cstrong\u003eRemove unused Rust dependencies with this one weird trick!\u003c/strong\u003e\n  \u003c/p\u003e\n\n  \u003cp\u003e\n    \u003ca href=\"https://github.com/bnjbvr/cargo-machete/actions?query=workflow%3ARust\"\u003e\u003cimg src=\"https://github.com/bnjbvr/cargo-machete/workflows/Rust/badge.svg\" alt=\"build status\" /\u003e\u003c/a\u003e\n    \u003ca href=\"https://matrix.to/#/#cargo-machete:delire.party\"\u003e\u003cimg src=\"https://img.shields.io/badge/matrix-join_chat-brightgreen.svg\" alt=\"matrix chat\" /\u003e\u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/badge/rustc-stable+-green.svg\" alt=\"supported rustc stable\" /\u003e\n    \u003ca href=\"https://deps.rs/repo/github/bnjbvr/cargo-machete\"\u003e\u003cimg src=\"https://deps.rs/repo/github/bnjbvr/cargo-machete/status.svg\" alt=\"dependency status\"/\u003e\u003c/a\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n![](https://github.com/bnjbvr/cargo-machete/raw/main/logo.svg)\n\n*Thanks to [Diego F. Goberna](https://github.com/feiss) for the lovely logo 🥰*\n\n## Introduction\n\n`cargo-machete` is a Cargo tool that detects unused dependencies in Rust\nprojects, in a fast (yet imprecise) way.\n\nSee also the [blog post](https://blog.benj.me/2022/04/27/cargo-machete/) for a\ndetailed writeup.\n\n## Installation\n\nInstall `cargo-machete` with cargo:\n\n`cargo install cargo-machete`\n\n## Usage\n\nRun cargo-machete in a directory that contains one or more Rust projects (using Cargo for\ndependency management):\n\n```bash\ncd my-directory \u0026\u0026 cargo machete\n\n# alternatively\n\ncargo machete /absolute/path/to/my/directory\n```\n\nThe **return code** gives an indication whether unused dependencies have been found:\n\n- 0 if machete found no unused dependencies,\n- 1 if it found at least one unused dependency,\n- 2 if there was an error during processing (in which case there's no indication whether any unused\n  dependency was found or not).\n\nThis can be used in CI situations.\n\n### False positives\n\nTo ignore a certain set of dependencies in a crate, add\n`package.metadata.cargo-machete` to `Cargo.toml` (or `workspace.metadata.cargo-machete` to a\nworkspace `Cargo.toml`), and specify an `ignored` array:\n\nFor example:\n\n```toml\n[dependencies]\nprost = \"0.10\" # Used in code generated by build.rs output, which cargo-machete cannot check\n\n# in an individual package Cargo.toml\n[package.metadata.cargo-machete]\nignored = [\"prost\"]\n\n# in a workspace Cargo.toml\n[workspace.metadata.cargo-machete]\nignored = [\"prost\"]\n```\n\nIf there are too many false positives, consider using the `--with-metadata` CLI\nflag, which will call `cargo metadata --all-features` to find final dependency\nnames, more accurate dependencies per build type, etc. ⚠ This may modify the\n`Cargo.lock` files in your projects.\n\n### Renamed crates\n\nSome crates have a different import name, than their dependency name (e.g.\n`rustls-webpki`). This triggers false positives in `cargo-machete` when used\nwithout the `--with-metadata` flag. To fix this you can manually rename a crate\nfor `cargo-machete`:\n\nFor example:\n\n```toml\n[dependencies]\nrustls-webpki = \"0.102\"\n\n# in an individual package Cargo.toml\n[package.metadata.cargo-machete.renamed]\nrustls-webpki = \"webpki\"\n\n# in a workspace Cargo.toml\n[workspace.metadata.cargo-machete.renamed]\nrustls-webpki = \"webpki\"\n```\n\nThis ensures that if `rustls-webpki` is no longer used in the project,\n`cargo-machete` will be able to detect it (unlike with the `ignored` table).\n\n## Docker Image\n\nA docker image for cargo machete.\n\nFor instance, run `cargo-machete` in the `$(pwd)` directory using:\n\n```\ndocker run -v $(pwd):/src ghcr.io/bnjbvr/cargo-machete:latest\n```\n\n## Cargo Machete Action\n\nA github action for cargo machete.\n\n### Example usage\n\nThe step given by,\n```\n      - uses: bnjbvr/cargo-machete@main\n```\ncan be added to any workflow.\n\nAn example workflow is shown below:\n\n```yaml\nname: Cargo Machete\non:\n  pull_request: { branches: \"*\" }\n\njobs:\n  detect-unused-dependencies:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout\n        uses: actions/checkout@v4\n      - name: Machete\n        uses: bnjbvr/cargo-machete@main\n```\n\n## `pre-commit` Hooks\n\n`cargo machete` can be used as a [`pre-commit`](https://pre-commit.com/) hook to check for unused dependencies before committing changes.\n\nAdd the following to your `.pre-commit-config.yaml`:\n\n```yaml\n- repo: https://github.com/bnjbvr/cargo-machete\n  rev: main  # or a specific tag/commit\n  hooks:\n    - id: cargo-machete\n```\n\n## Contributing\n\n[![Contributor Covenant](https://img.shields.io/badge/contributor%20covenant-v1.4-ff69b4.svg)](https://www.contributor-covenant.org/version/1/4/code-of-conduct/)\n\nWe welcome community contributions to this project.\n\n## License\n\n[MIT license](LICENSE.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnjbvr%2Fcargo-machete","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbnjbvr%2Fcargo-machete","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbnjbvr%2Fcargo-machete/lists"}