refactor

Guides surgical code refactoring to improve maintainability without changing behavior.

1|1|Updated Jan 29, 2026
One-click install
npx skills add https://github.com/ultraviollettnympho/transit-ticket --skill refactor-ultraviollettnympho
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: refactor
Source: https://github.com/ultraviollettnympho/transit-ticket/tree/main/.github/skills/refactor
Command: npx skills add https://github.com/ultraviollettnympho/transit-ticket --skill refactor-ultraviollettnympho

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate technical debt: long functions, duplicated logic, magic numbers, and god classes that make features hard to add and bugs easy to introduce. This Skill provides a structured playbook for cleaning up code incrementally while preserving existing behavior. ## Core Features & Use Cases - Code Smell Catalog: Identifies and fixes 10 common smells including long methods, duplicated code, feature envy, primitive obsession, and nested conditionals, each with before/after examples. - Refactoring Techniques: Covers extract method, introducing type safety, guard clauses, and design patterns like Strategy and Chain of Responsibility. - Safe Process Workflow: Enforces a test-first, small-steps, commit-often methodology with a quality checklist. - Use Case: When a user says "clean up this 200-line function" or "this class does too much", the Skill guides breaking it into focused units, verifying tests pass after each step. ## Quick Start Ask the AI to refactor a specific file or function to reduce duplication and improve readability without changing its behavior.

Frequently Asked Questions about refactor

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

FAQPage Schema
How do I refactor a long function without breaking it?

Break the long function into smaller focused functions using extract method, keeping behavior identical. Ensure tests exist first, make one small change at a time, run tests after each step, and commit whenever tests pass.

What are common code smells and how do I fix them?

Common smells include long methods, duplicated code, large classes, long parameter lists, magic numbers, and nested conditionals. Fixes include extracting methods, introducing parameter objects, named constants, guard clauses, and splitting classes by responsibility.

When should I not refactor code?

Avoid refactoring stable code that will not change, critical production code without test coverage, or when under a tight deadline. Add tests first before touching untested critical paths, and always have a clear purpose.

How do I replace nested conditionals with cleaner code?

Replace nested conditionals with guard clauses that return early on invalid states, flattening the arrow-shaped code. For complex validation, use a Chain of Responsibility pattern or a Result type to compose checks.

What is the difference between refactoring and rewriting code?

Refactoring preserves external behavior while improving internal structure through small verified steps. Rewriting replaces the implementation entirely, which carries higher risk and is appropriate only when gradual improvement is not viable.