rust-code-review

作成者: apollographql

Rust PR向けのコードレビューチェックリストと判断フレームワーク。rust-best-practicesに基づく。

npx skills add https://github.com/apollographql/rust-best-practices --skill rust-code-review

Rust Code Review

Use this for Rust review work where consistency, safety, and maintainability matter.

Follow ths standards in https://github.com/apollographql/rust-best-practices

Mandatory pre-merge checks

  • Ownership and data flow are intentional.
  • Error handling is explicit and aligns with crate/binary boundaries.
  • Clippy and format quality are clean in touched files.
  • Performance changes are measured before acceptance.
  • Public APIs are documented; docs match runtime behavior.
  • Tests cover intended behavior and error paths.
  • Unsafe or raw-pointer usage is justified and constrained.

Severity matrix

  • P0: unsafe memory bug, panic in recoverable production path, silent data corruption.
  • P1: correctness bug, missing error propagation, invalid API contract.
  • P2: likely performance regression, missing public API docs, flaky tests.
  • P3: style/readability issues, avoidable clone/allocation, unnecessary complexity.

Review skills

Ownership-first coding

  • Prefer borrowing (&T, &mut T) over cloning.
  • Use Clone only when ownership is required or snapshots are explicitly needed.
  • Treat unnecessary clones (especially in loops) as likely regressions.
  • Reject clone on Copy types.

Value vs reference

  • Pass Copy/small POD types by value.
  • Pass large heap-backed or non-trivial objects by reference.
  • Surface ownership intent in function signatures.
  • Use Cow<'_, T> when input may be borrowed or owned.

Fallible control flow

  • Use let PATTERN = EXPR else { ... } for expected early exits.
  • Use if let ... else when divergence needs additional logic.
  • Prefer ? for bubbling errors.
  • Avoid unwrap/expect in production except when impossible-by-design cases are documented.

Allocation and allocation timing

  • Prefer _else APIs to avoid eager allocation (ok_or_else, map_or_else, etc.).
  • Keep iterator chains lazy; allocate only when required by terminal ops.
  • Do not collect and allocate only to throw away data.

Iterator vs loop

  • Use iterator chains for data transformation and composition.
  • Use for for early exits and side-effect-heavy or control-heavy loops.
  • Require readable formatting; avoid long unreadable chains.

Lints and static checks

  • Run and fix warnings from:
    • cargo clippy --all-targets --all-feature --locked -- -D warnings
  • Do not globally silence useful lints.
  • Prefer #[expect(clippy::...)] with rationale instead of #[allow(...)] unless fully justified.

Error discipline

  • Libraries: prefer typed errors (thiserror and #[from] conversions).
  • Binaries: anyhow acceptable, but keep context rich and actionable.
  • Test both success and error behavior.

Tests as behavior docs

  • One behavior per test.
  • One core assertion per test where possible.
  • Names should be descriptive sentence-like statements.
  • Prefer unit tests for internals, integration tests for public behavior.
  • Use snapshot tests only for complex, stable structured outputs.

Documentation and comments

  • Use //////! for API behavior and constraints.
  • Use // for why, safety rationale, platform constraints, and assumptions.
  • Remove stale comments; prefer smaller functions over narrative comments.
  • Link TODOs to issues instead of leaving bare TODO:.

Pointers and concurrency

  • Prefer &/&mut before any heap pointer.
  • Use Arc for cross-thread shared ownership; Rc for single-threaded.
  • Use Box for recursive/heap allocation needs.
  • Review raw pointer usage as unsafe boundaries with explicit invariants.

Quick rejection triggers

  • Unnecessary clones in hot paths.
  • Unjustified allow(clippy::...).
  • Silent recovery from Err that discards root cause.
  • Copying large types by value without a proof of intent.
  • Comments that simply restate what code already expresses.
  • TODOs without ownership/context.

apollographqlのその他のスキル

apollo-federation
apollographql
Apollo Federationは、複数のGraphQL API(サブグラフ)を統合されたスーパーグラフに構成することを可能にします。
apollo-ios
apollographql
Apollo iOSは、Appleプラットフォーム向けの強く型付けされたGraphQLクライアントです。GraphQLの操作とスキーマからSwiftの型を生成し、async/awaitクライアント、正規化キャッシュ(インメモリまたはSQLite対応)、クエリ、ミューテーション、マルチパートサブスクリプションを処理するプラグ可能なインターセプターベースのHTTPトランスポート、および任意の操作タイプを伝送可能なオプションのWebSocketトランスポート(graphql-transport-ws)を搭載しています。
apollo-router
apollographql
Apollo Routerは、Apollo Federation 2のスーパーグラフを実行するためにRustで書かれた高性能なグラフルーターです。サブグラフの前に配置され、クエリの計画、実行、レスポンスの合成を処理します。
apollo-router-plugin-creator
apollographql
Apollo Router用のネイティブRustプラグインを作成します。
apollo-server
apollographql
Apollo Server 5.xを使用してフレームワーク間でGraphQLサーバーを構築するための完全ガイド。スキーマ定義、リゾルバ、コンテキスト設定、TypeScriptサポートによるエラーハンドリングを網羅。プロトタイピング用のスタンドアロンモードと、Express、Fastify、Koa、サーバーレス環境との統合をサポート。リゾルバパターン、認証/認可、プラグイン、N+1問題防止のためのDataLoader、パフォーマンス最適化手法を含む。データソース、エラー...のリファレンスドキュメントを提供。
graphql-operations
apollographql
効率的で型安全なGraphQLオペレーションを作成し、フラグメントで整理するためのベストプラクティスガイド。クエリ、ミューテーション、サブスクリプション、フラグメントについて、命名規則、変数構文、ディレクティブの使用法を網羅。必要なフィールドのみをリクエストする、すべてのオペレーションに名前を付ける、ハードコードされた値の代わりに変数を使用する、キャッシュ可能性のためにIDフィールドを含めるといった基本原則を強調。フラグメントをコンポーネントと併置し、条件付きフィールドには@include/@skipディレクティブを使用することを推奨...
graphql-schema
apollographql
直感的で高性能かつ保守可能なGraphQLスキーマを設計するための業界ベストプラクティスガイド。クライアント中心の型構成、明示的なnull許容パターン、後方互換性のある進化戦略を含む中核設計原則を網羅。型、命名規則、カーソルベースのページネーション、エラーモデリング、セキュリティ考慮事項に関するリファレンスドキュメントを提供。インターフェース、ユニオン、入力型、ミューテーション、ID戦略に関する実践的なパターンをコード例とともに収録...
rover
apollographql
Apollo Rover CLIは、GraphQLスキーマ、フェデレーション、ローカルスーパーグラフ開発を管理するためのツールです。サブグラフスキーマの公開、取得、検証、フェデレーテッドスーパーグラフのローカルまたはGraphOS経由での構成を行います。スキーマチェック(デプロイ前検証)、リンティング、実行中のサーバーからのイントロスペクションを含みます。rover devコマンドは、開発ワークフロー向けに自動スキーマ構成を備えたローカルRouterを起動します。公開前チェック検証とスクリプト用のJSON出力を備えたCI/CDパターンをサポートします。必須条件...