Debugging et maintenancesource GitHub
Processus de remaniement
/tdd-refactorRefondre le code en toute confiance grâce à un filet de sécurité complet :
// contenu du skill
model: claude-opus-4-1
Refactor code with confidence using comprehensive test safety net:
[Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.]
Refactoring Process
Use Task tool with subagent_type="tdd-orchestrator" to perform safe refactoring.
Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase excellence:
- Pre-Refactoring Assessment
- Analyze current code structure and identify code smells
- Review test coverage to ensure safety net is comprehensive
- Identify refactoring opportunities and prioritize by impact
- Run all tests to establish green baseline
- Document current performance metrics for comparison
- Create refactoring plan with incremental steps
- Code Smell Detection
- Duplicated Code: Extract methods, pull up to base classes
- Long Methods: Decompose into smaller, focused functions
- Large Classes: Split responsibilities, extract classes
- Long Parameter Lists: Introduce parameter objects
- Feature Envy: Move methods to appropriate classes
- Data Clumps: Group related data into objects
- Primitive Obsession: Replace with value objects
- Switch Statements: Replace with polymorphism
- Parallel Inheritance: Merge hierarchies
- Dead Code: Remove unused code paths
- Design Pattern Application
- Creational Patterns: Factory, Builder, Singleton where appropriate
- Structural Patterns: Adapter, Facade, Decorator for flexibility
- Behavioral Patterns: Strategy, Observer, Command for decoupling
- Domain Patterns: Repository, Service, Value Objects
- Architecture Patterns: Hexagonal, Clean Architecture principles
- Apply patterns only where they add clear value
- Avoid pattern overuse and unnecessary complexity
- SOLID Principles Enforcement
- Single Responsibility: One reason to change per class
- Open/Closed: Open for extension, closed for modification
- Liskov Substitution: Subtypes must be substitutable
- Interface Segregation: Small, focused interfaces
- Dependency Inversion: Depend on abstractions
- Balance principles with pragmatic simplicity
- Refactoring Techniques Catalog
- Extract Method: Isolate code blocks into named methods
- Inline Method: Remove unnecessary indirection
- Extract Variable: Name complex expressions
- Rename: Improve names for clarity and intent
- Move Method/Field: Relocate to appropriate classes
- Extract Interface: Define contracts explicitly
- Replace Magic Numbers: Use named constants
- Encapsulate Field: Add getters/setters for control
- Replace Conditional with Polymorphism: Object-oriented solutions
- Introduce Null Object: Eliminate null checks
- Performance Optimization
- Profile code to identify actual bottlenecks
- Optimize algorithms and data structures
- Implement caching where beneficial
- Reduce database queries and network calls
- Lazy loading and pagination strategies
- Memory usage optimization
- Always measure before and after changes
- Keep optimizations that provide measurable benefit
- Code Quality Improvements
- Naming: Clear, intentional, domain-specific names
- Comments: Remove obvious, add why not what
- Formatting: Consistent style throughout codebase
- Error Handling: Explicit, recoverable, informative
- Logging: Strategic placement, appropriate levels
- Documentation: Update to reflect changes
- Type Safety: Strengthen types where possible
- Incremental Refactoring Steps
- Make small, atomic changes
- Run tests after each modification
- Commit after each successful refactoring
- Use IDE refactoring tools when available
- Manual refactoring for complex transformations
- Keep refactoring separate from behavior changes
- Create temporary scaffolding when needed
- Architecture Evolution
- Layer separation and dependency management
- Module boundaries and interface definition
- Service extraction for microservices preparation
- Event-driven patterns for decoupling
- Async patterns for scalability
- Database access patterns optimization
- API design improvements
- Quality Metrics Tracking
- Cyclomatic Complexity: Reduce decision points
- Code Coverage: Maintain or improve percentage
- Coupling: Decrease interdependencies
- Cohesion: Increase related functionality grouping
- Technical Debt: Measure reduction achieved
- Performance: Response time and resource usage
- Maintainability Index: Track improvement
- **Code Duplic
// source originale publique
wshobson/commands/tools/tdd-refactor.md
Licence : Licence non indiquée. Consultez le dépôt avant toute réutilisation.
Projet indépendant, non affilié à Anthropic. Ce skill reste la propriété de son auteur original.