Refactor & Clean
Clean up code while maintaining functionality.
Scope
Specify what to refactor:
- •A specific file
- •A feature/module
- •Dead code removal
- •Pattern application
Process
- •Run tests first - Ensure green baseline
- •Identify issues - List what needs improvement
- •Refactor incrementally - One change at a time
- •Run tests after each change - Never break functionality
- •Final verification - All tests pass
Common Refactorings
Dead Code Removal
- •Unused imports
- •Unused variables/methods
- •Commented-out code
- •Unreachable code
Code Quality
- •Extract long methods
- •Remove duplication
- •Improve naming
- •Simplify conditionals
Pattern Application
- •Extract interface
- •Apply dependency injection
- •Use builder pattern
- •Apply strategy pattern
Rules
- •⚠️ NEVER refactor without tests
- •⚠️ One refactoring at a time
- •⚠️ Run tests after each change
- •⚠️ Commit frequently
Output Format
Baseline
- •Tests: X passing, Y failing
- •Files to refactor: list
Changes Made
| File | Refactoring | Tests |
|---|---|---|
| ... | ... | ✅ |
Final State
- •Tests: X passing, 0 failing
- •Lines removed: N
- •Complexity reduced: description