refactoring-patternslisted
Install: claude install-skill diegosouzapw/awesome-omni-skill
# Refactoring Patterns Skill
## When to Use
Invoke this skill when:
- Code smells are detected (long functions, duplicated logic, shotgun surgery)
- Before making major structural changes to existing code
- During tech debt sprints or cleanup tasks
- A function exceeds 30 lines and needs decomposition
- Renaming, moving, or reorganizing code across files or packages
## The Golden Rule
```
Tests green -> Refactor -> Tests green
```
Never refactor code that lacks test coverage. If tests don't exist, write them first (characterization tests that capture current behavior), then refactor.
## Safe Refactoring Steps
1. **Verify tests pass** before touching anything. Run the full suite for the affected area.
2. **Make one refactoring move at a time.** Never combine multiple refactorings in a single change.
3. **Run tests after each move.** If anything fails, you know exactly which move broke it.
4. **Commit after each successful step.** Small commits make `git bisect` possible and rollback trivial.
5. **If tests fail, revert the last move.** Do not debug forward -- undo and try a different approach.
```
[tests pass] -> extract method -> [tests pass] -> commit
-> rename variable -> [tests pass] -> commit
-> move to new file -> [tests pass] -> commit
-> [tests FAIL] -> git revert -> rethink
```
## Common Patterns
### Extract Method
**Smell:** Function too long, or comments explaining what a block does.
**Action:** Pull the block into a