principle-refactoring

Guide behavior-preserving refactoring with Fowler's catalog and characterization tests.

2|8|Updated Apr 20, 2026
One-click install
npx skills add https://github.com/lugassawan/swe-workbench --skill principle-refactoring
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: principle-refactoring
Source: https://github.com/lugassawan/swe-workbench/tree/main/skills/principle-refactoring
Command: npx skills add https://github.com/lugassawan/swe-workbench --skill principle-refactoring

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It prevents risky refactors by enforcing behavior-preserving steps, keeping the test suite green between moves, and guiding you from code smells to the correct Fowler refactoring catalog decisions.

Core Features & Use Cases

  • Behavior-preserving refactoring discipline: preserves behavior at every step, keeps small independently-reviewable changes, and runs tests after each move to stay green.
  • Smell-to-move mapping: translates common refactoring smells (Long Method, Large Class, Feature Envy, Data Clumps, Primitive Obsession, Shotgun Surgery, Divergent Change, Speculative Generality) into specific Fowler moves and sequencing guidance.
  • Legacy safety via characterization tests: instructs when and how to write characterization tests first for legacy code without coverage, turning unknown behavior into a verified safety net.

Quick Start

Ask the AI: “How do I refactor this legacy function with a Long Method into Extract Function steps while writing characterization tests first and keeping behavior identical between commits?”

Frequently Asked Questions about principle-refactoring

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

FAQPage Schema
How do I refactor legacy code safely without changing behavior?

Refactor legacy code safely by writing characterization tests first to capture existing behavior, then applying small Fowler catalog moves while keeping tests green between commits. This ensures behavior preservation and prevents risky structural changes.

How do I map code smells to the correct refactoring moves?

Map code smells to refactoring moves using smell-to-move mappings that translate issues like Long Method, Large Class, and Feature Envy into specific Fowler catalog sequences. This guides targeted structural improvements without altering functionality.

What are characterization tests and when do I need them for refactoring?

Characterization tests are safety nets you write before touching untested legacy code. You need them when refactoring code without coverage to turn unknown behavior into verified expectations before applying behavior-preserving moves.

How do I extract a function from a long method while keeping tests green?

Extract a function from a long method by applying the Extract Function refactoring in small, independently reviewable steps. Run tests after each move to stay green and ensure behavior preservation throughout the decomposition process.

What are the safety rules for behavior-preserving refactoring?

Safety rules for behavior-preserving refactoring include separating refactors from features, keeping steps small, running tests between commits, and stopping on red flags like mixed intent or test manipulation to avoid altering behavior.

Can I refactor code that has no existing test coverage?

You can refactor untested code by introducing characterization tests first to document current behavior. This creates a verified safety net before applying Fowler catalog moves, ensuring legacy safety without changing behavior.