code-reviewer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCode Reviewer Skill
Code Reviewer Skill
コードレビューを自動化し、包括的なフィードバックを提供するスキルです。
This is a skill that automates code reviews and provides comprehensive feedback.
概要
Overview
このスキルは、プルリクエストや個別のコードファイルに対して、プロフェッショナルなコードレビューを実施します。セキュリティ、パフォーマンス、保守性、ベストプラクティスの観点から詳細な分析を行い、具体的な改善提案を提供します。
This skill performs professional code reviews for pull requests and individual code files. It conducts detailed analysis from the perspectives of security, performance, maintainability, and best practices, and provides specific improvement suggestions.
主な機能
Key Features
- 包括的なコード分析: セキュリティ、パフォーマンス、可読性、保守性の多角的レビュー
- 言語別ベストプラクティス: 各プログラミング言語の規約とパターンに基づく評価
- 具体的な改善提案: コード例を含む実装可能な修正案
- 重大度レベル付け: Critical、High、Medium、Lowの4段階で問題を分類
- 自動検出: バグ、セキュリティ脆弱性、パフォーマンスボトルネックの特定
- コードメトリクス: 複雑度、重複、テストカバレッジの分析
- アーキテクチャ評価: 設計パターンとSOLID原則の適用状況
- Comprehensive Code Analysis: Multi-dimensional review of security, performance, readability, and maintainability
- Language-Specific Best Practices: Evaluation based on conventions and patterns of each programming language
- Specific Improvement Suggestions: Implementable fixes including code examples
- Severity Level Classification: Classifies issues into four levels: Critical, High, Medium, Low
- Automatic Detection: Identifies bugs, security vulnerabilities, and performance bottlenecks
- Code Metrics: Analysis of complexity, duplication, and test coverage
- Architecture Evaluation: Assessment of design pattern and SOLID principle application
サポート言語
Supported Languages
- JavaScript/TypeScript: React, Node.js, Next.js, Vue.js, Angular
- Python: Django, Flask, FastAPI, データ分析ライブラリ
- Java: Spring Boot, Jakarta EE, Android
- Go: 標準ライブラリ、主要フレームワーク
- Rust: Cargo、非同期プログラミング
- C#: .NET, ASP.NET Core, Unity
- PHP: Laravel, Symfony, WordPress
- Ruby: Rails, Sinatra
- Swift: iOS、macOS開発
- Kotlin: Android、JVM
その他50以上の言語に対応
- JavaScript/TypeScript: React, Node.js, Next.js, Vue.js, Angular
- Python: Django, Flask, FastAPI, data analysis libraries
- Java: Spring Boot, Jakarta EE, Android
- Go: Standard library, major frameworks
- Rust: Cargo, asynchronous programming
- C#: .NET, ASP.NET Core, Unity
- PHP: Laravel, Symfony, WordPress
- Ruby: Rails, Sinatra
- Swift: iOS, macOS development
- Kotlin: Android, JVM
Supports over 50 other languages
使用方法
Usage
基本的なコードレビュー
Basic Code Review
このファイルをレビューしてください:
[ファイルパスまたはコード]Please review this file:
[File path or code]プルリクエストレビュー
Pull Request Review
以下のPRをレビュー:
変更内容: [変更の説明]
ファイル: [変更されたファイルのリスト]
重点項目:
- セキュリティ
- パフォーマンス
- コードの可読性Review the following PR:
Changes: [Description of changes]
Files: [List of modified files]
Focus areas:
- Security
- Performance
- Code readability特定観点のレビュー
Targeted Perspective Review
セキュリティの観点からこのコードをレビュー:
- SQL インジェクション
- XSS 脆弱性
- 認証・認可の問題
- 機密情報の漏洩Review this code from a security perspective:
- SQL injection
- XSS vulnerabilities
- Authentication/authorization issues
- Sensitive information leaksレガシーコードの改善提案
Legacy Code Improvement Suggestions
このレガシーコードのリファクタリング提案:
- モダンな書き方への変換
- パフォーマンス改善
- テスタビリティ向上Refactoring suggestions for this legacy code:
- Conversion to modern syntax
- Performance improvements
- Testability enhancementsレビュー観点
Review Perspectives
1. セキュリティ
1. Security
チェック項目:
- OWASP Top 10脆弱性
- インジェクション攻撃(SQL、コマンド、XSS等)
- 認証・認可の実装
- データ検証と衛生化
- 暗号化とハッシュの適切な使用
- 機密情報のハードコーディング
- セッション管理
- CSRF、CORS設定
- 依存関係の脆弱性
出力例:
markdown
undefinedCheck Items:
- OWASP Top 10 vulnerabilities
- Injection attacks (SQL, command, XSS, etc.)
- Authentication/authorization implementation
- Data validation and sanitization
- Proper use of encryption and hashing
- Hardcoding of sensitive information
- Session management
- CSRF, CORS settings
- Dependency vulnerabilities
Output Example:
markdown
undefinedセキュリティ問題
Security Issues
[CRITICAL] SQL インジェクション脆弱性
[CRITICAL] SQL Injection Vulnerability
場所: user_controller.py:45
問題: ユーザー入力を直接SQLクエリに連結しています
影響: データベースの不正アクセス、データ漏洩の可能性
現在のコード:
python
query = f"SELECT * FROM users WHERE username = '{username}'"
cursor.execute(query)推奨される修正:
python
query = "SELECT * FROM users WHERE username = ?"
cursor.execute(query, (username,))undefinedLocation: user_controller.py:45
Issue: User input is directly concatenated into SQL queries
Impact: Potential unauthorized database access and data leakage
Current Code:
python
query = f"SELECT * FROM users WHERE username = '{username}'"
cursor.execute(query)Recommended Fix:
python
query = "SELECT * FROM users WHERE username = ?"
cursor.execute(query, (username,))undefined2. パフォーマンス
2. Performance
チェック項目:
- アルゴリズムの時間計算量
- 不要なループやネスト
- データベースクエリの最適化(N+1問題)
- メモリリークの可能性
- 非効率なデータ構造
- キャッシュの活用
- 遅延読み込み
- バッチ処理の機会
- 非同期処理の活用
出力例:
markdown
undefinedCheck Items:
- Algorithm time complexity
- Unnecessary loops and nesting
- Database query optimization (N+1 problem)
- Potential memory leaks
- Inefficient data structures
- Cache utilization
- Lazy loading
- Batch processing opportunities
- Asynchronous processing utilization
Output Example:
markdown
undefinedパフォーマンス改善
Performance Improvements
[HIGH] N+1クエリ問題
[HIGH] N+1 Query Problem
場所: blog_service.ts:78-85
問題: ループ内でデータベースクエリを実行しています
影響: 100記事で101回のクエリが実行され、レスポンス時間が大幅に増加
現在のコード:
typescript
for (const post of posts) {
post.author = await db.users.findById(post.authorId);
}推奨される修正:
typescript
const authorIds = posts.map(p => p.authorId);
const authors = await db.users.findByIds(authorIds);
const authorMap = new Map(authors.map(a => [a.id, a]));
posts.forEach(post => post.author = authorMap.get(post.authorId));効果: クエリ数が101回→2回に削減、レスポンス時間50-90%改善
undefinedLocation: blog_service.ts:78-85
Issue: Database queries are executed within a loop
Impact: 101 queries are executed for 100 posts, significantly increasing response time
Current Code:
typescript
for (const post of posts) {
post.author = await db.users.findById(post.authorId);
}Recommended Fix:
typescript
const authorIds = posts.map(p => p.authorId);
const authors = await db.users.findByIds(authorIds);
const authorMap = new Map(authors.map(a => [a.id, a]));
posts.forEach(post => post.author = authorMap.get(post.authorId));Effect: Number of queries reduced from 101 to 2, response time improved by 50-90%
undefined3. コード品質
3. Code Quality
チェック項目:
- 命名規則の一貫性
- 関数の単一責任原則
- DRY原則(重複の排除)
- マジックナンバーの除去
- コメントの適切性
- エラーハンドリング
- 型安全性
- null/undefined チェック
- コードの複雑度(サイクロマティック複雑度)
出力例:
markdown
undefinedCheck Items:
- Consistent naming conventions
- Single responsibility principle for functions
- DRY principle (elimination of duplication)
- Removal of magic numbers
- Appropriateness of comments
- Error handling
- Type safety
- Null/undefined checks
- Code complexity (cyclomatic complexity)
Output Example:
markdown
undefinedコード品質
Code Quality
[MEDIUM] 関数が長すぎる(単一責任原則違反)
[MEDIUM] Function is too long (Violation of Single Responsibility Principle)
場所: order_processor.java:120-280
問題: processOrder() が160行あり、複数の責務を持っています
リファクタリング提案:
java
// 現在: 1つの長い関数
public void processOrder(Order order) {
// 検証ロジック (20行)
// 在庫チェック (30行)
// 支払い処理 (40行)
// 通知送信 (25行)
// ロギング (15行)
// データベース更新 (30行)
}
// 推奨: 分割された関数
public void processOrder(Order order) {
validateOrder(order);
checkInventory(order);
processPayment(order);
sendNotifications(order);
updateDatabase(order);
logOrderProcessing(order);
}効果: テスタビリティ向上、保守性改善、再利用性向上
undefinedLocation: order_processor.java:120-280
Issue: processOrder() is 160 lines long and has multiple responsibilities
Refactoring Suggestion:
java
// Current: One long function
public void processOrder(Order order) {
// Validation logic (20 lines)
// Inventory check (30 lines)
// Payment processing (40 lines)
// Notification sending (25 lines)
// Logging (15 lines)
// Database update (30 lines)
}
// Recommended: Split into functions
public void processOrder(Order order) {
validateOrder(order);
checkInventory(order);
processPayment(order);
sendNotifications(order);
updateDatabase(order);
logOrderProcessing(order);
}Effect: Improved testability, maintainability, and reusability
undefined4. アーキテクチャとデザインパターン
4. Architecture and Design Patterns
チェック項目:
- SOLID原則の適用
- デザインパターンの適切な使用
- レイヤーの分離(関心の分離)
- 依存性注入
- インターフェースの設計
- モジュール性
- スケーラビリティ
- 拡張性
Check Items:
- Application of SOLID principles
- Proper use of design patterns
- Layer separation (separation of concerns)
- Dependency injection
- Interface design
- Modularity
- Scalability
- Extensibility
5. テスト
5. Testing
チェック項目:
- テストの存在
- テストカバレッジ
- テストの品質(AAA パターン)
- エッジケースのカバー
- モックの適切な使用
- テストの独立性
- テストの可読性
Check Items:
- Existence of tests
- Test coverage
- Test quality (AAA pattern)
- Edge case coverage
- Proper use of mocks
- Test independence
- Test readability
6. エラーハンドリングとロギング
6. Error Handling and Logging
チェック項目:
- 適切な例外処理
- エラーメッセージの明確性
- スタックトレースの保持
- リソースのクリーンアップ
- ロギングレベルの適切性
- 機密情報の非ログ化
Check Items:
- Proper exception handling
- Clarity of error messages
- Preservation of stack traces
- Resource cleanup
- Appropriateness of logging levels
- Non-logging of sensitive information
7. ドキュメンテーション
7. Documentation
チェック項目:
- コメントの適切性
- API ドキュメント
- 複雑なロジックの説明
- TODO/FIXME の管理
- README の充実度
Check Items:
- Appropriateness of comments
- API documentation
- Explanation of complex logic
- Management of TODO/FIXME items
- Completeness of README
レビュー出力形式
Review Output Format
標準レビューレポート
Standard Review Report
markdown
undefinedmarkdown
undefinedコードレビュー結果
Code Review Results
サマリー
Summary
- 総合評価: B+ (良好)
- Critical問題: 0件
- High問題: 2件
- Medium問題: 5件
- Low問題: 8件
- 改善提案: 12件
- Overall Rating: B+ (Good)
- Critical Issues: 0
- High Issues: 2
- Medium Issues: 5
- Low Issues: 8
- Improvement Suggestions: 12
重要な問題
Important Issues
[HIGH] セキュリティ: CSRF保護の欠如
[HIGH] Security: Missing CSRF Protection
ファイル: api/routes.py:45-67
説明: POSTエンドポイントにCSRF保護がありません
推奨: FlaskのCSRF保護を有効化
優先度: 即時対応推奨
File: api/routes.py:45-67
Description: POST endpoints lack CSRF protection
Recommendation: Enable Flask's CSRF protection
Priority: Immediate action recommended
[HIGH] パフォーマンス: 同期的なファイルI/O
[HIGH] Performance: Synchronous File I/O
ファイル: upload_handler.js:89
説明: 大きなファイルを同期的に読み込んでいます
影響: サーバーブロッキング、タイムアウトの可能性
推奨: 非同期I/Oまたはストリーミング処理に変更
File: upload_handler.js:89
Description: Large files are read synchronously
Impact: Server blocking, potential timeouts
Recommendation: Change to asynchronous I/O or streaming processing
改善提案
Improvement Suggestions
コード重複の削減
Code Duplication Reduction
3つのコントローラーで類似の検証ロジックが重複しています。
共通のバリデーターユーティリティの作成を推奨します。
Similar validation logic is duplicated across three controllers. It is recommended to create a common validator utility.
型安全性の向上
Type Safety Improvement
TypeScriptの型が15箇所で使用されています。
適切な型定義またはインターフェースの作成を推奨します。
anyTypeScript's type is used in 15 places. It is recommended to create appropriate type definitions or interfaces.
anyベストプラクティス
Best Practices
✅ 適切に実装されている点:
- エラーハンドリングが適切
- 一貫した命名規則
- ユニットテストのカバレッジ良好(85%)
✅ Properly implemented aspects:
- Appropriate error handling
- Consistent naming conventions
- Good unit test coverage (85%)
推奨アクション
Recommended Actions
-
即時対応 (Critical/High):
- CSRF保護の実装
- 非同期I/Oへの変更
-
短期対応 (Medium):
- コード重複の削減
- 型安全性の向上
- 複雑な関数のリファクタリング
-
長期改善 (Low):
- ドキュメント拡充
- テストカバレッジ向上
- コードコメント改善
undefined-
Immediate Action (Critical/High):
- Implement CSRF protection
- Switch to asynchronous I/O
-
Short-Term Action (Medium):
- Reduce code duplication
- Improve type safety
- Refactor complex functions
-
Long-Term Improvement (Low):
- Expand documentation
- Improve test coverage
- Enhance code comments
undefined言語別チェックリスト
Language-Specific Checklists
JavaScript/TypeScript
JavaScript/TypeScript
- の代わりに
==を使用=== - の代わりに
var/constを使用let - Promise の適切なエラーハンドリング
- async/await の適切な使用
- TypeScript: の過度な使用回避
any - React: useEffect の依存配列
- メモリリーク(イベントリスナー、タイマー)
- Use instead of
===== - Use /
constinstead ofletvar - Proper error handling for Promises
- Proper use of async/await
- TypeScript: Avoid excessive use of
any - React: useEffect dependency array
- Memory leaks (event listeners, timers)
Python
Python
- PEP 8 スタイルガイド準拠
- list/dict comprehension の適切な使用
- 文によるリソース管理
with - 型ヒントの使用(Python 3.5+)
- グローバル変数の回避
- 例外の適切なキャッチ(broad exceptの回避)
- Comply with PEP 8 style guide
- Proper use of list/dict comprehensions
- Resource management using statements
with - Use of type hints (Python 3.5+)
- Avoid global variables
- Proper exception catching (avoid broad except)
Java
Java
- ストリーム API の活用
- Optional の適切な使用
- リソースの try-with-resources
- equals() と hashCode() のオーバーライド
- 不変オブジェクトの推奨
- スレッドセーフティ
- Utilize Stream API
- Proper use of Optional
- Resource management with try-with-resources
- Override equals() and hashCode()
- Recommend immutable objects
- Thread safety
Go
Go
- エラーハンドリングの徹底
- defer による リソースクリーンアップ
- goroutine リーク の回避
- context の適切な使用
- ポインタ vs 値のレシーバー
- race condition の回避
- Thorough error handling
- Resource cleanup using defer
- Avoid goroutine leaks
- Proper use of context
- Pointers vs value receivers
- Avoid race conditions
カスタムルール
Custom Rules
プロジェクト固有のルールを定義可能:
カスタムレビュールール:
- すべてのAPI エンドポイントにレート制限を実装
- データベース移行はロールバック可能に
- すべての公開関数にJSDocコメント必須
- エラーレスポンスは標準フォーマットに従うCustom review rules can be defined:
Custom review rules:
- Implement rate limiting for all API endpoints
- Database migrations must be rollbackable
- All public functions require JSDoc comments
- Error responses must follow standard format自動化との統合
Integration with Automation
CI/CD パイプライン
CI/CD Pipeline
yaml
undefinedyaml
undefined.github/workflows/code-review.yml
.github/workflows/code-review.yml
name: Automated Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Code Review
run: |
# Claude による自動レビュー
claude-code review --pr ${{ github.event.pull_request.number }}
undefinedname: Automated Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run Code Review
run: |
# Automated review by Claude
claude-code review --pr ${{ github.event.pull_request.number }}
undefinedpre-commit hook
Pre-commit Hook
bash
#!/bin/bashbash
#!/bin/bash.git/hooks/pre-commit
.git/hooks/pre-commit
claude-code review --staged --quick
undefinedclaude-code review --staged --quick
undefined使用例
Usage Examples
例1: 新機能の追加PR
Example 1: PR for New Feature Addition
入力:
以下のPRをレビューしてください:
タイトル: ユーザー認証機能の追加
変更ファイル:
- src/auth/login.ts (新規)
- src/auth/jwt.ts (新規)
- src/middleware/auth.ts (新規)
- src/routes/api.ts (変更)
変更内容:
- JWT ベースの認証を実装
- ログインエンドポイントを追加
- 認証ミドルウェアを作成出力: セキュリティ、トークン管理、エラーハンドリングの包括的レビュー
Input:
Please review the following PR:
Title: Add user authentication feature
Modified Files:
- src/auth/login.ts (new)
- src/auth/jwt.ts (new)
- src/middleware/auth.ts (new)
- src/routes/api.ts (modified)
Changes:
- Implemented JWT-based authentication
- Added login endpoint
- Created authentication middlewareOutput: Comprehensive review of security, token management, and error handling
例2: バグ修正のレビュー
Example 2: Bug Fix Review
入力:
このバグ修正をレビュー:
問題: ユーザーリストの読み込みが遅い
修正内容: クエリの最適化とキャッシング追加出力: パフォーマンス改善の検証、キャッシュ戦略の評価、エッジケースの確認
Input:
Review this bug fix:
Issue: User list loading is slow
Fix: Query optimization and caching additionOutput: Validation of performance improvements, evaluation of caching strategy, confirmation of edge cases
例3: リファクタリング
Example 3: Refactoring
入力:
このリファクタリングをレビュー:
変更: 500行の関数を10個の小さな関数に分割
目的: 保守性とテスタビリティの向上出力: SOLID原則の適用状況、命名の適切性、モジュール分割の妥当性
Input:
Review this refactoring:
Change: Split 500-line function into 10 small functions
Purpose: Improve maintainability and testabilityOutput: Assessment of SOLID principle application, appropriateness of naming, validity of module division
ベストプラクティス
Best Practices
レビュー実施のタイミング
Timing of Reviews
- プルリクエスト作成時: 変更の全体像を把握
- コミット前: 早期の問題発見
- 定期的なコード監査: 既存コードの改善機会発見
- リファクタリング前: 改善優先順位の決定
- When creating a pull request: Understand the overall picture of changes
- Before committing: Early issue detection
- Periodic code audits: Identify improvement opportunities for existing code
- Before refactoring: Determine improvement priorities
効果的なレビューのコツ
Tips for Effective Reviews
- コンテキストを提供: 変更の目的と背景を説明
- 重点項目を指定: 特に注目してほしい観点を明示
- 段階的にレビュー: 大きな変更は小さな単位に分割
- フィードバックを活用: 指摘事項を次のコードに反映
- Provide context: Explain the purpose and background of changes
- Specify focus areas: Clearly indicate perspectives to focus on
- Review incrementally: Split large changes into smaller units
- Utilize feedback: Reflect pointed-out issues in subsequent code
レビュー結果の活用
Utilizing Review Results
- 優先順位付け: Critical → High → Medium → Low の順に対応
- チームで共有: レビュー結果をチームの学習材料に
- 自動化: 繰り返し指摘される問題は linter ルール化
- メトリクス追跡: 問題発生率の推移を監視
- Prioritize: Address in order of Critical → High → Medium → Low
- Share with the team: Use review results as team learning materials
- Automate: Turn repeatedly pointed-out issues into linter rules
- Track metrics: Monitor trends in issue occurrence rates
制限事項
Limitations
- 実行テストは不可: コードの静的分析のみ(実際の実行は行わない)
- ビジネスロジックの正確性: 要件との整合性は人間の判断が必要
- 完全性の保証なし: すべてのバグや問題を検出できるわけではない
- プロジェクト固有のルール: デフォルトでは一般的なベストプラクティスのみ
- Cannot execute tests: Only static code analysis (no actual execution)
- Accuracy of business logic: Alignment with requirements requires human judgment
- No guarantee of completeness: Not all bugs or issues can be detected
- Project-specific rules: Only general best practices are applied by default
統合ツール
Integrated Tools
- GitHub/GitLab: PR コメントとして自動投稿
- Linters: ESLint, Pylint, RuboCop等との併用推奨
- Static Analyzers: SonarQube, CodeClimate等の補完
- Security Scanners: Snyk, OWASP Dependency-Check との併用
- GitHub/GitLab: Automatically posts as PR comments
- Linters: Recommended for use with ESLint, Pylint, RuboCop, etc.
- Static Analyzers: Complementary to SonarQube, CodeClimate, etc.
- Security Scanners: Recommended for use with Snyk, OWASP Dependency-Check, etc.
バージョン情報
Version Information
- スキルバージョン: 1.0.0
- 最終更新: 2025-01-22
使用例:
このPRをレビューしてください:
ファイル: src/payment/processor.py
変更内容: クレジットカード決済処理の実装
重点チェック項目:
- セキュリティ(カード情報の取り扱い)
- エラーハンドリング
- トランザクション管理
- PCI DSS 準拠このプロンプトで、包括的なコードレビューレポートが生成されます!
- Skill version: 1.0.0
- Last updated: 2025-01-22
Usage Example:
Please review this PR:
File: src/payment/processor.py
Changes: Implementation of credit card payment processing
Key check items:
- Security (handling of card information)
- Error handling
- Transaction management
- PCI DSS complianceThis prompt will generate a comprehensive code review report!