본문으로 건너뛰기
cccskills
무료GitHub에 공개

refactoring-engineer

Code refactoring strategies, technical debt reduction, architecture modernization, and code quality improvement. Use when refactoring code, modernizing legacy code, reducing complexity, or improving maintainability.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

설치 방법 보기

포함된 파일(1)

  • SKILL.md5.7 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Refactoring Engineer

Refactoring Patterns

Extract Function

// Before
function processOrder(order: Order) {
  console.log(`Processing order ${order.id}`);
  
  // Validate items
  for (const item of order.items) {
    if (item.quantity <= 0) throw new Error('Invalid quantity');
    if (!item.price || item.price < 0) throw new Error('Invalid price');
  }
  
  // Calculate total
  let total = 0;
  for (const item of order.items) {
    total += item.price * item.quantity;
  }
  
  // Apply discount
  if (order.coupon) {
    total = total * (1 - order.coupon.discount);
  }
  
  return { orderId: order.id, total };
}

// After
function processOrder(order: Order) {
  console.log(`Processing order ${order.id}`);
  
  validateOrderItems(order.items);
  const subtotal = calculateSubtotal(order.items);
  const total = applyDiscount(subtotal, order.coupon);
  
  return { orderId: order.id, total };
}

function validateOrderItems(items: OrderItem[]) {
  for (const item of items) {
    if (item.quantity <= 0) throw new Error('Invalid quantity');
    if (!item.price || item.price < 0) throw new Error('Invalid price');
  }
}

function calculateSubtotal(items: OrderItem[]): number {
  return items.reduce((sum, item) => sum + item.price * item.quantity, 0);
}

function applyDiscount(amount: number, coupon?: Coupon): number {
  return coupon ? amount * (1 - coupon.discount) : amount;
}

Replace Conditional with Polymorphism

// Before
function calculateShipping(order: Order): number {
  if (order.shippingType === 'ground') {
    return order.weight * 1.5;
  } else if (order.shippingType === 'express') {
    return order.weight * 3 + 10;
  } else if (order.shippingType === 'overnight') {
    return order.weight * 5 + 25;
  }
  throw new Error('Unknown shipping type');
}

// After
interface ShippingStrategy {
  calculate(weight: number): number;
}

class GroundShipping implements ShippingStrategy {
  calculate(weight: number) {
    return weight * 1.5;
  }
}

class ExpressShipping implements ShippingStrategy {
  calculate(weight: number) {
    return weight * 3 + 10;
  }
}

class OvernightShipping implements ShippingStrategy {
  calculate(weight: number) {
    return weight * 5 + 25;
  }
}

const strategies: Record<string, ShippingStrategy> = {
  ground: new GroundShipping(),
  express: new ExpressShipping(),
  overnight: new OvernightShipping()
};

function calculateShipping(order: Order): number {
  const strategy = strategies[order.shippingType];
  if (!strategy) throw new Error('Unknown shipping type');
  return strategy.calculate(order.weight);
}

Replace Magic Numbers

// Before
if (user.tier === 3) {
  return 100;
}

// After
const TIERS = {
  BASIC: 1,
  STANDARD: 2,
  PREMIUM: 3,
  ENTERPRISE: 4
} as const;

const RATE_LIMITS = {
  [TIERS.BASIC]: 10,
  [TIERS.STANDARD]: 50,
  [TIERS.PREMIUM]: 100,
  [TIERS.ENTERPRISE]: 1000
} as const;

if (user.tier === TIERS.PREMIUM) {
  return RATE_LIMITS[TIERS.PREMIUM];
}

Legacy Code Modernization

Callback to Async/Await

// Before
function getUser(id: string, callback: (err: Error | null, user?: User) => void) {
  db.query('SELECT * FROM users WHERE id = ?', [id], (err, results) => {
    if (err) return callback(err);
    callback(null, results[0]);
  });
}

// After
async function getUser(id: string): Promise<User | null> {
  const [user] = await db.query('SELECT * FROM users WHERE id = ?', [id]);
  return user || null;
}

Class to Functional with Hooks

// Before
class UserList extends React.Component {
  state = { users: [], loading: false };
  
  componentDidMount() {
    this.loadUsers();
  }
  
  loadUsers = async () => {
    this.setState({ loading: true });
    const users = await fetchUsers();
    this.setState({ users, loading: false });
  };
  
  render() {
    const { users, loading } = this.state;
    return loading ? <Spinner /> : <List users={users} />;
  }
}

// After
function UserList() {
  const { data: users, isLoading } = useQuery(['users'], fetchUsers);
  return isLoading ? <Spinner /> : <List users={users} />;
}

Complexity Reduction

Reduce Nesting

// Before
function process(data: Data) {
  if (data) {
    if (data.items) {
      if (data.items.length > 0) {
        for (const item of data.items) {
          if (item.active) {
            processItem(item);
          }
        }
      }
    }
  }
}

// After
function process(data: Data) {
  if (!data?.items?.length) return;
  
  for (const item of data.items) {
    if (!item.active) continue;
    processItem(item);
  }
}

Early Returns

// Before
function validateUser(user: User): boolean {
  let isValid = true;
  
  if (!user.email) {
    isValid = false;
  } else if (!user.email.includes('@')) {
    isValid = false;
  } else if (user.email.length < 5) {
    isValid = false;
  }
  
  return isValid;
}

// After
function validateUser(user: User): boolean {
  if (!user.email) return false;
  if (!user.email.includes('@')) return false;
  if (user.email.length < 5) return false;
  return true;
}

Refactoring Checklist

  • Extract long functions
  • Remove duplicate code
  • Rename unclear variables
  • Replace magic numbers
  • Simplify conditionals
  • Reduce nesting depth
  • Add type safety
  • Update tests
  • Run full test suite
  • Measure performance impact

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

ai-sdk

무료

Vercel AI SDK expert guidance. Use when building AI-powered features — chat interfaces, text generation, structured output, tool calling, agents, MCP integration, streaming, embeddings, reranking, image generation, or working with any LLM provider.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

garochee33/DSH42026년 10월 12일 업데이트

Algorithm design and analysis skill for DSH; use when working on optimization, data structures, or computational procedures.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

garochee33/DSH42026년 10월 12일 업데이트

Design and implement scalable API gateways, RESTful APIs, GraphQL endpoints, WebSocket handlers, and microservice communication patterns. Use when creating API routes, designing endpoints, implementing middleware, or setting up service mesh architectures.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

garochee33/DSH42026년 10월 12일 업데이트

best-of-n

무료

Implement a task N ways in parallel and pick the best. Spawns multiple subagents in isolated worktrees, evaluates all candidates, and applies the winner. Use when asked to "best of n", "try multiple approaches", "parallel implementations", "/best-of-n", or "/bon".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

garochee33/DSH42026년 10월 12일 업데이트

check

무료

Check your work with a verification subagent. Spawns a verifier that reviews diffs, runs builds and tests, and evaluates correctness. Use when asked to "check work", "verify changes", "self-verify", "/check", "/verify", "/check-work", or "/self-verify".

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

garochee33/DSH42026년 10월 12일 업데이트

CI/CD pipeline design, GitHub Actions workflows, deployment automation, infrastructure as code, and release management. Use when setting up CI/CD, automating deployments, configuring build pipelines, or managing releases.

한국어 요약은 준비 중입니다. 원문 설명을 표시하고 있습니다.

garochee33/DSH42026년 10월 12일 업데이트

garochee33의 스킬 모두 보기

이 스킬의 문제 신고