Code refactoring best practices based on Martin Fowler's catalog and Clean Code principles (formerly refactoring). This skill should be used when refactoring existing code, improving code structure, reducing complexity, eliminating code smells, or reviewing code for maintainability. Triggers on tasks involving extract method, rename, decompose conditional, reduce coupling, or improve readability.
A comprehensive collection of code refactoring rules based on Martin Fowler's refactoring catalog and Robert C. Martin's Clean Code principles.
This skill provides 43 rules across 8 categories to help AI agents and developers refactor code systematically. Rules are prioritized by impact, from critical structural improvements to incremental micro-refactoring.
code-refactor/
├── SKILL.md # Entry point with quick reference
├── AGENTS.md # Compiled comprehensive guide
├── metadata.json # Version, organization, references
├── README.md # This file
└── rules/
├── _sections.md # Category definitions
├── struct-*.md # Structure & Decomposition rules (7)
├── couple-*.md # Coupling & Dependencies rules (6)
├── name-*.md # Naming & Clarity rules (5)
├── cond-*.md # Conditional Logic rules (6)
├── pattern-*.md # Abstraction & Patterns rules (6)
├── data-*.md # Data Organization rules (5)
├── error-*.md # Error Handling rules (4)
└── micro-*.md # Micro-Refactoring rules (4)
# Install dependencies (if using validation scripts)
pnpm install
# Build AGENTS.md from individual rules
pnpm build
# Validate the skill against quality guidelines
pnpm validate
rules/{prefix}-{descriptive-name}.mdrules/_template.md| Category | Prefix | Impact |
|----------|--------|--------|
| Structure & Decomposition | struct- | CRITICAL |
| Coupling & Dependencies | couple- | CRITICAL |
| Naming & Clarity | name- | HIGH |
| Conditional Logic | cond- | HIGH |
| Abstraction & Patterns | pattern- | MEDIUM-HIGH |
| Data Organization | data- | MEDIUM |
| Error Handling | error- | MEDIUM |
| Micro-Refactoring | micro- | LOW |
Each rule file follows this structure:
---
title: Rule Title
impact: CRITICAL|HIGH|MEDIUM-HIGH|MEDIUM|LOW-MEDIUM|LOW
impactDescription: Quantified impact (e.g., "reduces complexity by 50%")
tags: prefix, keyword1, keyword2
---
## Rule Title
Brief explanation of WHY this matters (1-3 sentences).
**Incorrect (what's wrong):**
\`\`\`typescript
// Bad code example with comment explaining the cost
\`\`\`
**Correct (what's right):**
\`\`\`typescript
// Good code example with comment explaining the benefit
\`\`\`
**When NOT to use:**
- Exception 1
- Exception 2
Reference: [Reference Title](URL)
Rule files follow the pattern: {prefix}-{descriptive-slug}.md
Examples:
struct-extract-method.mdcond-guard-clauses.mdpattern-strategy.md| Level | Description | |-------|-------------| | CRITICAL | Foundational improvements with cascade effects | | HIGH | Significant improvements to readability or maintainability | | MEDIUM-HIGH | Important patterns that enable extensibility | | MEDIUM | Valuable improvements with localized impact | | LOW-MEDIUM | Minor improvements with cumulative benefits | | LOW | Small improvements, apply incrementally |
| Command | Description |
|---------|-------------|
| pnpm build | Compile rules into AGENTS.md |
| pnpm validate | Validate skill against quality checklist |
| pnpm lint | Check markdown formatting |
This skill is based on:
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer