refactor

Refactor codebases by extracting functions and renaming variables while preserving behavior.

48|2|Updated Dec 23, 2017
One-click install
npx skills add https://github.com/g4rcez/dotfiles --skill refactor-g4rcez
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/g4rcez/dotfiles/tree/main/.ai/skills/refactor
Command: npx skills add https://github.com/g4rcez/dotfiles --skill refactor-g4rcez

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.

Core Features & Use Cases

  • Safe, incremental refactoring of legacy codebases.
  • Extract functions and rename variables while preserving behavior.
  • Improve type safety and reduce code smells with guided design patterns.
  • Use cases include cleaning up large functions, breaking down god classes, and applying safer abstractions.

Quick Start

Identify a target function or class with excessive responsibilities and perform one small, well-scoped refactor, then run tests to verify behavior.

Frequently Asked Questions about refactor

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

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

To refactor legacy code without breaking behavior, apply surgical, incremental improvements like extracting functions and renaming variables. This approach isolates changes and relies on unit-test verification to ensure regression-free evolution in medium-to-large codebases.

What is the best way to break down god classes and long functions?

The best way to break down god classes and long functions is through surgical refactoring, which involves extracting functions and improving type safety. This process applies guided design patterns to reduce code smells while maintaining behavior.

Can I apply design patterns incrementally to reduce code smells?

Yes, you can apply design patterns incrementally to reduce code smells by performing one small, well-scoped refactor at a time. This surgical method improves maintainability and type safety while running tests to verify behavior after each change.

Does incremental refactoring work for medium-to-large codebases with duplicated logic?

Incremental refactoring works effectively for medium-to-large codebases with duplicated logic by enabling safe, isolated changes. It targets long functions and fragile class structures, ensuring small commits and unit-test verification for regression-free improvements.

When should I avoid surgical refactoring and use a more drastic approach?

You should avoid surgical refactoring when a codebase requires drastic, wholesale restructuring rather than gradual improvements. If incremental changes cannot salvage the architecture, a more drastic approach like a complete repository rebuild is necessary.