mcpField
C
clippy-advanced

clippy-advanced

github.com/laurigates测试与质量59106 次安装1 天前更新
代码仓库

关于 clippy-advanced

为 Rust 开发者提供 Clippy 配置指导,涵盖 lint 类别、自定义规则、禁用项及 IDE 集成,并说明 CI 检查方式。适用于建立和维护项目代码规范,不用于格式化、构建或测试。

主要功能

  1. 01配置 lint 类别与级别
  2. 02设置 clippy.toml 阈值和禁用项
  3. 03使用 Cargo 工作区 lint 配置
  4. 04配置 CI 检查与输出格式
  5. 05管理 lint 抑制规则

适用场景

  1. 01为 Rust 项目制定代码规范
  2. 02在 CI 中将 lint 警告视为错误
  3. 03按项目需要启用 pedantic 检查

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/laurigates/claude-plugins --skill clippy-advanced

安装后在 Claude Code 中输入/clippy-advanced确认已加载。

附带文件REFERENCE.md

详细介绍

clippy-advanced - 高级 Clippy 配置

用于全面 Rust lint 检查的高级 Clippy 配置,包括自定义规则、lint 类别、禁用方法和 IDE 集成。

何时使用此技能

在以下情况下使用此技能……在以下情况下改用其他工具……
配置 Clippy lint 规则格式化代码(使用 rustfmt)
为 Rust 设置 CI lint 检查构建/编译(使用 cargo build)
自定义 clippy.toml运行测试(使用 cargo test)
强制执行代码标准管理依赖项(使用 cargo add)

安装

# Clippy is included with rustup
rustup component add clippy

# Verify installation
cargo clippy --version

# Update clippy with rust toolchain
rustup update

基本用法

# Run clippy on current project
cargo clippy

# Run on all targets (lib, bins, tests, examples, benches)
cargo clippy --all-targets

# Run with all features enabled
cargo clippy --all-features

# Run on workspace
cargo clippy --workspace --all-targets --all-features

# Show detailed lint explanations
cargo clippy -- -W clippy::all -A clippy::pedantic

# Treat warnings as errors
cargo clippy -- -D warnings

Lint 类别

类别用途默认值
clippy::correctness可能存在的错误Deny
clippy::complexity过于复杂的代码Warn
clippy::perf性能问题Warn
clippy::style代码风格Warn
clippy::suspicious看起来有问题的代码Warn
clippy::pedantic主观性较强的风格规则Off
clippy::restriction选择性启用的约束Off
clippy::nursery实验性规则Off
clippy::cargoCargo.toml 问题Off
推荐的 Cargo.toml 配置
[workspace.lints.clippy]
# Deny correctness issues (likely bugs)
correctness = "deny"
complexity = "warn"
perf = "warn"
style = "warn"
suspicious = "warn"

# Enable pedantic but allow some noisy lints
pedantic = "warn"
must_use_candidate = "allow"
missing_errors_doc = "allow"

# Enable some restriction lints selectively
clone_on_ref_ptr = "warn"
dbg_macro = "warn"
print_stdout = "warn"
todo = "warn"
unimplemented = "warn"
unwrap_used = "warn"

# Enable nursery lints (experimental)
use_self = "warn"

clippy.toml 必要设置

在项目根目录创建 clippy.toml,用于设置阈值和禁用项:

cognitive-complexity-threshold = 15
too-many-lines-threshold = 100
too-many-arguments-threshold = 5

disallowed-methods = [
  { path = "std::env::var", reason = "Use std::env::var_os for better Unicode handling" },
  { path = "std::process::exit", reason = "Use Result propagation instead" },
]

disallowed-names = ["foo", "bar", "baz"]

抑制 Lint

// Function-level
#[allow(clippy::too_many_arguments)]
fn complex_function(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) {}

// Module-level (src/lib.rs)
#![warn(clippy::all)]
#![warn(clippy::pedantic)]
#![deny(clippy::unwrap_used)]
#![allow(clippy::module_name_repetitions)]

// Inline
#[allow(clippy::cast_possible_truncation)]
let x = value as u8;

Agentic 优化

场景命令
CI 严格模式cargo clippy --workspace --all-targets -- -D warnings
JSON 输出cargo clippy --message-format=json
精简错误信息cargo clippy --message-format=short
快速检查cargo clippy --message-format=short -- -D warnings
Pedantic 检查cargo clippy -- -W clippy::pedantic -D clippy::correctness

快速参考

命令行标志
标志描述
--all-targets检查库、二进制文件、测试、示例和基准测试
--all-features启用所有功能
--workspace检查整个工作区
--message-format=json为工具提供 JSON 输出
--message-format=short精简错误格式
-- -D warnings将警告视为错误
-- -W clippy::pedantic启用 pedantic lint
-- -A clippy::lint_name放行指定的 lint
Lint 级别
级别属性效果
Allow#[allow(...)]抑制 lint
Warn#[warn(...)]显示警告
Deny#[deny(...)]编译错误

参考资料

详细的配置示例、CI 集成、IDE 设置和最佳实践,请参阅 REFERENCE.md。

评论

支持 Markdown