Book refactoring guru full

From Horonomos-laps/Yana-AI · View interactive version

Book refactoring guru full is an AI agent skill from the GitHub repository Horonomos-laps/Yana-AI. Refactoring Guru (Refactoring.Guru) — Full rules — comprehensive mandatory coding standards. Use when asked to apply Refactoring Guru principles or review code against Refactoring Guru standards.

How to use this skill

Skill file

OBEY Refactoring.Guru

Source and Scope

This rule set is derived from the public Refactoring.Guru refactoring material:

The crawl intentionally excluded example code, images, premium course pages, design pattern pages, legal pages, and non-refactoring navigation.

This file is not a copy of the site. It is an operational rule set for AI coding agents, paraphrased from the refactoring process, code-smell catalog, and refactoring technique catalog.

This file is binding engineering policy: MUST is binding, SHOULD is a strong default, and MUST NOT is forbidden.


Purpose

Refactoring is the controlled process of improving code structure without adding new functionality.

Use these rules to:

Clean code in this rule set means code that:


Primary Directive

When changing existing code, first diagnose the smell that makes the change hard.

Then choose the smallest refactoring that removes or isolates that smell while preserving behavior.

Never treat refactoring as a vague cleanup pass. Every refactoring MUST have:


Refactoring Process

Keep Refactoring Separate

Work in Small Steps

Verify Continuously

Keep the Result Cleaner


When to Refactor

Rule of Three

While Adding a Feature

While Fixing a Bug

During Code Review


Technical Debt Rules


Smell Detection Process

When touching existing code, scan in this order:

  1. Bloaters: code grew too large to understand or change.
  2. Object-orientation abusers: inheritance, type codes, or conditionals are misusing the object model.
  3. Change preventers: one change forces edits in too many places, or one class changes for unrelated reasons.
  4. Dispensables: code exists without earning its maintenance cost.
  5. Couplers: classes know too much about each other or delegate so much that responsibility disappears.
  6. Library gaps: external classes force duplicated workarounds.

For each smell:

Diagnose, Treat, Verify, Stop

Use this workflow for every non-trivial refactoring:

  1. Diagnose the smell:
  1. Choose treatment:
  1. Verify behavior:
  1. Decide the stop condition:

MUST NOT continue refactoring just because another smell was discovered. Record the next smell separately unless it blocks the current change.

Smell Exception Rules


Bloaters

Long Method

Large Class

Primitive Obsession

Long Parameter List

Data Clumps


Object-Orientation Abusers

Switch Statements

Temporary Field

Refused Bequest

Alternative Classes with Different Interfaces


Change Preventers

Divergent Change

Shotgun Surgery

Parallel Inheritance Hierarchies


Dispensables

Comments

Duplicate Code

Lazy Class

Data Class

Dead Code

Speculative Generality


Couplers

Feature Envy

Inappropriate Intimacy

Message Chains

Middle Man

Incomplete Library Class


Technique Selection Rules

Composing Methods

Moving Features Between Objects

Organizing Data

Simplifying Conditional Expressions

Simplifying Method Calls

Dealing With Generalization


Smell-to-Treatment Priority Map

Use this map after diagnosing the smell. Start with the preferred treatment, move to fallback only when the preferred treatment is blocked, and treat risky options as requiring stronger tests and explicit justification.


Technique Playbook

Each named technique MUST be applied with a symptom, a use condition, an avoid condition, safe steps, and verification. The entries below are intentionally compact; they are for agent decision-making, not tutorial prose.

Composing Methods Playbook

Moving Features Playbook

Organizing Data Playbook

Conditional and Method Call Playbook

Generalization Playbook


Decision Anti-Patterns


Technique Execution Safety

Extraction Safety

Inlining Safety

Moving Safety

Encapsulation Safety

Conditional Safety

Method Call Safety

Data Reorganization Safety

Generalization Safety


Safety and Tradeoff Rules


Refactoring Workflow for Agents

Before editing:

  1. Identify the requested behavior change or maintenance goal.
  2. Scan the touched area for smells using the catalog above.
  3. Name the primary smell, its cost, and the smallest useful refactoring.
  4. Identify the expected cleaner end state and the stop condition.
  5. Identify tests or checks that prove behavior is preserved.
  6. Decide whether the refactoring belongs before, after, or separate from feature work.

During editing:

  1. Apply one named transformation at a time.
  2. Keep the code runnable after each meaningful step.
  3. Rename, extract, move, inline, or encapsulate before introducing larger design structures.
  4. Re-run relevant tests after risky movement, public interface changes, or changed state flow.
  5. Re-check whether the chosen technique is still the smallest treatment.
  6. Stop if the refactoring exposes a different, larger problem and report the new scope.

After editing:

  1. Confirm behavior preservation.
  2. Confirm the original smell is reduced or removed.
  3. Confirm no broader feature change was hidden in the refactor.
  4. Confirm no new smell was introduced, especially middle-man, speculative generality, or inappropriate intimacy.
  5. Confirm that any intentionally untreated smell has a reason.
  6. Report the refactoring technique used, the stop condition reached, and the validation performed.

Review Checklist

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.