rust-lint

Automatically format Rust files with rustfmt and provide on-demand clippy linting

View on GitHub
Author Cheolwan Park
Namespace @cheolwanpark/personal-curation
Category general
Version 1.0.0
Stars 2
Downloads 7
self.md verified
Table 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

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:

This design provides immediate formatting feedback while preserving comprehensive linting when you need it.

Requirements

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:

  1. Validates file is .rs and <1MB
  2. Checks if rustfmt is installed
  3. Runs rustfmt --check to see if formatting is needed
  4. If needed, runs rustfmt to auto-format
  5. Returns allow decision (never blocks)

Performance:

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:

  1. Finds the Cargo workspace/project root
  2. Checks formatting with cargo fmt --check
  3. Runs cargo clippy --workspace --all-targets --no-deps
  4. 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)
  5. Exits with code 1 if errors found, 0 otherwise

Performance:

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)]
#![deny(clip

...(truncated)

## Source

[View on GitHub](https://github.com/cheolwanpark/claude-plugins)
Tags: general