Use when adding new error messages to React, or seeing "unknown error code" warnings.
npx skills add DonggangChen/antigravity-agentic-skills --skill "refactoring_patterns"
Install specific skill from multi-skill repository
# Description
Common refactoring patterns - Extract, Rename, Move and code smell solutions.
# SKILL.md
name: refactoring_patterns
router_kit: FullStackKit
description: Common refactoring patterns - Extract, Rename, Move and code smell solutions.
metadata:
skillport:
category: quality
tags: [architecture, automation, best practices, clean code, coding, collaboration, compliance, debugging, design patterns, development, documentation, efficiency, git, optimization, productivity, programming, project management, quality assurance, refactoring, refactoring patterns, software engineering, standards, testing, utilities, version control, workflow] - refactoring-strategies
π Refactoring Patterns
Common refactoring patterns and code smell solutions.
π― Golden Rule
Do NOT change behavior, only improve structure
Before: Input X β [Code A] β Output Y
After: Input X β [Code B] β Output Y (SAME!)
π Code Smells
| Smell | Solution |
|---|---|
| Long Method | Extract Method |
| Large Class | Extract Class |
| Duplicate Code | Extract + Reuse |
| Long Parameter List | Parameter Object |
| Feature Envy | Move Method |
| Data Clumps | Extract Class |
π¦ Extract Method
// β Before
function processOrder(order) {
// 20 lines of validation
// 30 lines of calculation
// 15 lines of formatting
}
// β
After
function processOrder(order) {
validateOrder(order);
const total = calculateTotal(order);
return formatOutput(total);
}
π Replace Conditional with Polymorphism
// β Before
function getPrice(type) {
if (type === 'premium') return 100;
if (type === 'basic') return 50;
return 30;
}
// β
After
const pricing = { premium: 100, basic: 50, free: 30 };
const getPrice = (type) => pricing[type] ?? 30;
Refactoring Patterns v1.1 - Enhanced
π Workflow
Source: Refactoring.guru & Martin Fowler - Refactoring
Phase 1: Preparation (Safety First)
- [ ] Red-Green-Refactor: Do you have tests? If not, write tests first ("Characterization Tests"), then refactor.
- [ ] Small Steps: Make changes in atomic commits. Run tests after every step.
- [ ] Backup: Work on a clean branch in VCS (Git).
Phase 2: Applying Patterns
- [ ] Simplification: Simplify complex conditions with
Decompose ConditionalorReplace Nested Conditional with Guard Clauses. - [ ] Abstraction: Separate responsibilities (SRP) with
Extract MethodandExtract Class. If there isPrimitive Obsession, convert to Value Object. - [ ] Modernization: Apply
var->const/let,for->map/filter, Callback -> Async/Await conversions (Use language features).
Phase 3: Verification & Cleanup
- [ ] Regression Testing: Verify that existing functions are not broken.
- [ ] Dead Code: Delete unused code (Dead Code) ruthlessly. Do not comment it out, delete it (It's already in Git history).
- [ ] Naming: Update variable and function names to describe "why" the code does what it does, not just what it does.
Checkpoints
| Phase | Verification |
|---|---|
| 1 | Was a new feature added during Refactoring? (ABSOLUTELY NO. Two hats rule: Either Refactor or Add Feature). |
| 2 | Did readability increase? (Did Cognitive Complexity drop?). |
| 3 | Was test coverage preserved? |
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.