Tips & Tricks

Code Review Checklist dengan Claude Code

code review checklist menggunakan Claude Code untuk improving code quality.

コードレビューをefisiensi dengan Claude Code

コードレビュー 品質 維持 untuk pentingなproses す 、レビュアー 負担 大きい tantangan.Claude Code pemanfaatanすれば、体系的なチェックリスト 基づいたefisienなレビュー dimungkinkan なり.

セキュリティチェック

> こ PR コード セキュリティ 観点 dengan レビューして。
> XSS、SQLインジェクション、認証 kerentanan periksa.
// セキュリティチェックリスト
const securityChecks = {
  // 1. inputvalidasi
  inputValidation: {
    check: 'penggunainput サニタイズされているか',
    bad: `element.innerHTML = userInput;`,
    good: `element.textContent = userInput;`,
  },

  // 2. SQLインジェクション
  sqlInjection: {
    check: 'parameter化query 使われているか',
    bad: `db.query(\`SELECT * FROM users WHERE id = \${userId}\`);`,
    good: `db.query('SELECT * FROM users WHERE id = ?', [userId]);`,
  },

  // 3. 認証・認可
  auth: {
    check: 'APIendpoint 認証middleware adaか',
    bad: `app.get('/api/admin/users', handler);`,
    good: `app.get('/api/admin/users', requireAuth, requireAdmin, handler);`,
  },

  // 4. 秘密情報 露出
  secrets: {
    check: 'environment variable client 漏れてい tidakか',
    bad: `const apiKey = "sk-1234567890abcdef";`,
    good: `const apiKey = process.env.API_KEY;`,
  },
};

performaチェック

// performaチェックリスト
const performanceChecks = [
  {
    item: 'N+1query 発生 い tidakか',
    bad: `
      const users = await db.user.findMany();
      for (const user of users) {
        const posts = await db.post.findMany({ where: { userId: user.id } });
      }`,
    good: `
      const users = await db.user.findMany({
        include: { posts: true },
      });`,
  },
  {
    item: '不diperlukanな再rendering tidakか',
    bad: `
      function Component() {
        const handler = () => doSomething();
        return <Child onClick={handler} />;
      }`,
    good: `
      function Component() {
        const handler = useCallback(() => doSomething(), []);
        return <Child onClick={handler} />;
      }`,
  },
  {
    item: '大きなリスト 仮想化 適用されているか',
    check: '1000件以上 リスト → react-virtual 検討',
  },
];

readability・maintainabilityチェック

> こ コード readability peningkatanする提案 して。
> 命名規則、fungsi 長さ、コメント tepatさ periksa.
// readabilityチェック ポイント

// 1. fungsi 長さ(30行以下 理想)
// ❌ 1つ fungsi 全pemrosesan
async function processOrder(order: Order) {
  // 100行 pemrosesan...
}

// ✅ 責務ご dan 分割
async function processOrder(order: Order) {
  const validated = validateOrder(order);
  const priced = calculateTotal(validated);
  const payment = await processPayment(priced);
  return createConfirmation(payment);
}

// 2. 早期リターンpola
// ❌ ネスト 深い
function getDiscount(user: User) {
  if (user) {
    if (user.isPremium) {
      if (user.orders > 10) {
        return 0.2;
      }
      return 0.1;
    }
    return 0.05;
  }
  return 0;
}

// ✅ 早期リターン
function getDiscount(user: User) {
  if (!user) return 0;
  if (!user.isPremium) return 0.05;
  if (user.orders > 10) return 0.2;
  return 0.1;
}

// 3. マジックナンバー 排除
// ❌
if (status === 3) { /* ... */ }

// ✅
const ORDER_STATUS = { PENDING: 1, PROCESSING: 2, COMPLETED: 3 } as const;
if (status === ORDER_STATUS.COMPLETED) { /* ... */ }

errorハンドリングチェック

// errorハンドリング konfirmasiポイント

// ❌ error 握りつぶし
try {
  await saveData(data);
} catch (e) {
  // 何 し tidak
}

// ✅ tepatなerrorpemrosesan
try {
  await saveData(data);
} catch (error) {
  logger.error('データpenyimpanan gagal', { error, data: data.id });
  throw new AppError('SAVE_FAILED', 'データ penyimpanan gagalしま', { cause: error });
}

レビューotomatisasiscript

// scripts/review-check.ts
import { execSync } from 'child_process';

interface ReviewIssue {
  file: string;
  line: number;
  severity: 'error' | 'warning' | 'info';
  message: string;
}

function checkForIssues(): ReviewIssue[] {
  const issues: ReviewIssue[] = [];
  const diff = execSync('git diff --cached --name-only').toString().split('\n');

  for (const file of diff.filter(f => f.endsWith('.ts') || f.endsWith('.tsx'))) {
    const content = execSync(`git show :${file}`).toString();
    const lines = content.split('\n');

    lines.forEach((line, index) => {
      // console.log チェック
      if (line.includes('console.log') && !file.includes('scripts/')) {
        issues.push({
          file, line: index + 1, severity: 'warning',
          message: 'console.log 残っています',
        });
      }

      // TODO/FIXME チェック
      if (/\/\/\s*(TODO|FIXME|HACK)/i.test(line)) {
        issues.push({
          file, line: index + 1, severity: 'info',
          message: 'TODO/FIXMEコメント あります',
        });
      }

      // any型 チェック
      if (/:\s*any\b/.test(line)) {
        issues.push({
          file, line: index + 1, severity: 'warning',
          message: 'any型 penggunaanされています',
        });
      }
    });
  }

  return issues;
}

const issues = checkForIssues();
issues.forEach(i => console.log(`[${i.severity}] ${i.file}:${i.line} - ${i.message}`));

Ringkasan

Untuk コードレビューはtest戦略と密接に関連します。Claude Codeを使えば、セキュリティ・performa・readabilityの観点から体系的なレビューをefisienに実施できます。AIペアプログラミングの手法と組み合わせれば、レビューの質と速度を両立できます。コードレビューのbest practices, lihat Google Engineering Practices.

#Claude Code #code review #quality assurance #チェックリスト #automation