code-refactoring

Refactor complex code using incremental steps and behavior validation.

Updated Dec 20, 2023
One-click install
npx skills add https://github.com/Thiago-Cruz-eng/Hibrygame --skill code-refactoring-thiago-cruz-eng
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: code-refactoring
Source: https://github.com/Thiago-Cruz-eng/Hibrygame/tree/main/.claude/skills/code-refactoring
Command: npx skills add https://github.com/Thiago-Cruz-eng/Hibrygame --skill code-refactoring-thiago-cruz-eng

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you simplify and refactor code while preserving behavior, reducing complexity, and improving clarity for maintainable software.

Core Features & Use Cases

  • Extract Method (메서드 추출): Split long functions into smaller, focused helpers to improve readability and reduce cognitive load.
  • Remove Duplication (중복 제거): Consolidate repeated query/build logic using shared functions and parameter objects to follow DRY.
  • Design improvements for maintainability: Replace conditional chains with polymorphism, introduce parameter objects, and apply SOLID principles to separate responsibilities.
  • Behavior validation: Add a structured pre/post refactor checklist covering inputs, outputs, invariants, dependencies, and test/verification steps to reduce regression risk.
  • Use Case Examples: Refactor a bloated order-processing function, unify similar database queries for different user segments, or restructure payment method handling to be easier to extend.

Quick Start

Use code-refactoring to refactor a complex TypeScript function into smaller helpers, remove duplication, and validate behavior with tests and static checks.

Frequently Asked Questions about code-refactoring

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

FAQPage Schema
How do I refactor a long TypeScript function without breaking existing behavior?▼

Refactoring long TypeScript functions safely requires extracting methods into smaller helpers and validating behavior preservation via tests and static-analysis commands. A checklist-driven approach ensures functional equivalence before finalizing changes.

What is the best way to remove code duplication and enforce DRY in an existing codebase?▼

Removing code duplication involves consolidating repeated query and build logic using shared functions and parameter objects. This DRY approach reduces complexity and improves maintainability across the codebase.

How do I replace conditional logic with polymorphism to improve code maintainability?▼

Replacing conditional chains with polymorphism separates responsibilities and makes code easier to extend. This design improvement applies SOLID principles to restructure payment handling or similar logic structures.

Do I need tests before starting a refactoring task to simplify complex code?▼

Tests are required before refactoring to validate behavior preservation. A structured pre/post refactor checklist covers inputs, outputs, invariants, and dependencies to reduce regression risk during the process.

How to create a refactor plan using small incremental steps for TypeScript?▼

Creating a refactor plan requires breaking down complex code changes into small incremental steps. This approach enforces SOLID principles and introduces parameter objects while validating behavior at each stage.

When should I introduce parameter objects when refactoring complex functions?▼

Introduce parameter objects during refactoring to consolidate repeated query and build logic. This technique simplifies long functions and reduces duplication by grouping related parameters together.