LLM Skills
~/catalogue/debugging et maintenance//tdd-refactor

Processus de remaniement

/tdd-refactor

Refondre le code en toute confiance grâce à un filet de sécurité complet :

wshobsonwshobson
2.6k
12 octobre 2025
// 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:

  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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
  1. 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.
// installer ce skill
Collez cette commande dans votre terminal à la racine de votre projet :
mkdir -p .claude/commands && curl -o ".claude/commands/tdd-refactor.md" "https://raw.githubusercontent.com/wshobson/commands/main/tools/tdd-refactor.md"
Ensuite dans Claude Code, tapez /tdd-refactor pour l'activer.
open_in_newVoir la source originale
// sauvegarder
Sauvegarde disponible après connexion.
loginSe connecter pour sauvegarder
// informations
Créateurwshobson
Étoiles 2.6k
Mis à jour12 octobre 2025
Format.md
AccèsGratuit
// similaires

Skills Debugging et maintenance

Voir toutarrow_forward