rust-clippy
Skill8 starsChanged 17 days agoApache-2.0View on GitHub
使用 cargo clippy 对 Rust 代码做静态分析,并通过 cargo fix 自动修复。适用于 Rust 项目规范检查、缺陷与性能问题发现、CI 质量门禁。
In this repository32 other files it gives its agents.
- AGENTS.mdAGENTS.md
- ast-grep-blockSkill
- code-deconstructSkill
- code-detect-dupSkill
- code-detect-problemSkill
- code-part-modificationSkill
- code-refactorSkill
- code-reviewSkill
- cpp-checkSkill
- cpp-clang-tidySkill
- cpp-tscancodeSkill
- full-analysisSkill
- gdb-heap-analysisSkill
- java-asprofSkill
- java-check-pmdSkill
- java-check-spotbugsSkill
- java-coverageSkill
- java-envSkill
- java-g2mSkill
- jmh-benchSkill
- lets-loopSkill
- long-term-taskSkill
- md2pdfSkill
- merge-agents-mdSkill
- qualitative-assessmentSkill
- requirement-collectSkill
- rust-flamegraphSkill
- shell-checkSkill
- sql-extractSkill
- sync-dev-specSkill
- sync-repo-docsSkill
- vbox-test-envSkill
The file
Files
Rust Clippy 静态分析技能
本文件中的
templates/...均指本技能目录下的templates/子目录。
执行流程
步骤1:确定项目路径
PROJECT_DIR=. # Rust 项目根目录(包含 Cargo.toml)步骤2:执行 Clippy 检查
cargo clippy # 基础检查
cargo clippy --all-targets # 含测试、示例
cargo clippy -p <package_name> # 特定包
cargo clippy -- --deny warnings # 严格模式
cargo clippy -- --allow <lint_name> # 允许特定 lint
cargo clippy -- --deny <lint_name> # 禁止特定 lint步骤3:自动修复
cargo clippy --fix # 安全修复
cargo clippy --fix --allow-dirty --allow-staged # 允许语义变更修复
cargo clippy --all-targets # 验证修复结果步骤4:输出与报告
cargo clippy --message-format=json > clippy-report.json # JSON
cargo clippy --message-format=short # 简短报告模板见 templates/report.md。
Lint 级别与组
| 级别 | 描述 | 组名 | 严格程度 |
| allow | 允许,不提示 | clippy::all(默认) | 适中 |
| warn | 警告 | clippy::pedantic | 严格 |
| deny | 错误,阻止编译 | clippy::correctness | 严格 |
| forbid | 禁止,无法覆盖 | clippy::restriction | 最严格 |
其他组:style(宽松)、complexity(适中)、perf(适中)、cargo(宽松)、nursery(不稳定)。
启用/禁用 Lint
命令行
cargo clippy -- --clippy::pedantic
cargo clippy -- --allow clippy::too_many_arguments
cargo clippy -- --clippy::pedantic --deny clippy::unwrap_used代码内属性
#![warn(clippy::pedantic)]
#![allow(clippy::too_many_lines)]
#[allow(clippy::too_many_arguments)]
fn complex_function(a: i32, b: i32, c: i32, d: i32, e: i32) {}Cargo.toml 配置
[lints]
workspace = true
[workspace.lints.clippy]
pedantic = "warn"
unwrap_used = "deny"
too_many_arguments = "allow"CI 集成
模板见 templates/ 目录:
ci-github-actions.yaml— GitHub Actionsci-pre-commit.yaml— pre-commit hookMakefile— Make 目标
分析结果处理
# 统计 lint 类型
cargo clippy --message-format=json 2>/dev/null | \
jq -r 'select(.message != null) | .message.code | .code // empty' | \
sort | uniq -c | sort -nr
# 提取错误级别
cargo clippy --message-format=json 2>/dev/null | \
jq -r 'select(.message != null and .message.level == "error") | .message.rendered'典型场景
| 场景 | 命令 |
| 快速检查 | cargo clippy --all-targets |
| CI 严格模式 | cargo clippy --all-targets -- --deny warnings |
| 渐进式采用 | --fix → --warn clippy::pedantic → --deny clippy::unwrap_used |
| 修复后验证 | cargo clippy --fix --allow-dirty && cargo clippy --all-targets -- --deny warnings && cargo test |
最佳实践
- CI 中 deny warnings
- 渐进式采用:从
clippy::all到pedantic - 自动修复优先:先用
--fix - 合理例外用
#[allow()]并附注释 - 先 rustfmt 再 clippy
- 定期
rustup update
注意事项
--fix可能改变语义,修复后务必测试nursery组不稳定,可能变化restriction需手动启用- 与
#[deny(warnings)]冲突时 clippy 警告也会被拒绝
技能版本: 1.0.0 | 工具: cargo clippy | 适用: Rust 项目
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

