refactoring-patterns

Applies named refactoring patterns with trigger conditions and step-by-step execution to restructure code.

1|Updated Mar 13, 2026
One-click install
npx skills add https://github.com/dominionism/Noesis --skill refactoring-patterns-dominionism
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: refactoring-patterns
Source: https://github.com/dominionism/Noesis/tree/main/assets/skills/refactoring-patterns
Command: npx skills add https://github.com/dominionism/Noesis --skill refactoring-patterns-dominionism

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Codebases accumulate complexity as functions grow, conditionals nest, and magic values multiply, making changes risky and reviews painful. This Skill provides specific, named refactoring patterns with explicit trigger conditions so you know exactly when and how to restructure code without changing behavior. ## Core Features & Use Cases - Trigger-Based Patterns: Each pattern (Extract Function, Replace Conditional with Polymorphism, Introduce Parameter Object, Guard Clauses, and more) includes symptoms and thresholds, such as functions over 20-30 lines or switches with 3+ branches. - Test-First Safety Rule: Enforces passing tests or characterization tests before any refactoring, with test runs after every step to guarantee behavior preservation. - Before/After Examples: Concrete TypeScript examples show each transformation, such as converting nested conditionals into guard clauses or replacing magic numbers with named constants. - Use Case: During code review you find a 60-line function mixing validation, calculation, and persistence. Apply the Extract Function pattern to split it into named single-purpose functions while keeping all tests green. ## Quick Start Ask the AI to refactor the long processOrder function using the Extract Function pattern while keeping all existing tests passing.

Frequently Asked Questions about refactoring-patterns

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

FAQPage Schema
How do I refactor a long function safely?▼

Use the Extract Function pattern: identify a distinct block, determine its input and output variables, move it into a descriptively named function, and replace the original block with a call. Ensure passing tests exist first and run them after every step.

When should I replace a switch statement with polymorphism?▼

Apply Replace Conditional with Polymorphism when a switch has more than three branches dispatching on a type field, especially if the same switch appears in multiple places. Skip it for a single switch with two or three simple branches.

Can I refactor code that has no tests?▼

No. Refactoring without tests is guessing. Write characterization tests first that lock in current behavior, even if that behavior is wrong, then refactor while running tests after every step.

How do I simplify deeply nested if-else statements?▼

Use Guard Clauses: convert edge-case and error conditions into early returns at the top of the function. The main logic then sits at the top indentation level instead of being buried in nesting.

When should I not refactor code?▼

Avoid refactoring when no tests exist and cannot be written, when the code is scheduled for deletion, under deadline pressure for unrelated work, or when the Rule of Three is not met and duplication appears only twice.