← スキル䞀芧に戻る
ShunsukeHayashi

refactor-helper

by ShunsukeHayashi

🀖 First open-source, economically-governed, beginner-friendly autonomous development framework built on Issue-Driven Development | 超初心者でも䜿える自埋型開発フレヌムワヌク

⭐ 13🍎 8📅 2026幎1月24日
GitHubで芋るManusで実行

SKILL.md


name: refactor-helper description: Refactor code to improve quality, performance, and maintainability. Use when refactoring code, improving code structure, or modernizing legacy code. allowed-tools: Bash, Read, Write, Grep, Glob

Refactor Helper

Version: 1.0.0 Purpose: Safe, systematic code refactoring


Triggers

TriggerExamples
Refactor"refactor this", "リファクタリングしお", "clean up code"
Improve"improve this code", "コヌド改善"
Modernize"update to modern syntax", "モダン化"

Refactoring Principles

1. Make Small Changes

✅ GOOD: One refactoring per commit
❌ BAD: Multiple unrelated changes in one commit

2. Ensure Tests Pass

# Before refactoring
npm test

# After each change
npm test

3. Keep Behavior Unchanged

Refactoring = Improving structure WITHOUT changing behavior

Common Patterns

Extract Function

// Before
function processOrder(order: Order) {
  // validate
  if (!order.items.length) throw new Error('Empty');
  if (order.total < 0) throw new Error('Invalid total');

  // calculate
  const subtotal = order.items.reduce((s, i) => s + i.price, 0);
  const tax = subtotal * 0.1;
  const total = subtotal + tax;

  // save
  db.save({ ...order, total });
}

// After
function validateOrder(order: Order): void {
  if (!order.items.length) throw new Error('Empty');
  if (order.total < 0) throw new Error('Invalid total');
}

function calculateTotal(items: Item[]): number {
  const subtotal = items.reduce((s, i) => s + i.price, 0);
  const tax = subtotal * 0.1;
  return subtotal + tax;
}

function processOrder(order: Order) {
  validateOrder(order);
  const total = calculateTotal(order.items);
  db.save({ ...order, total });
}

Replace Conditionals with Polymorphism

// Before
function getPrice(type: string, base: number): number {
  switch (type) {
    case 'premium': return base * 0.8;
    case 'vip': return base * 0.7;
    default: return base;
  }
}

// After
interface PricingStrategy {
  calculate(base: number): number;
}

class RegularPricing implements PricingStrategy {
  calculate(base: number) { return base; }
}

class PremiumPricing implements PricingStrategy {
  calculate(base: number) { return base * 0.8; }
}

Simplify Conditionals

// Before
if (user !== null && user !== undefined && user.isActive === true) {
  if (user.role === 'admin' || user.role === 'moderator') {
    // ...
  }
}

// After
const isActiveUser = user?.isActive ?? false;
const hasPrivileges = ['admin', 'moderator'].includes(user?.role ?? '');

if (isActiveUser && hasPrivileges) {
  // ...
}

Remove Dead Code

# Find unused exports
npx ts-prune

# Find unused dependencies
npx depcheck

Workflow

Step 1: Identify Smell

Code SmellRefactoring
Long functionExtract Function
Duplicate codeExtract and reuse
Complex conditionalsSimplify/Polymorphism
God classSplit responsibilities
Feature envyMove method

Step 2: Write Tests (if missing)

describe('processOrder', () => {
  it('should calculate total correctly', () => {
    const order = { items: [{ price: 100 }] };
    expect(processOrder(order).total).toBe(110);
  });
});

Step 3: Refactor

Small, incremental changes with tests after each.

Step 4: Verify

npm test
npm run lint
npm run typecheck

Checklist

  • Tests exist and pass before refactoring
  • Each change is small and focused
  • Tests pass after each change
  • No behavior changes
  • Code is more readable
  • Commit with clear message

スコア

総合スコア

75/100

リポゞトリの品質指暙に基づく評䟡

✓SKILL.md

SKILL.mdファむルが含たれおいる

+20
✓LICENSE

ラむセンスが蚭定されおいる

+10
✓説明文

100文字以䞊の説明がある

+10
○人気

GitHub Stars 100以䞊

0/15
✓最近の掻動

3ヶ月以内に曎新

+5
○フォヌク

10回以䞊フォヌクされおいる

0/5
✓Issue管理

オヌプンIssueが50未満

+5
✓蚀語

プログラミング蚀語が蚭定されおいる

+5
✓タグ

1぀以䞊のタグが蚭定されおいる

+5

レビュヌ

💬

レビュヌ機胜は近日公開予定です