rust-lint
Automatically format Rust files with rustfmt and provide on-demand clippy linting
View on GitHubTable of content
Automatically format Rust files with rustfmt and provide on-demand clippy linting
Installation
npx claude-plugins install @cheolwanpark/personal-curation/rust-lint
Contents
Folders: commands, hooks, scripts, tests
Files: README.md
Documentation
Automatically format Rust files with rustfmt and provide on-demand comprehensive linting with clippy.
Features
- โ
Auto-formatting: Automatically formats
.rsfiles on every edit/write usingrustfmt - ๐ Fast hook execution: Hook completes in <2s (formatting only, no compilation)
- ๐ Comprehensive linting: On-demand project-wide clippy analysis via slash command
- ๐๏ธ Workspace support: Automatically detects and handles Cargo workspaces
- ๐งน Isolated builds: Build artifacts stored in
/tmpto avoid project pollution - ๐ก๏ธ Graceful degradation: Clear error messages when tools are missing
- ๐ Detailed reports: Markdown-formatted reports with file:line:column references
Why This Architecture?
Unlike ESLint or Ruff, clippy requires full cargo compilation and can take 5-30+ seconds even on small projects. Running clippy on every file save would make the editor unresponsive.
Our solution:
- Hook (PostToolUse): Fast rustfmt-only formatting (<2s)
- Command (
/rust-lint:lint-project): Comprehensive clippy analysis (user-initiated, acceptable wait time)
This design provides immediate formatting feedback while preserving comprehensive linting when you need it.
Requirements
- Rust toolchain (rustc, cargo): Install from rustup.rs
- rustfmt:
rustup component add rustfmt - clippy:
rustup component add clippy - jq: JSON processor
- macOS:
brew install jq - Ubuntu/Debian:
apt-get install jq - Other: See jq download page
- macOS:
Installation
1. Install the plugin
Place this plugin in your Claude Code plugins directory:
# If you haven't cloned the repository
cd ~/.claude/plugins # or your plugins directory
git clone https://github.com/cheolwanpark/useful-claude-plugins
cd useful-claude-plugins/plugins/rust-lint
# Or if you already have the repository
cd /path/to/useful-claude-plugins/plugins/rust-lint
2. Install Rust components
rustup component add rustfmt clippy
3. Verify installation
rustfmt --version
cargo clippy --version
jq --version
4. Enable the plugin in Claude Code
The plugin will be automatically detected by Claude Code. You can verify it’s loaded by checking for the /rust-lint:lint-project command.
How It Works
Hook Behavior (Automatic)
Triggered on: Every Edit or Write operation on .rs files
What it does:
- Validates file is
.rsand <1MB - Checks if
rustfmtis installed - Runs
rustfmt --checkto see if formatting is needed - If needed, runs
rustfmtto auto-format - Returns
allowdecision (never blocks)
Performance:
- Typical execution time: <1 second
- No compilation required
- No clippy analysis (too slow for hooks)
File size limit: Files larger than 1MB are skipped to avoid timeouts. Use cargo fmt manually for large files.
Slash Command (On-Demand)
Command: /rust-lint:lint-project [directory]
What it does:
- Finds the Cargo workspace/project root
- Checks formatting with
cargo fmt --check - Runs
cargo clippy --workspace --all-targets --no-deps - Generates a markdown report with:
- Summary (error count, warning count)
- Formatting issues (if any)
- Clippy errors (up to 20 shown)
- Clippy warnings (up to 10 shown)
- Exits with code 1 if errors found, 0 otherwise
Performance:
- First run: 10-30 seconds (requires compilation)
- Subsequent runs: 2-10 seconds (incremental compilation)
Build artifacts: Isolated to /tmp/claude-rust-lint-cache-<project-hash> to avoid polluting your project directory.
Configuration
rustfmt Configuration
Create a rustfmt.toml or .rustfmt.toml in your project root:
# Edition must match Cargo.toml
edition = "2021"
# Line width
max_width = 100
# Indentation
hard_tabs = false
tab_spaces = 4
# Imports
imports_granularity = "Crate"
group_imports = "StdExternalCrate"
# Trailing commas
trailing_comma = "Vertical"
# Use field init shorthand
use_field_init_shorthand = true
Generate default config:
rustfmt --print-config default > rustfmt.toml
clippy Configuration
Option 1: Cargo.toml [lints] (Recommended for Rust 1.74+)
[lints.clippy]
# Enable groups
all = "warn"
pedantic = "warn"
# Deny specific lints
unwrap_used = "deny"
expect_used = "warn"
# Allow noisy pedantic lints
missing_errors_doc = "allow"
missing_panics_doc = "allow"
module_name_repetitions = "allow"
Option 2: clippy.toml or .clippy.toml
# Cognitive complexity threshold
cognitive-complexity-threshold = 30
# Maximum allowed type complexity
type-complexity-threshold = 250
# Maximum allowed function parameters
too-many-arguments-threshold = 7
# Allowed variable names
allowed-names = ["i", "j", "k", "x", "y", "z"]
Option 3: Source code attributes
#![warn(clippy::all)]
#![warn(clippy::pedantic)]
#