install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/refactor" ~/.claude/skills/comeonoliver-skillshub-refactor-c13235 && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/refactor/SKILL.mdsource content
Fowler/Martin Code Refactoring Best Practices
Comprehensive code refactoring guide based on Martin Fowler's catalog and Clean Code principles, designed for AI agents and LLMs. Contains 43 rules across 8 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Refactoring existing code to improve maintainability
- Decomposing long methods or large classes
- Reducing coupling between components
- Simplifying complex conditional logic
- Reviewing code for code smells and anti-patterns
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Structure & Decomposition | CRITICAL | |
| 2 | Coupling & Dependencies | CRITICAL | |
| 3 | Naming & Clarity | HIGH | |
| 4 | Conditional Logic | HIGH | |
| 5 | Abstraction & Patterns | MEDIUM-HIGH | |
| 6 | Data Organization | MEDIUM | |
| 7 | Error Handling | MEDIUM | |
| 8 | Micro-Refactoring | LOW | |
Quick Reference
1. Structure & Decomposition (CRITICAL)
- Extract Method for Long Functionsstruct-extract-method
- Apply Single Responsibility Principlestruct-single-responsibility
- Extract Class from Large Classstruct-extract-class
- Compose Method for Readable Flowstruct-compose-method
- Keep Functions Under 20 Linesstruct-function-length
- Replace Method with Method Objectstruct-replace-method-with-object
- Introduce Parameter Objectstruct-parameter-object
2. Coupling & Dependencies (CRITICAL)
- Use Dependency Injectioncouple-dependency-injection
- Hide Delegate to Reduce Couplingcouple-hide-delegate
- Remove Middle Man When Excessivecouple-remove-middle-man
- Fix Feature Envy by Moving Methodscouple-feature-envy
- Apply Interface Segregation Principlecouple-interface-segregation
- Preserve Whole Object Instead of Fieldscouple-preserve-whole-object
3. Naming & Clarity (HIGH)
- Use Intention-Revealing Namesname-intention-revealing
- Avoid Abbreviations and Acronymsname-avoid-abbreviations
- Use Consistent Vocabularyname-consistent-vocabulary
- Use Searchable Namesname-searchable-names
- Avoid Type Encodings in Namesname-avoid-encodings
4. Conditional Logic (HIGH)
- Replace Nested Conditionals with Guard Clausescond-guard-clauses
- Replace Conditional with Polymorphismcond-polymorphism
- Decompose Complex Conditionalscond-decompose
- Consolidate Duplicate Conditional Fragmentscond-consolidate
- Introduce Special Case Objectcond-special-case
- Replace Conditional with Lookup Tablecond-lookup-table
5. Abstraction & Patterns (MEDIUM-HIGH)
- Extract Strategy for Algorithm Variantspattern-strategy
- Use Template Method for Shared Skeletonpattern-template-method
- Use Factory for Complex Object Creationpattern-factory
- Apply Open-Closed Principlepattern-open-closed
- Prefer Composition Over Inheritancepattern-composition-over-inheritance
- Extract Superclass for Common Behaviorpattern-extract-superclass
6. Data Organization (MEDIUM)
- Encapsulate Collectiondata-encapsulate-collection
- Replace Primitive with Objectdata-replace-primitive
- Encapsulate Record into Classdata-encapsulate-record
- Split Variable with Multiple Assignmentsdata-split-variable
- Replace Temp with Querydata-replace-temp-with-query
7. Error Handling (MEDIUM)
- Use Exceptions Instead of Error Codeserror-exceptions-over-codes
- Create Domain-Specific Exception Typeserror-custom-exceptions
- Fail Fast with Preconditionserror-fail-fast
- Separate Error Handling from Business Logicerror-separate-concerns
8. Micro-Refactoring (LOW)
- Remove Dead Codemicro-remove-dead-code
- Inline Trivial Variablesmicro-inline-variable
- Simplify Boolean Expressionsmicro-simplify-expressions
- Rename for Claritymicro-rename-for-clarity
How to Use
Read individual reference files for detailed explanations and code examples:
- Section definitions - Category structure and impact levels
- Rule template - Template for adding new rules
- Individual rules:
references/{prefix}-{slug}.md
Full Compiled Document
For the complete guide with all rules expanded:
AGENTS.md