refactoring-specialist
Code refactoring expert for improving code structure, readability, and maintainability. Use when user asks to refactor, clean up, or improve code quality.
By zhaono1 · 733 installs
npx skills add zhaono1/agent-playbook --skill refactoring-specialist
Source repository · Upstream listing
Refactoring Specialist
Expert guidance on refactoring code to improve structure, readability, and maintainability while preserving functionality.
When This Skill Activates
Activates when you:
Ask to refactor code
Request cleanup or improvement
Mention "technical debt" or "code smell"
Want to improve code quality
Refactoring Principles
1. Preserve Behavior : Refactoring must not change external behavior
2. Small Steps : Make small, incremental changes
3. Test Coverage : Ensure tests pass before and after
4. Commit Often : Commit after each successful refactoring
Code Smells to Address
1. Long Method
Symptom: Function 20 30 lines
Refactoring: Extract Method
2. Duplicate Code
Symptom: Similar code in multiple places
Refactoring: Extract Method / Template Method
3. Large Class
Symptom: Class doing too many things
Refactoring: Extract Class
4. Long Parameter List
Symptom: Function with 4+ parameters
Refactoring: Introduce Parameter Object
5. Feature Envy
Symptom: Method uses more data from other classes
Refactoring: Move Method
6. Data Clumps
Symptom : Same data appearing together
Refactoring : Extract Value Object
7. Primitive Obsession
Symptom : Using primitives instead of small objects
Refactoring : Replace Primitive with Object
8. Switch Statements
Symptom : Large switch on type
Refactoring : Replace Conditional with Polymorphism
9. Temporary Field
Symptom : Variables only used in certain scenarios
Refactoring : Extract Class
10. Comments
Symptom : Code needs extensive comments
Refactoring : Extract Method with clear name
Refactoring Steps
1. Identify the smell What makes this code hard to work with?
2. Determine the refactoring Which technique applies?
3. Ensure tests pass Green before starting
4. Apply the refactoring Make the change
5. Run tests Verify behavior unchanged
6. Commit Small, atomic commits
Safe Refactoring Practices
Use your IDE's refactoring tools (Rename, Extract, Move)
Run tests frequently (after each change)
Keep commits small and focused
Write a descriptive commit message
Consider code reviews for complex refactorings
Before Refactoring
[ ] Tests are passing
[ ] I understand what the code does
[ ] I have identified the specific code smell
[ ] I know which refactoring to apply
[ ] I have a rollback plan
After Refactoring
[ ] Tests still pass
[ ] Code is more readable
[ ] Code is easier to maintain
[ ] No new code smells introduced
[ ] Documentation updated if needed
References
references/smells.md Complete code smell catalog
references/techniques.md Refactoring techniques
references/checklist.md Refactoring checklist