lint-code
Run code linters based on project configuration. Uses centralized detection to determine and run the appropriate linter.
Usage
/lint-code # Lint entire project /lint-code src/utils.ts # Lint specific file /lint-code --fix # Auto-fix issues /lint-code src/ --fix # Lint directory with auto-fix
Lints the entire project by default. You can also specify:
- •A file path to lint a specific file
- •
--fixto auto-fix issues where possible
Instructions
Step 1: Discover Project Context
Use the Explore agent to discover project context:
Explore Prompt:
Discover project context for linting code. Find and read:
- •Root CLAUDE.md - Read
CLAUDE.mdat project root. All instructions are MANDATORY.- •Relevant CLAUDE.md Files - Search
**/CLAUDE.mdfor keywords: lint, eslint, prettier, ruff, format, style, conventions- •Project Type - Detect from package.json, pyproject.toml, go.mod, Cargo.toml, etc.
Return: Project type, linter(s), lint command, code style instructions
From the Explore results, extract:
- •Project type and package manager
- •Linter(s) configured
- •Lint command
- •Any code style instructions from CLAUDE.md
Step 2: Run Linter
Using the detected linter, run the appropriate command:
JavaScript/TypeScript:
# ESLint npx eslint . npx eslint . --fix # with auto-fix # Prettier (check) npx prettier --check . npx prettier --write . # with auto-fix # Biome npx biome check . npx biome check --apply . # with auto-fix
Python:
# Ruff (fast, recommended) ruff check . ruff check . --fix # with auto-fix ruff format . # formatting # Flake8 flake8 . # Black (formatting) black --check . black . # with auto-fix
Go:
# golangci-lint golangci-lint run # go fmt go fmt ./... # go vet go vet ./...
Rust:
# Clippy cargo clippy # rustfmt cargo fmt --check cargo fmt # with auto-fix
Ruby:
# RuboCop bundle exec rubocop bundle exec rubocop -a # with auto-fix
Java:
# Checkstyle (via Maven) mvn checkstyle:check # Checkstyle (via Gradle) ./gradlew checkstyleMain # SpotBugs mvn spotbugs:check ./gradlew spotbugsMain
C#/.NET:
# dotnet format dotnet format --verify-no-changes dotnet format # with auto-fix # With analyzers dotnet build /p:TreatWarningsAsErrors=true
Step 3: Parse Results
Extract from linter output:
- •Total issues found
- •Errors vs warnings
- •File locations
- •Rule violations
Step 4: Report Results
Output in this format:
## Lint Results **Linter**: [detected linter] **Command**: [command executed] **Status**: PASSED / [X] issues found ## Summary - Errors: X - Warnings: Y - Fixable: Z ## Issues ### Errors | File | Line | Rule | Message | |------|------|------|---------| | src/index.ts | 10 | no-unused-vars | 'x' is defined but never used | ### Warnings | File | Line | Rule | Message | |------|------|------|---------| | src/utils.ts | 25 | prefer-const | Use 'const' instead of 'let' | ## Auto-fixable Issues Run `[command] --fix` to automatically fix [Z] issues. ## Manual Fixes Required ### [File:Line] - [Rule] **Issue**: [description] **Fix**: [suggested fix]
Common Linter Configurations
ESLint + Prettier (Node.js)
// .eslintrc.json
{
"extends": ["eslint:recommended", "prettier"],
"env": { "node": true, "es2022": true }
}
Ruff (Python)
# pyproject.toml [tool.ruff] select = ["E", "F", "I", "N", "W"] ignore = ["E501"]
golangci-lint (Go)
# .golangci.yml
linters:
enable:
- gofmt
- govet
- errcheck
- staticcheck
Linter Priority
When multiple linters are configured, use this order:
JavaScript/TypeScript:
- •
package.jsonscripts.lint → use that command - •Biome (if
biome.jsonexists) - •ESLint (if
.eslintrc*exists) - •Prettier (formatting only, if
.prettierrc*exists)
Python:
- •
pyproject.tomlconfigured tool → use that - •Ruff (preferred - fast, modern)
- •Flake8 + Black (legacy setup)
If multiple linters configured: Run in order: static analysis first, then formatting. Example: ESLint → Prettier, or Ruff check → Ruff format
Error Handling
No Linter Configured
If no linter configuration is found:
No linter configured for this project. Question: "Would you like to set up a linter?" Options: - Show recommended linter for [detected language] - Continue without linting - Cancel
Recommendations by language:
- •Node.js → ESLint + Prettier
- •Python → Ruff
- •Go → golangci-lint
- •Rust → Clippy (built-in)
- •Ruby → RuboCop
- •Java → Checkstyle
- •C#/.NET → dotnet format
Linter Not Installed
If the linter command fails with "command not found":
Linter '[name]' is not installed. Question: "How should I proceed?" Options: - Show installation instructions - Try a different linter - Cancel
Installation commands:
- •ESLint:
npm install -D eslint - •Prettier:
npm install -D prettier - •Ruff:
pip install ruff - •golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest - •RuboCop:
gem install rubocop
Invalid Configuration
If linter fails due to config errors:
## Configuration Error Linter '[name]' failed due to invalid configuration. Error: [error message] Config file: [path to config] Fix the configuration, then run `/lint-code` again.
Exit Code Handling
| Exit Code | Meaning |
|---|---|
0 | No issues found (PASSED) |
1 | Lint issues found (report them) |
2+ | Configuration or runtime error |
Timeout on Large Codebase
If linting takes longer than 60 seconds:
Warning: Linting is taking a long time on this codebase. Question: "How should I proceed?" Options: - Continue waiting - Lint specific directory instead - Cancel
Tips
- •Run linters in CI to catch issues early
- •Use
--fixcarefully; review changes before committing - •Configure your editor to lint on save
- •Add pre-commit hooks for automatic linting