Configs2026年5月18日·1 分钟阅读

Clippy — The Official Rust Lint Collection for Cleaner Code

Clippy is the official Rust linter maintained by the Rust project. It provides over 700 lints that catch common mistakes, enforce idiomatic patterns, and improve code quality in Rust projects.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Stage only · 17/100Stage only
Agent 入口
任意 MCP/CLI Agent
类型
CLI Tool
安装
Stage only
信任
信任等级:Established
入口
Clippy Rust Linter
通用 CLI 安装命令
npx tokrepo install bf3de5e6-52b5-11f1-9bc6-00163e2b0d79

Introduction

Clippy is the official lint tool for Rust, shipped as a rustup component. It analyzes your code for common mistakes, style issues, and performance pitfalls, providing actionable suggestions that help both beginners and experienced Rust developers write more idiomatic and correct code.

What Clippy Does

  • Provides over 700 lints organized into categories: correctness, style, complexity, performance, and pedantic
  • Catches common bugs like unused results, redundant clones, and incorrect iterator usage
  • Suggests idiomatic Rust patterns and simplifications for verbose code
  • Integrates with cargo as a first-class subcommand via cargo clippy
  • Supports auto-fix for many lints using cargo clippy --fix

Architecture Overview

Clippy is built as a compiler plugin that hooks into the Rust compiler's analysis passes. It runs after type checking and borrow checking, giving it access to the full type information and HIR (High-level Intermediate Representation). Each lint is implemented as a separate pass that walks the syntax tree looking for specific patterns. Clippy ships with each Rust toolchain release and is kept in sync with compiler internals.

Self-Hosting & Configuration

  • Install via rustup component add clippy on any Rust toolchain
  • Run cargo clippy in your project root to lint the entire workspace
  • Configure lint levels in Cargo.toml under [lints.clippy] or via #[allow()] and #[deny()] attributes
  • Use cargo clippy --fix to automatically apply safe suggestions
  • Add to CI with cargo clippy -- -D warnings to fail the build on any lint warning

Key Features

  • Official Rust project tool with guaranteed compatibility with each compiler release
  • Categories from permissive (style) to strict (correctness, nursery) for gradual adoption
  • Machine-applicable suggestions that integrate with cargo fix
  • Works on individual crates or entire cargo workspaces including dependencies
  • Extensive documentation with explanations and examples for every lint

Comparison with Similar Tools

  • rustfmt — formats code style; Clippy analyzes logic and patterns rather than whitespace
  • rust-analyzer — provides IDE features and some quick-fixes; Clippy offers deeper lint coverage
  • cargo-audit — scans for security vulnerabilities in dependencies; Clippy focuses on code quality
  • Miri — detects undefined behavior at runtime; Clippy catches issues statically at compile time
  • dylint — allows writing custom Rust lints; Clippy provides the standard curated set

FAQ

Q: Does Clippy produce false positives? A: Rarely. Most lints are well-tested, and you can suppress individual warnings with #[allow(clippy::lint_name)] when needed.

Q: Can I run Clippy only on changed files? A: Clippy respects cargo's incremental compilation, so only modified crates are re-checked. For CI, tools like cargo-nextest can parallelize.

Q: How do I enable stricter lints like pedantic? A: Add #![warn(clippy::pedantic)] to your crate root or configure it in Cargo.toml under [lints.clippy].

Q: Is Clippy required for publishing to crates.io? A: No, but many open-source Rust projects enforce Clippy in CI as a quality gate before merging.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产