Clean Code Review
Grounded in the principles of Clean Code (Robert C. Martin), focused on 7 high-leverage check dimensions.
Workflow
Review Progress:
- [ ] 1. Scan codebase: identify files to review (default to recently changed code if scope is unspecified)
- [ ] 2. Check each dimension (naming, functions, DRY, YAGNI, magic numbers, clarity, conventions)
- [ ] 3. Rate severity (高/中/低) for each issue
- [ ] 4. Generate report sorted by severity (highest first)
Severity reflects maintainability impact, so the report leads with what to fix first. Prefer the few highest-leverage findings over an exhaustive list of 低 smells — a signal-dense report the human acts on beats a long one they ignore.
When the codebase is primarily Python or Go, consult references/language-patterns.md for language-specific smells before finalizing.
Core Principle: Behavior Preservation
Every suggestion targets only how the code is implemented — never suggest changing the code's functionality, output, or behavior.
Check Dimensions
These are the detection signals and thresholds — the load-bearing decision criteria. Full ❌/✅ worked examples for dimensions 1–5 live in references/detailed-examples.md; read it when you need richer cases or are unsure a finding qualifies.
1. Naming Problems (Meaningful Names)
Detection signals:
- Meaningless names like
data1, temp, result, info, obj
- Multiple names for the same concept (mixing
get/fetch/retrieve)
- Booleans missing an
is/has/can/should prefix
const data1 = fetchUser(); // ❌ → const userProfile = fetchUser(); // ✅
2. Function Problems (Small Functions + SRP)
Detection signals:
- Function exceeds 100 lines
- More than 3 parameters (use a parameter object instead)
- Function does multiple things (violates Single Responsibility)
- Function name implies read-only but it has side effects
3. Duplication (DRY)
Detection signals:
- Similar if-else structures
- Similar data-transformation / error-handling logic
- Copy-paste traces
4. Over-Engineering (YAGNI)
Detection signals:
if (config.legacyMode) branches that are never true (dead code)
- Interfaces with only one implementation
- Over-defensive / useless try-catch or if-else
5. Magic Numbers (Avoid Hardcoding)
Detection signals:
- Bare numbers with no explanation (
retryCount > 3, setTimeout(fn, 86400000))
- Hardcoded strings, status codes, time constants
if (retryCount > 3) {} // ❌ → const MAX_RETRY_COUNT = 3; if (retryCount > MAX_RETRY_COUNT) {} // ✅
6. Structural Clarity (Readability First)
Detection signals:
- Nested ternary operators
- Overly compact one-liners
- Deep conditional nesting (> 3 levels) — prefer guard clauses with early returns
7. Project Conventions (Consistency)
Detection signals:
- Disordered import order (external libraries vs internal modules)
- Inconsistent function declaration style
- Inconsistent naming conventions (mixing camelCase and snake_case)
[!TIP]
Source project conventions from the project root CLAUDE.md / AGENTS.md, plus linter configs (.eslintrc, .prettierrc, ruff/flake8 config).
Severity Levels
Use 高 / 中 / 低 as the literal severity labels in the report — they are part of the output contract.
| Level |
Criteria |
| 高 (High) |
Hurts maintainability/readability; fix immediately |
| 中 (Medium) |
Room for improvement; fix recommended |
| 低 (Low) |
Code smell; optional optimization |
Output
Emit a Summary first, then P-numbered findings sorted by severity, then patterns worth keeping and any tests needed to refactor safely. Skeleton (read references/output-template.md before finalizing — it is the full, canonical shape):
# Clean Code Review: <scope>
## Summary
<the highest-leverage maintainability risk, one paragraph>
## Findings
### P1: <issue title>
- **原则**: <命名 / 单一职责 / DRY / YAGNI / 魔法数字 / 结构清晰度 / 项目规范>
- **位置**: `<file>:<line>`
- **级别**: 高 / 中 / 低
- **问题**: <what makes the code harder to read, change, or test>
- **建议**: <behavior-preserving refactor direction>
- **Why now**: <risk if left as-is>
## Good Patterns To Keep
- <implementation choice worth preserving>
## Test Gaps
- <tests needed to protect behavior during the refactor>
References
- references/output-template.md — the full canonical report shape; read before finalizing output.
- references/detailed-examples.md — full ❌/✅ worked cases for the 5 core dimensions (naming, functions, DRY, YAGNI, magic numbers); read when you need richer cases or are unsure a finding qualifies.
- references/language-patterns.md — language-specific smells for TypeScript/JavaScript, Python, and Go; consult when the codebase is primarily one of these languages.
Multi-Agent Parallel
When parallelizing across subagents, split the work along one axis, then dedupe and reconcile severity ratings when merging:
- By check dimension — one agent per dimension (7 total)
- By module/directory — one agent per module
- By language — one agent each for TypeScript, Python, Go
- By file type — components, hooks, utility functions, type definitions
Use a different skill when
This skill reports file/function-level Clean Code findings and does not modify code. Route elsewhere when:
- Architecture / module boundaries / abstraction quality (system-level, APoSD) →
hai-architecture.
- Eliminating
any / TypeScript type safety → ts-type-safety-reviewer.
- Actually applying the refactors (not just reporting) →
code-simplifier.
- React component design (consumer API, data flow, testability) →
component-diagnosis / react-component-diagnosis.
1---2name: clean-code-reviewer3description: Produces a severity-rated (高/中/低) Clean Code findings report across 7 dimensions (naming, function size/SRP, duplication/DRY, over-engineering/YAGNI, magic numbers, structural clarity, project conventions), each with a location and a behavior-preserving refactor suggestion — never changing functionality. Use whenever the user asks for a code review, quality check, refactor advice, or code-smell / Clean Code analysis, OR points at a file/function/diff and asks if it is well-written, too long, too repetitive, over-engineered, or poorly named — even casually, and even if they never say "review" ("I just wrote this, look it over", "does this look good before I commit"). Trigger on 代码体检, 代码质量, 重构检查, 代码审查, 这段代码写得怎么样, 帮我看看代码有没有问题, 有没有坏味道, 这函数是不是太长了, 命名规范吗, 魔法数字, 重复代码, 过度设计, and English like "is this code clean", "any code smells", "check this file".4---56# Clean Code Review78Grounded in the principles of *Clean Code* (Robert C. Martin), focused on 7 high-leverage check dimensions.910## Workflow1112```13Review Progress:14- [ ] 1. Scan codebase: identify files to review (default to recently changed code if scope is unspecified)15- [ ] 2. Check each dimension (naming, functions, DRY, YAGNI, magic numbers, clarity, conventions)16- [ ] 3. Rate severity (高/中/低) for each issue17- [ ] 4. Generate report sorted by severity (highest first)18```1920Severity reflects maintainability impact, so the report leads with what to fix first. Prefer the few highest-leverage findings over an exhaustive list of 低 smells — a signal-dense report the human acts on beats a long one they ignore.2122When the codebase is primarily Python or Go, consult [references/language-patterns.md](references/language-patterns.md) for language-specific smells before finalizing.2324## Core Principle: Behavior Preservation2526Every suggestion targets only **how the code is implemented** — never suggest changing the code's functionality, output, or behavior.2728## Check Dimensions2930These are the detection signals and thresholds — the load-bearing decision criteria. Full ❌/✅ worked examples for dimensions 1–5 live in [references/detailed-examples.md](references/detailed-examples.md); read it when you need richer cases or are unsure a finding qualifies.3132### 1. Naming Problems (Meaningful Names)3334Detection signals:35- Meaningless names like `data1`, `temp`, `result`, `info`, `obj`36- Multiple names for the same concept (mixing `get`/`fetch`/`retrieve`)37- Booleans missing an `is`/`has`/`can`/`should` prefix3839```typescript40const data1 = fetchUser(); // ❌ → const userProfile = fetchUser(); // ✅41```4243### 2. Function Problems (Small Functions + SRP)4445Detection signals:46- Function exceeds **100 lines**47- More than **3 parameters** (use a parameter object instead)48- Function does multiple things (violates Single Responsibility)49- Function name implies read-only but it has side effects5051### 3. Duplication (DRY)5253Detection signals:54- Similar if-else structures55- Similar data-transformation / error-handling logic56- Copy-paste traces5758### 4. Over-Engineering (YAGNI)5960Detection signals:61- `if (config.legacyMode)` branches that are never true (dead code)62- Interfaces with only one implementation63- Over-defensive / useless try-catch or if-else6465### 5. Magic Numbers (Avoid Hardcoding)6667Detection signals:68- Bare numbers with no explanation (`retryCount > 3`, `setTimeout(fn, 86400000)`)69- Hardcoded strings, status codes, time constants7071```typescript72if (retryCount > 3) {} // ❌ → const MAX_RETRY_COUNT = 3; if (retryCount > MAX_RETRY_COUNT) {} // ✅73```7475### 6. Structural Clarity (Readability First)7677Detection signals:78- Nested ternary operators79- Overly compact one-liners80- Deep conditional nesting (**> 3 levels**) — prefer guard clauses with early returns8182### 7. Project Conventions (Consistency)8384Detection signals:85- Disordered import order (external libraries vs internal modules)86- Inconsistent function declaration style87- Inconsistent naming conventions (mixing camelCase and snake_case)8889> [!TIP]90> Source project conventions from the project root `CLAUDE.md` / `AGENTS.md`, plus linter configs (`.eslintrc`, `.prettierrc`, ruff/flake8 config).9192## Severity Levels9394Use 高 / 中 / 低 as the literal severity labels in the report — they are part of the output contract.9596| Level | Criteria |97|------|------|98| 高 (High) | Hurts maintainability/readability; fix immediately |99| 中 (Medium) | Room for improvement; fix recommended |100| 低 (Low) | Code smell; optional optimization |101102## Output103104Emit a Summary first, then P-numbered findings sorted by severity, then patterns worth keeping and any tests needed to refactor safely. Skeleton (read [references/output-template.md](references/output-template.md) before finalizing — it is the full, canonical shape):105106```markdown107# Clean Code Review: <scope>108109## Summary110<the highest-leverage maintainability risk, one paragraph>111112## Findings113114### P1: <issue title>115- **原则**: <命名 / 单一职责 / DRY / YAGNI / 魔法数字 / 结构清晰度 / 项目规范>116- **位置**: `<file>:<line>`117- **级别**: 高 / 中 / 低118- **问题**: <what makes the code harder to read, change, or test>119- **建议**: <behavior-preserving refactor direction>120- **Why now**: <risk if left as-is>121122## Good Patterns To Keep123- <implementation choice worth preserving>124125## Test Gaps126- <tests needed to protect behavior during the refactor>127```128129## References130131- [references/output-template.md](references/output-template.md) — the full canonical report shape; read before finalizing output.132- [references/detailed-examples.md](references/detailed-examples.md) — full ❌/✅ worked cases for the 5 core dimensions (naming, functions, DRY, YAGNI, magic numbers); read when you need richer cases or are unsure a finding qualifies.133- [references/language-patterns.md](references/language-patterns.md) — language-specific smells for TypeScript/JavaScript, Python, and Go; consult when the codebase is primarily one of these languages.134135## Multi-Agent Parallel136137When parallelizing across subagents, split the work along one axis, then dedupe and reconcile severity ratings when merging:1381391. **By check dimension** — one agent per dimension (7 total)1402. **By module/directory** — one agent per module1413. **By language** — one agent each for TypeScript, Python, Go1424. **By file type** — components, hooks, utility functions, type definitions143144## Use a different skill when145146This skill reports file/function-level Clean Code findings and does not modify code. Route elsewhere when:147148- **Architecture / module boundaries / abstraction quality** (system-level, APoSD) → `hai-architecture`.149- **Eliminating `any` / TypeScript type safety** → `ts-type-safety-reviewer`.150- **Actually applying the refactors** (not just reporting) → `code-simplifier`.151- **React component design** (consumer API, data flow, testability) → `component-diagnosis` / `react-component-diagnosis`.