4.8 KiB
4.8 KiB
name, description
| name | description |
|---|---|
| setup-code-quality | Detect project tools and generate a /check command for linting and typechecking |
You are setting up a project for automated code quality checks. Follow these steps carefully:
Step 1: Detect Project Type
Check for these files in the current directory to determine the project type:
package.json→ JavaScript/TypeScript (Node.js)pyproject.tomlorrequirements.txtorsetup.py→ Pythongo.mod→ GoCargo.toml→ Rustcomposer.json→ PHPbuild.gradleorpom.xml→ Java
Read the relevant config file to understand the project structure.
Step 2: Check Existing Tools
Based on the project type, check if these tools are already configured:
JavaScript/TypeScript:
- Check
package.jsonfor:eslint,prettier,typescript,@typescript-eslint/* - Check for config files:
.eslintrc.*,.prettierrc.*,tsconfig.json - Check
package.jsonscripts for:lint,typecheck,type-check, ortsc
Python:
- Check for:
mypy,pylint,black,ruff,flake8in dependencies - Check for config files:
mypy.ini,.pylintrc,pyproject.toml - Look for linting/type checking configurations
Go:
- Check for:
golint,gofmt,staticcheck - Go has built-in tools, check if project uses them
Rust:
- Check for:
clippy,rustfmt(built-in to Rust toolchain) - Check
Cargo.tomlfor workspace configuration
Step 3: Install Missing Tools (if needed)
If tools are missing, install them based on the project type:
JavaScript/TypeScript:
# Detect package manager (npm, yarn, pnpm, bun)
# Install missing tools, e.g.:
npm install --save-dev eslint prettier typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
# Add scripts to package.json if missing:
# "lint": "eslint ."
# "typecheck": "tsc --noEmit"
Python:
pip install mypy pylint black ruff
# or add to requirements-dev.txt / pyproject.toml
Go:
go install golang.org/x/lint/golint@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
Rust:
rustup component add clippy rustfmt
IMPORTANT: Always check if tools exist first. Only install if missing.
Step 4: Generate /fix Command
Create a file at .claude/commands/fix.md with the following structure:
---
name: fix
description: Run typechecking and linting, then spawn parallel agents to fix all issues
---
# Project Code Quality Check
This command runs all linting and typechecking tools for this project, collects errors, groups them by domain, and spawns parallel agents to fix them.
## Step 1: Run Linting and Typechecking
Run the appropriate commands for this project:
[INSERT PROJECT-SPECIFIC COMMANDS HERE]
## Step 2: Collect and Parse Errors
Parse the output from the linting and typechecking commands. Group errors by domain:
- **Type errors**: Issues from TypeScript, mypy, etc.
- **Lint errors**: Issues from eslint, pylint, ruff, clippy, etc.
- **Format errors**: Issues from prettier, black, rustfmt, gofmt
Create a list of all files with issues and the specific problems in each file.
## Step 3: Spawn Parallel Agents
For each domain that has issues, spawn an agent in parallel using the Task tool:
**IMPORTANT**: Use a SINGLE response with MULTIPLE Task tool calls to run agents in parallel.
Example:
- Spawn a "type-fixer" agent for type errors
- Spawn a "lint-fixer" agent for lint errors
- Spawn a "format-fixer" agent for formatting errors
Each agent should:
1. Receive the list of files and specific errors in their domain
2. Fix all errors in their domain
3. Run the relevant check command to verify fixes
4. Report completion
## Step 4: Verify All Fixes
After all agents complete, run the full check again to ensure all issues are resolved.
Replace [INSERT PROJECT-SPECIFIC COMMANDS HERE] with the actual commands for the detected project type.
JavaScript/TypeScript Example:
npm run lint
npm run typecheck
Python Example:
mypy .
pylint src/
black --check .
Go Example:
go vet ./...
staticcheck ./...
gofmt -l .
Rust Example:
cargo clippy -- -D warnings
cargo fmt -- --check
Step 5: Confirm Completion
After generating the /fix command, inform the user:
- What project type was detected
- Which tools were already present
- Which tools were installed (if any)
- That the
/fixcommand has been created at.claude/commands/fix.md - How to use it: "Run
/fixto lint, typecheck, and auto-fix all issues"
Important Notes:
- Always create the
.claude/commands/directory if it doesn't exist - Ensure the YAML frontmatter includes both
nameanddescription - The generated
/fixcommand must spawn agents in parallel (single response, multiple Task tool calls) - Tailor the commands to what's actually available in the project