refactoring-patterns

Apply test-backed refactoring patterns to eliminate code smells incrementally.

364|53|Updated May 9, 2026
One-click install
npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill refactoring-patterns-cosmicstack-labs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactoring-patterns
Source: https://github.com/cosmicstack-labs/mercury-agent-skills/tree/main/categories/development/refactoring-patterns
Command: npx skills add https://github.com/cosmicstack-labs/mercury-agent-skills --skill refactoring-patterns-cosmicstack-labs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you improve and modernize existing code by removing code smells and applying refactorings systematically without changing behavior.

Core Features & Use Cases

  • Refactoring Workflow: A step-by-step process to identify issues, protect behavior with tests, apply one change at a time, and verify correctness after each step.
  • Targeted Refactoring Patterns: Practical guidance for techniques like extracting methods, replacing conditionals with polymorphism, and managing legacy modernization safely.
  • Legacy Modernization Strategy: Test-first characterization and incremental adoption approaches to reduce risk in older codebases.
  • Common Refactorings & Risk Awareness: A quick reference mapping refactorings to when to use them and the typical risk level.

Quick Start

Ask the AI to propose a small, test-backed refactoring plan for a specific function or class, including which refactoring pattern to apply first and what to verify after each change.

Frequently Asked Questions about refactoring-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor legacy code without breaking existing behavior?

Refactor legacy code safely by establishing test coverage first, applying incremental one-refactoring-at-a-time changes, and verifying correctness after each transformation to preserve behavior. This systematic approach reduces risk in older codebases.

What is the best way to eliminate code smells in long methods?

Eliminate code smells in long methods by applying targeted refactoring patterns like extracting methods. Follow a step-by-step workflow to identify issues, apply one change at a time, and verify correctness after each step.

How do I replace growing conditional chains with polymorphism?

Replace growing conditional chains with polymorphism by applying targeted refactoring patterns. This systematic transformation eliminates complex conditionals, improving maintainability while preserving the original behavior through test-backed changes.

Do I need test coverage before starting legacy modernization?

Yes, test coverage is required before starting legacy modernization. A test-first characterization approach protects existing behavior, allowing you to apply incremental refactoring changes safely and verify correctness after each step.

What refactoring patterns should I apply first to reduce risk in production codebases?

Apply small, incremental refactoring patterns first to reduce risk in production codebases. Start with test-backed transformations like extracting methods, verifying correctness after each single change before proceeding to more complex patterns.

When should I not use incremental refactoring on my codebase?

Avoid incremental refactoring when you cannot establish test coverage first. Without tests to characterize existing behavior, making incremental one-refactoring-at-a-time changes in legacy or production codebases becomes unsafe.