clippy-advanced について
Rust 開発者向けの Clippy 設定ガイドで、リンティングの分類、カスタムルール、禁止項目、IDE 連携と CI チェックを扱います。コード規約の策定と維持を目的とし、フォーマット、ビルド、テストには使いません。
主な機能
- 01リンティング分類とレベルの設定
- 02clippy.toml のしきい値と禁止項目の設定
- 03Cargo ワークスペースの lint 設定
- 04CI チェックと出力形式の設定
- 05lint 抑制ルールの管理
活用シーン
- 01Rust プロジェクトのコード規約策定
- 02CI で lint 警告をエラーとして扱う
- 03プロジェクトで pedantic チェックを有効化
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ laurigates/ claude-plugins --skill clippy-advancedインストール後、Claude Code で/clippy-advancedを入力して読み込まれたか確認します。
同梱ファイルREFERENCE.md
詳細
clippy-advanced - 高度な Clippy 設定
カスタムルール、Lint カテゴリ、使用禁止メソッド、IDE 連携を含む、包括的な Rust Lint のための高度な Clippy 設定です。
このスキルを使用する場面
| このスキルを使用する場面... | 代わりに別のツールを使用する場面... |
|---|---|
| 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 | バグの可能性 | 拒否 |
clippy::complexity | 複雑すぎるコード | 警告 |
clippy::perf | パフォーマンスの問題 | 警告 |
clippy::style | コードスタイル | 警告 |
clippy::suspicious | 誤りに見えるコード | 警告 |
clippy::pedantic | 独自の見解に基づくスタイル | オフ |
clippy::restriction | オプトインの制約 | オフ |
clippy::nursery | 実験的な機能 | オフ |
clippy::cargo | Cargo.toml の問題 | オフ |
推奨される 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;
エージェント向けの最適化
| コンテキスト | コマンド |
|---|---|
| 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(...)] | Lint を抑制 |
| 警告 | #[warn(...)] | 警告を表示 |
| 拒否 | #[deny(...)] | コンパイルエラー |
参考資料
詳細な設定例、CI 連携、IDE のセットアップ、ベストプラクティスについては、REFERENCE.md を参照してください。
コメント
Markdown 対応