---
name: clean-code
description: Evaluate and improve code quality using Clean Code principles (Robert C. Martin)
version: 1.0.0
author: wondelai (adapted)
platforms: [claude-code, cursor, windsurf]
license: MIT
source: https://github.com/wondelai/skills
---

# Clean Code

Apply Clean Code principles to evaluate and improve code quality.

## Scoring System
Rate the code 0-10 based on adherence to clean code principles.
Always show: current score → identified issues → improved code → new score.

## Core Principles

### Naming
- Variables: noun or noun phrase (`customerList`, not `cl`)
- Functions: verb or verb phrase (`getUserById`, not `get`)
- Boolean: `isLoaded`, `hasPermission`, `canDelete`
- No abbreviations unless universally known (`i` in for-loops is OK, `usr` is not)
- Length should match scope: short names for small scopes, descriptive for wider scopes

### Functions
- **Do one thing** — if you can extract a meaningful function, the original does too much
- **≤ 3 parameters** — if more, use a parameter object
- **≤ 20 lines** ideally
- **No side effects** — a function named `getUser` should not modify state
- **Command/Query separation** — either return a value OR cause a side effect, not both

### Comments
- Comments are a failure to express intent in code
- Good code reads like well-written prose
- If a comment explains WHAT, rename the variable/function instead
- Only comment WHY (business rules, regulatory requirements, workarounds)
- Delete commented-out code

### Error Handling
- Use exceptions, not return codes
- Create informative error messages
- Don't return null — use Optional, Result, or throw
- Don't pass null

### DRY (Don't Repeat Yourself)
- Every piece of knowledge must have a single, unambiguous representation
- Duplication is the root cause of most software problems
- Extract: pure functions, shared utilities, abstract base classes

### SOLID
- **S**ingle Responsibility: one reason to change
- **O**pen/Closed: open for extension, closed for modification
- **L**iskov Substitution: subtypes must be substitutable for base types
- **I**nterface Segregation: many specific interfaces over one general
- **D**ependency Inversion: depend on abstractions, not concretions

## Common Smells Checklist
- [ ] Long method (> 20 lines)
- [ ] Large class (> 200 lines)
- [ ] Long parameter list (> 3 params)
- [ ] Duplicated code
- [ ] Dead code (unused variables, unreachable code)
- [ ] Magic numbers/strings
- [ ] Deep nesting (> 3 levels)
- [ ] Inconsistent naming conventions