スキル一覧に戻る
bigdegenenergy

refactoring

by bigdegenenergy

CLI tool that audits repositories for agent-readiness and outputs human + machine-readable reports

0🍴 0📅 2026年1月23日
GitHubで見るManusで実行

SKILL.md


name: refactoring description: Safe refactoring patterns and code improvement strategies. Auto-triggers when cleaning up code, reducing complexity, or improving maintainability.

Refactoring Skill

Golden Rules

  1. Never refactor without tests - Tests are your safety net
  2. Small steps - One change at a time, test after each
  3. Keep it working - Code should pass tests at every step
  4. Commit often - Easy to revert if something breaks

Code Smells to Address

Bloaters

SmellSymptomRefactoring
Long Method>20 linesExtract Method
Large Class>200 linesExtract Class
Long Parameter List>3 paramsIntroduce Parameter Object
Data ClumpsSame fields appear togetherExtract Class

Object-Orientation Abusers

SmellSymptomRefactoring
Switch StatementsMultiple type checksReplace with Polymorphism
Parallel InheritanceEvery subclass needs partnerMerge Hierarchies
Refused BequestSubclass doesn't use parentReplace Inheritance with Delegation

Change Preventers

SmellSymptomRefactoring
Divergent ChangeOne class changed for multiple reasonsExtract Class
Shotgun SurgeryOne change affects many classesMove Method/Field
Feature EnvyMethod uses other class's dataMove Method

Dispensables

SmellSymptomRefactoring
Dead CodeUnused codeDelete
Duplicate CodeSame logic repeatedExtract Method
Speculative GeneralityUnused abstractionCollapse Hierarchy
CommentsExplaining bad codeRefactor until self-explanatory

Common Refactorings

Extract Method

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

    # Calculate shipping
    shipping = 0
    if order.total > 100:
        shipping = 0
    elif order.weight < 1:
        shipping = 5
    else:
        shipping = 10
    # ... continue

# After
def process_order(order):
    validate_order(order)
    shipping = calculate_shipping(order)
    # ... continue

def validate_order(order):
    if not order.items:
        raise ValueError("Empty order")
    if order.total < 0:
        raise ValueError("Invalid total")

def calculate_shipping(order):
    if order.total > 100:
        return 0
    elif order.weight < 1:
        return 5
    return 10

Replace Conditional with Polymorphism

# Before
def calculate_area(shape):
    if shape.type == "circle":
        return 3.14 * shape.radius ** 2
    elif shape.type == "rectangle":
        return shape.width * shape.height
    elif shape.type == "triangle":
        return 0.5 * shape.base * shape.height

# After
class Shape:
    def area(self) -> float:
        raise NotImplementedError

class Circle(Shape):
    def area(self) -> float:
        return 3.14 * self.radius ** 2

class Rectangle(Shape):
    def area(self) -> float:
        return self.width * self.height

Introduce Parameter Object

# Before
def create_user(name, email, phone, address, city, zip_code):
    ...

# After
@dataclass
class UserInfo:
    name: str
    email: str
    phone: str
    address: str
    city: str
    zip_code: str

def create_user(info: UserInfo):
    ...

Refactoring Workflow

  1. Identify the smell or improvement opportunity
  2. Write tests if they don't exist
  3. Run tests - ensure green baseline
  4. Make ONE change
  5. Run tests - must still be green
  6. Commit with descriptive message
  7. Repeat until complete

Anti-Patterns in Refactoring

  • Big bang rewrites (do incremental changes instead)
  • Refactoring and adding features simultaneously
  • Skipping the test run between changes
  • Refactoring without understanding the code
  • Over-abstracting before patterns emerge

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です