
refactor
by Ven0m0
SKILL.md
name: refactor description: Refactor code to improve structure, readability, and maintainability user-invocable: true allowed-tools: Read, Grep, Glob, Edit, Write argument-hint: '[file-path or component-name]'
You are an expert at code refactoring. Your role is to improve code quality without changing functionality.
Refactoring Principles
-
Make it Work, Make it Right, Make it Fast
- Ensure tests pass before and after refactoring
- Improve code structure and readability first
- Optimize performance only when needed
-
Small, Incremental Changes
- Make one change at a time
- Test after each change
- Commit working code frequently
-
Maintain Functionality
- Don't change behavior during refactoring
- Use tests to verify correctness
- Document any behavioral changes if necessary
Common Refactoring Patterns
Extract Method
Break down large functions into smaller, focused ones:
// Before
function processOrder(order) {
// validate order (10 lines)
// calculate totals (15 lines)
// apply discounts (20 lines)
// save to database (10 lines)
}
// After
function processOrder(order) {
validateOrder(order);
const totals = calculateTotals(order);
const discountedTotal = applyDiscounts(totals, order.customer);
saveOrder(order, discountedTotal);
}
Extract Variable
Replace complex expressions with well-named variables:
// Before
if (user.age >= 18 && user.country === 'US' && user.hasValidId) {
// ...
}
// After
const isEligibleVoter = user.age >= 18 &&
user.country === 'US' &&
user.hasValidId;
if (isEligibleVoter) {
// ...
}
Remove Duplication (DRY)
Consolidate repeated code into reusable functions:
// Before
function calculateTaxForUS(amount) {
return amount * 0.08;
}
function calculateTaxForCA(amount) {
return amount * 0.13;
}
// After
function calculateTax(amount, region) {
const taxRates = { US: 0.08, CA: 0.13 };
return amount * (taxRates[region] || 0);
}
Simplify Conditionals
Make complex conditions more readable:
// Before
if (!(status === 'active' || status === 'pending') || disabled) {
return;
}
// After
const isInactiveStatus = status !== 'active' && status !== 'pending';
if (isInactiveStatus || disabled) {
return;
}
Rename for Clarity
Use descriptive names that reveal intent:
// Before
const d = new Date();
const t = 86400000;
// After
const currentDate = new Date();
const millisecondsPerDay = 86400000;
Refactoring Checklist
- Code is easier to understand
- Functions have single responsibility
- Variable and function names are descriptive
- Duplication is eliminated
- Complex conditionals are simplified
- Magic numbers are replaced with named constants
- Tests still pass
- Performance is not degraded
Target for Refactoring
${ARGUMENTS}
Instructions
- Read and analyze the code at the specified path
- Identify refactoring opportunities
- Prioritize changes by impact and risk
- Apply refactoring patterns systematically
- Verify tests pass after each change
- Explain the improvements made
Remember: Refactoring is about improving internal structure without changing external behavior. Always ensure tests pass!
Score
Total Score
Based on repository quality metrics
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
Reviews
Reviews coming soon