Skip to content
Agentmart
Submit a tool

refactoring-patterns

Safe refactoring techniques — extract method, rename, move, inline, and structural patterns.

Skill by Claude-Code-Community-Ireland

IndexedMIT★ 11
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/claude-code-community-ireland-refactoring-patterns

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Safe refactoring techniques — extract method, rename, move, inline, and structural patterns. Includes code smell identification and transformation recipes. Use when refactoring code or improving structure.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/refactoring-patterns

What's inside

Skill name
refactoring-patterns
Description
Safe refactoring techniques — extract method, rename, move, inline, and structural patterns. Includes code smell identification and transformation recipes. Use when refactoring code or improving structure.
License
MIT
Instructions
243 lines in SKILL.md · view on GitHub

Files (1)

  • SKILL.md

SKILL.md (first lines)

# Refactoring Patterns

## Safety Rules

Before any refactoring, verify all of the following:

- [ ] Tests exist covering the code you will change
- [ ] All tests pass before you start
- [ ] Perform one transformation at a time
- [ ] Run tests after every single transformation
- [ ] Commit after each successful step
- [ ] Name every transformation in your commit message (e.g., "refactor: Extract Method -- validateEmail")
- [ ] Never change behavior and structure in the same commit
- [ ] If a step breaks tests, revert immediately and try a smaller step

## Code Smell Catalog

| Smell                  | Symptoms                                                   | Typical Refactoring                          |
|------------------------|------------------------------------------------------------|----------------------------------------------|
| Long Method            | Method over 20 lines; multiple levels of abstraction       | Extract Method                               |
| Large Class            | Class over 300 lines; too many responsibilities            | Extract Class                                |
| Feature Envy           | Method uses more data from another class than its own      | Move Method                                  |
| Data Clump             | Same group of fields/params appear together repeatedly     | Introduce Parameter Object                   |
| Primitive Obsession    | Using primitives instead of small domain objects           | Replace Primitive with Value Object          |
| Shotgun Surgery        | One change requires edits across many files                | Move Method, Inline Class                    |
| Divergent Change       | One class changed for many different reasons               | Extract Class                                |
| Dead Code              | Unreachable code, unused variables, commented-out blocks   | Remove Dead Code                             |
| Long Parameter List    | Method takes more than 3 parameters                        | Introduce Parameter Object                   |
| Switch Statements      | Repeated switch/if-else on the same type field             | Replace Conditional with Polymorphism        |
| Duplicate Code         | Same logic in multiple places                              | Extract Method, Extract Superclass           |
| Magic Numbers          | Unexplained literal values in logic                        | Replace Magic Number with Named Constant     |

### Smell Examples

**Long Method:**
```typescript
function processOrder(order: Order) {
  // validate (10 lines) + calculate totals (15 lines)
  // apply discounts (12 lines) + check inventory (8 lines)
  // create invoice (10 lines) + send notification (6 lines)
}
```

**Feature Envy:**
```typescript
class Order {
  calculateShipping() {
    if (this.customer.address.country === "US") {
      if (this.customer.tier === "premium") return 0;
      return this.customer.address.isRemote ? 15 : 5;
    }
    return 25;
  }
}
```

**Data Clump:**
```typescript
function createUser(name: string, street: string, city: string, state: string, zip: string) {}
function updateAddress(street: string, city: string, state: string, zip: string) {}
```

## Named Refactorings

| Refactoring                               | Input                             | Output                                 |
|-------------------------------------------|-----------------------------------|----------------------------------------|
| Extract Method                            | Code block inside a method        | New method + call site                 |
| Extract Class                             | Fields and methods from a class   | New class with focused responsibility  |
| Inline Method                             | Trivial method                    | Body placed at all call sites          |
| Rename                                    | Unclear name                      | Intention-revealing name               |
| Move Method                               | Method in wrong class             | Method in the class that owns the data |
| Introduce Parameter Object                | Multiple related parameters       | Single object parameter                |
| Replace Conditional with Polymorphism     | Type-based switch/if-else         | Subclasses with overridden method      |
| Replace Magic Number with Named Constant  | Literal number in code            | Named constant                         |
| Decompose Conditional                     | Complex boolean expression        | Named methods for conditions           |
| Remove Dead Code                          | Unused code                       | Deletion                               |

### Extract Method

**Recipe:** (1) Identify code to extract. (2) Create method with intention-revealing name. (3) Copy code in. (4) Local variables become locals; outer scope reads become parameters; modified-and-used-after become return values. (5) Replace original with call. (6) Run tests.

```typescript
// Before
function printInvoice(invoice: Invoice) {
  console.log("=== Invoice ===");
  let total = 0;
  for (const item of invoice.items) { total += item.price * item.quantity; }
  const tax = total * 0.08;
  console.log(`Total: ${total + tax}`);
}

// After
function printInvoice(invoice: Invoice) {
  console.log("=== Invoice ===");
  console.log(`Total: ${calculateGrandTotal(invoice.items)}`);
}

function calculateGrandTotal(items: InvoiceItem[]): number {
  const subtotal = items.reduce((sum, i) => sum + i.price * i.quantity, 0);
  return subtotal + subtotal * 0.08;
}
```

### Extract Class

**Recipe:** (1) Identify cohesive fields and methods. (2) Create new class. (3) Move fields. (4) Move methods. (5) Delegate from original. (6) Run tests after each move.

```typescript
// Before
class User {
  name: string; email: string;
  street: string; city: string; state: string; zip: string;
  fullAddress(): string { return `${this.street}, ${this.city}, ${this.state} ${this.zip}`; }
}

// After
class Address {
  constructor(public street: string, public city: string, public state: string, public zip: string) {}
  full(): string { return `${this.street}, ${this.city}, ${this.state} ${this.zip}`; }

From Claude-Code-Community-Ireland/claude-code-resources, MIT.

More from Claude-Code-Community-Ireland/claude-code-resources

Signals

Stars
11
Forks
4
Open issues
4
Last commit (this folder)
Jan 29, 2026 (9 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Claude-Code-Community-Ireland

Cite this page

refactoring-patterns skill. Agent Mart. https://agentmart.dev/skills/claude-code-community-ireland-refactoring-patterns (last updated 2026-10-24)