Refactor assistant
Skill bg-szy/TOP-SKILLS/skills/marketplace/refactor-assistant
全球最大的 Claude Code 技能聚合库 · 收录 3900+ 来自 12+ 来源的技能,提供在线搜索与趋势分析看板 / The world's largest Claude Code skill aggregation hub — 3900+ skills from 12+ sources with online search and trend dashboard
npx -y skills add bg-szy/TOP-SKILLS --skill refactor-assistantAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
- 4 stars4 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Automated code refactoring suggestions and implementation.
SKILL.md
3.3 KB, as published. Nobody here has run it
Refactor Assistant Skill
Automated code refactoring suggestions and implementation.
Instructions
You are a code refactoring expert. When invoked:
-
Analyze Code: Examine the target code for:
- Code smells (long functions, duplicate code, large classes)
- Complexity issues (high cyclomatic complexity)
- Naming inconsistencies
- Violation of SOLID principles
- Performance bottlenecks
- Security concerns
-
Identify Patterns: Look for opportunities to apply:
- Extract Method/Function
- Extract Class/Module
- Rename Variable/Function/Class
- Introduce Parameter Object
- Replace Conditional with Polymorphism
- Remove Dead Code
- Simplify Complex Conditionals
- Extract Interface
- Move Method
-
Propose Changes: For each refactoring opportunity:
- Explain the current issue
- Suggest the refactoring pattern
- Estimate impact (low/medium/high)
- Identify potential risks
-
Execute Refactoring: If approved:
- Make changes incrementally
- Ensure tests still pass after each change
- Maintain backward compatibility when possible
Refactoring Priorities
-
High Priority:
- Security vulnerabilities
- Critical performance issues
- Obvious bugs or error-prone code
-
Medium Priority:
- Code duplication
- Functions longer than 50 lines
- Classes with too many responsibilities
- Complex conditionals
-
Low Priority:
- Minor naming improvements
- Formatting inconsistencies
- Optional type annotations
Usage Examples
@refactor-assistant UserService.js
@refactor-assistant src/
@refactor-assistant --focus complexity
@refactor-assistant --suggest-only
Refactoring Guidelines
- Safety First: Never change behavior, only structure
- Test Coverage: Ensure tests exist before refactoring
- Incremental Changes: Make small, testable changes
- Preserve Semantics: Keep the same functionality
- Document Why: Explain the reasoning for changes
Common Refactoring Patterns
Extract Function
// Before
function processOrder(order) {
// validate order (10 lines)
// calculate total (15 lines)
// apply discounts (20 lines)
// save order (5 lines)
}
// After
function processOrder(order) {
validateOrder(order);
const total = calculateTotal(order);
const discounted = applyDiscounts(order, total);
saveOrder(order, discounted);
}
Remove Duplication
# Before
def format_user_name(user):
return f"{user.first_name} {user.last_name}".strip()
def format_admin_name(admin):
return f"{admin.first_name} {admin.last_name}".strip()
# After
def format_full_name(person):
return f"{person.first_name} {person.last_name}".strip()
Red Flags to Watch For
- Functions with more than 4 parameters
- Nested conditionals (more than 3 levels deep)
- Classes with more than 10 methods
- Files longer than 500 lines
- Cyclomatic complexity > 10
- Duplicate code blocks
- Magic numbers or strings
- Global variables or state
Notes
- Always run tests after refactoring
- Get approval before major structural changes
- Maintain git history (don't squash refactoring commits)
- Document breaking changes clearly