Dự Án GitHub Hot: Boshen/cargo-shear – Remove unused dependencies in a Rust project

3 phút đọc

Dự Án GitHub Hot: Boshen/cargo-shear – Remove unused dependencies in a Rust project – Repository Boshen/cargo-shear (548 stars). Mô tả: Remove unused dependencies in a Rust project

1. Bối Cảnh & Thông Tin Chi Tiết

Detect and fix issues in Rust projects:

This tool is considered feature-complete. We continue to welcome contributions that focus on bug fixes, dependency upgrades, and UI/UX improvements.

Check for issues without making changes:

Automatically fix unused dependencies:

Treat warnings as errors (exit with failure code):

2. Phân Tích Diễn Biến & Tác Động Nổi Bật

This is useful for CI/CD pipelines to enforce strict checking of warnings such as empty files, unlinked files, and unused optional dependencies.

Generate machine-readable JSON output:

This is particularly useful for CI/CD pipelines and custom tooling that need to programmatically process the results.

Detect mismatches between [lib] target settings and source content:

When set, cargo-shear warns when test = false is paired with source that contains tests (or doctest = false with source that contains doc tests), and — within a workspace — when test / doctest are left at their default of true for lib targets that contain none. Disabled by default; pair with –fix to automatically reconcile the flags.

cargo shear cannot detect “hidden” imports from macro expansions without the –expand flag (nightly only).
This is because cargo shear uses rust-analyzer’s parser to parse files and does not expand macros by default.

The –expand flag uses cargo expand, which requires nightly and is significantly slower.

3. Góc Nhìn Chuyên Gia & Xu Hướng Tiếp Theo

Misplaced dependency detection only works for integration tests, benchmarks, and examples.
Unit tests dependencies within #[cfg(test)] cannot be detected as misplaced.

False positives can be ignored by adding them to the package’s Cargo.toml:

Unlinked files can be ignored using glob patterns:

Both options work in workspace Cargo.toml as well:

An ignore that suppresses nothing is reported as redundant so it can be removed. A
workspace ignore is considered redundant only when no member needs it — a dependency
that is used in one crate but unused in another stays covered by the workspace ignore.

cargo-hakari workspace-hack crates

cargo-hakari generates a workspace-hack crate that declares many dependencies it never imports (to unify Cargo features) and is depended on by every workspace member without being imported. cargo shear detects such a crate automatically — via the ### BEGIN HAKARI SECTION marker in its Cargo.toml — and skips both the crate itself and the dependency edges pointing at it, so no ignored configuration is needed.

Otherwise please report the issue as a bug.

4. Phân Tích Mã Nguồn & Ứng Dụng Thực Tế

Dự án này mang đến nhiều ưu điểm vượt trội cho cộng đồng lập trình viên và nhà phát triển phần mềm:

  • Tối ưu hóa kiến trúc: Cấu trúc mã nguồn rõ ràng, dễ dàng mở rộng và tích hợp vào các hệ thống sẵn có.
  • Cộng đồng hỗ trợ mạnh mẽ: Số lượng stars và contributors tăng trưởng nhanh chóng trên GitHub.
  • Tài liệu hướng dẫn đầy đủ: Giúp nhà phát triển nhanh chóng nắm bắt và triển khai thành công.

5. Tổng Kết Đánh Giá

Dự án là một giải pháp hữu ích rất đáng trải nghiệm cho các kỹ sư công nghệ trong năm 2026.

📆
Âm Lịch: 17/8
Giáp Thìn

📆 Lịch Âm Dương NsN

×
Hôm Nay - Chủ Nhật
Âm Lịch: 17 Tháng 8
Năm Bính Ngọ
📌 Ngày Can Chi: Giáp Thìn
✨ Giờ Hoàng Đạo: Dần (3-5), Thìn (7-9), Tỵ (9-11), Thân (15-17), Dậu (17-19), Hợi (21-23)
Vĩnh Phúc (Liên Bảo - Vĩnh Yên)
27°C
Nắng Đẹp
💧 89% | 💨 15 km/h
Hôm nay 32°
28/09 33°
29/09 34°
30/09 33°
01/10 31°