mcpField
E
encore-code-review

encore-code-review

github.com/encoredevテスト・品質30833 回インストール2 日前に更新
リポジトリ

encore-code-review について

Encore.ts プロジェクト向けのコードレビュースキルです。一般的な設計、セキュリティ、信頼性の問題を確認し、重大度と場所を付けて問題、警告、良い実践を報告します。

主な機能

  1. 01インフラ宣言の配置確認
  2. 02インポートとサービス呼び出しの確認
  3. 03エラー処理と SQL のリスク検出
  4. 04エンドポイント公開とサブスクリプションの確認
  5. 05重大度と場所を付けた結果報告

活用シーン

  1. 01Encore.ts のプルリクエストレビュー
  2. 02危険な SQL 構築の検出
  3. 03サービス境界とインポートの確認
  4. 04サブスクリプションの冪等性とシークレット参照の監査

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/encoredev/skills --skill encore-code-review

インストール後、Claude Code で/encore-code-reviewを入力して読み込まれたか確認します。

詳細

Encore コードレビュー

手順

Encore.ts のコードをレビューする際は、以下の一般的な問題を確認してください:

重大な問題

1. 関数内部でのインフラストラクチャ
// WRONG: Infrastructure declared inside function
async function setup() {
  const db = new SQLDatabase("mydb", { migrations: "./migrations" });
  const topic = new Topic<Event>("events", { deliveryGuarantee: "at-least-once" });
}

// CORRECT: Package level declaration
const db = new SQLDatabase("mydb", { migrations: "./migrations" });
const topic = new Topic<Event>("events", { deliveryGuarantee: "at-least-once" });
2. import の代わりに require() を使用
// WRONG
const { api } = require("encore.dev/api");

// CORRECT
import { api } from "encore.dev/api";
3. 誤ったサービスインポートパターン
// WRONG: Direct import from another service
import { getUser } from "../user/api";

// CORRECT: Use ~encore/clients
import { user } from "~encore/clients";
const result = await user.getUser({ id });
4. エラーハンドリングの欠如
// WRONG: Returning null for not found
const user = await db.queryRow`SELECT * FROM users WHERE id = ${id}`;
if (!user) return null;

// CORRECT: Throw APIError
import { APIError } from "encore.dev/api";

const user = await db.queryRow`SELECT * FROM users WHERE id = ${id}`;
if (!user) {
  throw APIError.notFound("user not found");
}
5. SQL インジェクションのリスク
// WRONG: String concatenation
await db.query(`SELECT * FROM users WHERE email = '${email}'`);

// CORRECT: Template literal with automatic escaping
await db.queryRow`SELECT * FROM users WHERE email = ${email}`;

警告レベルの問題

6. 型アノテーションの欠如
// WEAK: No explicit types
export const getUser = api(
  { method: "GET", path: "/users/:id", expose: true },
  async ({ id }) => {
    return await findUser(id);
  }
);

// BETTER: Explicit request/response types
interface GetUserRequest { id: string; }
interface User { id: string; email: string; name: string; }

export const getUser = api(
  { method: "GET", path: "/users/:id", expose: true },
  async ({ id }: GetUserRequest): Promise<User> => {
    return await findUser(id);
  }
);
7. 内部エンドポイントの露出
// CHECK: Should this cron endpoint be exposed?
export const cleanupJob = api(
  { expose: true },  // Probably should be false
  async () => { /* ... */ }
);
8. 冪等でないサブスクリプションハンドラー
// RISKY: Not idempotent (pubsub has at-least-once delivery)
const _ = new Subscription(orderCreated, "process-order", {
  handler: async (event) => {
    await chargeCustomer(event.orderId);  // Could charge twice!
  },
});

// SAFER: Check before processing
const _ = new Subscription(orderCreated, "process-order", {
  handler: async (event) => {
    const order = await getOrder(event.orderId);
    if (order.status !== "pending") return;  // Already processed
    await chargeCustomer(event.orderId);
  },
});
9. モジュールレベルでのシークレット呼び出し
// WRONG: Secret accessed at startup
const stripeKey = secret("StripeKey");
const client = new Stripe(stripeKey());  // Called during import

// CORRECT: Access inside functions
const stripeKey = secret("StripeKey");

async function charge() {
  const client = new Stripe(stripeKey());  // Called at runtime
}

レビューチェックリスト

  • すべてのインフラストラクチャがパッケージレベルにある
  • require() ではなく ES6 の import を使用している
  • サービス間呼び出しに ~encore/clients を使用している
  • APIError による適切なエラーハンドリング
  • SQL がテンプレートリテラルを使用している
  • リクエスト/レスポンスの型が定義されている
  • 内部エンドポイントに expose: false が設定されている
  • サブスクリプションハンドラーが冪等である
  • シークレットがインポート時ではなく関数内部でアクセスされている
  • マイグレーションが命名規則に従っている (001_name.up.sql)

出力フォーマット

レビュー時は、問題を次のように報告してください:

[CRITICAL] [file:line] Description of issue
[WARNING] [file:line] Description of concern  
[GOOD] Notable good practice observed

コメント