Przejdź do treści
Biblioteka skilli
Programowanie · Przegląd i audyt

refactoring-advisor

/refactoring-advisor

Analizuje kod pod kątem problemów strukturalnych i code smells, a potem rekomenduje priorytetowe wzorce refaktoryzacji z przykładami przed i po.

Licencja
Apache-2.0
Ostatnia zmiana repozytorium
25.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 25.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

Co robi i kiedy

Analizuje kod pod kątem problemów strukturalnych i code smells, a potem rekomenduje priorytetowe wzorce refaktoryzacji z przykładami przed i po.

Oryginalny opis (EN)

Analyze code for structural issues and code smells, then recommend prioritized refactoring patterns with before/after examples. Use when the user asks to refactor, clean up, or improve code structure, when a module has grown hard to change or test, or when a review surfaces maintainability problems.

Jak działa

  1. When to Apply
  2. Analysis Workflow
  3. Code Smell Catalog
  4. Refactoring Pattern Examples
  5. Complexity Thresholds
  6. Delegation
Sekcje z nagłówków SKILL.md, w oryginale · 145 linii, 743 słów
Podgląd SKILL.md
---
name: refactoring-advisor
description: Analyze code for structural issues and code smells, then recommend prioritized refactoring patterns with before/after examples. Use when the user asks to refactor, clean up, or improve code structure, when a module has grown hard to change or test, or when a review surfaces maintainability problems.
---

# Refactoring Advisor

Identify structural problems in code, name the smell, and recommend a specific refactoring that preserves external behavior. Never recommend a rewrite when a targeted refactoring will do.

## When to Apply

- Code review reveals structural issues
- A module or class has grown too large or accumulated responsibilities
- Adding features is increasingly difficult, or test coverage is hard to improve
- Developers report difficulty understanding a piece of code
- Performance bottlenecks trace back to structural issues

## Analysis Workflow

1. **Identify**: Scan the target files (Read/Grep/Glob) for the code smells cataloged below.
2. **Assess impact**: Rank each finding by how much it impairs maintainability, testability, and change safety.
3. **Prioritize by churn**: High-churn files first — frequently modified code yields the highest return. Find churn with:
   `git log --format= --name-only -- <path> | sort | uniq -c | sort -rn | head -20`
4. **Recommend**: For each finding, name the smell, the matching refactoring pattern, and show a before/after sketch in the project's language.
5. **Validate**: State how behavior preservation will be verified — existing tests must pass unchanged; if coverage is thin, recommend characterization tests before refactoring.

Present findings as a prioritized list (highest impact x highest churn first), not an unordered dump.

## Code Smell Catalog

### Bloaters (code too large)

- **Long Method** (>30 lines or >3 levels of nesting) — method does too many things and is hard to name. Fix: **Extract Method** — pull cohesive blocks into named functions.
- **Large Class** (>300 lines or >10 public methods) — class has multiple responsibilities. Fix: **Extract Class** — split into focused, single-responsibility classes.
- **Long Parameter List** (>4 parameters) — signature is hard to read and call correctly. Fix: **Introduce Parameter Object** — group related params into a struct/class.

### Object-orientation abusers

- **Switch Statements** — the same switch/match on a type field is duplicated across methods. Fix: **Replace Conditional with Polymorphism** — strategy pattern or trait objects.
- **Feature Envy** — a method accesses another class's data more than its own. Fix: **Move Method** — relocate the method to the class whose data it uses.

### Change preventers

- **Divergent Change** — one class is modified for multiple unrelated reasons. Fix: **Extract Class** — separate the concerns.
- **Shotgun Surgery** — one small change touches many files. Fix: **Move Method/Field** — consolidate related logic into fewer places.

### Dispensables

- **Dead Code** — unreachable code, unused variables, obsolete methods. Fix: delete it; version control preserves history.
- **Speculative Generality** — abstractions with a single implementation (one-implementor interface, factory that creates one type). Fix: **Inline Class/Method** — remove the unnecessary layer.

## Refactoring Pattern Examples

### Extract Method

Before:
```python
def process_order(order):
    # Validate
    if not order.items:
        raise ValueError("Empty order")
    if order.total < 0:
        raise ValueError("Invalid total")

    # Calculate discount
    discount = 0
    if order.customer.is_vip:
        discount = order.total * 0.1
    elif order.total > 100:
        discount = order.total * 0.05

    # Apply and save
    order.total -= discount
    db.save(order)
```

After:
```python
def process_order(order):
    validate_order(order)
    discount = calculate_discount(order)
    order.total -= discount
    db.save(order)
```

### Replace Conditional with Polymorphism

Before:
```typescript
function calculateArea(shape: Shape): number {
  switch (shape.type) {
    case "circle": return Math.PI * shape.radius ** 2;
    case "rectangle": return shape.width * shape.height;
    case "triangle": return 0.5 * shape.base * shape.height;
  }
}
```

After:
```typescript
interface Shape {
  area(): number;
}

class Circle implements Shape {
  constructor(private radius: number) {}
  area(): number { return Math.PI * this.radius ** 2; }
}
```

### Introduce Parameter Object

Before:
```go
func createUser(name string, email string, age int, role string, dept string) error {
```

After:
```go
type CreateUserRequest struct {
    Name  string
    Email string
    Age   int
    Role  string
    Dept  string
}

func createUser(req CreateUserRequest) error {
```

## Complexity Thresholds

Use these as flags for investigation, not hard rules:

- **Cyclomatic complexity**: decision points (if, for, while, match) — target <10 per function
- **Cognitive complexity**: nesting depth plus breaks in linear flow — target <15 per function
- **Lines per function**: target <30
- **Parameters per function**: target <4
- **Direct imports per module**: target <7

## Delegation

For work that goes beyond advice, route through the roster in the registry (claude.json):

- Language expert agents (rust-expert, python-expert, typescript-expert, etc.) implement language-specific refactorings.
- `comprehensive-analyst` assesses the blast radius of large refactorings before they start.
- `code-review-gatekeeper` validates quality after the refactoring lands.
- `peer-review-critic` performs the final diff-scoped review before the work is declared done.

Wersje

W bazie nie ma innych skilli o nazwie refactoring-advisor.

Migawka bazy z 13.11.2026 · wersja paczki 2338a80d2271 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100refactor
    Analizuje kod pod kątem code smells i problemów strukturalnych, proponuje bezpieczny plan refaktoryzacji i wykonuje go z weryfikacją testami.
  • 100python-refactoring
    Porządkuje kod Python według katalogu 83 wzorców refaktoryzacji, z przykładami przed i po zmianie.
  • 100refactoring
    Zawiera opis 89 technik refaktoryzacji i 22 code smells z mechaniką i przykładami przed i po, do wykrywania smells i spłacania długu technicznego.
  • 100refactoring
    Poprawia jakość i łatwość utrzymania kodu przez systematyczne wykrywanie code smells i stosowanie sprawdzonych wzorców refaktoryzacji.
  • 100refactor
    Analizuje złożoność i code smells, układa bezpieczny plan refaktoryzacji i wykonuje go krok po kroku z testami.
  • 100refactor
    Systematycznie refaktoryzuje kod, aby poprawić jego utrzymywalność, upraszcza go i usuwa code smells, zawsze zachowując istniejące zachowanie.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.