refactor

Restructure code while preserving behavior through small, test-guided changes.

5|2|Updated Jan 10, 2017
One-click install
npx skills add https://github.com/brujack/dotfiles --skill refactor-brujack
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/brujack/dotfiles/tree/main/.claude/skills/refactor
Command: npx skills add https://github.com/brujack/dotfiles --skill refactor-brujack

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Improve code structure while preserving behavior. Refactoring is required to clean up code smells, restructure a class or function, or improve overall quality without changing external behavior.

Core Features & Use Cases

  • Guidelines for safe refactoring: Never change behavior in the same commit; write tests first; make small, incremental changes; keep the code working.
  • Common refactoring techniques: Extract Method, Extract Class, Replace Conditional with Polymorphism, Introduce Parameter Object.
  • Use Case: When a project has bloated classes or complex switch logic, apply refactoring to improve readability and maintainability while preserving functionality.

Quick Start

Describe the exact code area to refactor and the behavior to preserve, then start with small, test-guided changes and verify behavior after each step.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor code without changing its external behavior?

To refactor code without changing behavior, make small, incremental changes and keep the code working after each step. Never change behavior in the same commit, and use test-driven development to verify functionality throughout the restructuring process.

What are common refactoring techniques for bloated classes and complex logic?

Common refactoring techniques include Extract Method, Extract Class, Replace Conditional with Polymorphism, and Introduce Parameter Object. These patterns improve readability and maintainability by restructuring code smells without modifying external functionality.

When do I need to refactor code in a software project?

You need to refactor code when a project has bloated classes, complex switch logic, or code smells. Refactoring cleans up classes or functions and restructures modules to improve overall quality while preserving the existing external behavior.

Do I need to write tests before refactoring code?

Yes, you need to write tests first before refactoring code. Test-driven development is a core requirement, ensuring you verify behavior after each small, incremental change to guarantee the restructuring does not alter external functionality.

What is the best way to start refactoring a specific code area safely?

The best way to start refactoring safely is to describe the exact code area to refactor and the behavior to preserve. Then, begin with small, test-guided changes and verify the behavior after each incremental step to ensure continuous functionality.