This skill automates code reviews and provides comprehensive feedback.
Overview
This skill performs professional code reviews on pull requests and individual code files. It conducts detailed analysis from the perspectives of security, performance, maintainability, and best practices, and provides concrete improvement suggestions.
Key Features
- Comprehensive Code Analysis: Multi-faceted review of security, performance, readability, and maintainability
- Language-Specific Best Practices: Evaluation based on the conventions and patterns of each programming language
- Concrete Improvement Suggestions: Implementable fixes including code examples
- Severity Level Assignment: Classifies issues into four levels: Critical, High, Medium, and Low
- Automatic Detection: Identification of bugs, security vulnerabilities, and performance bottlenecks
- Code metrics: Analysis of complexity, duplication, and test coverage
- Architecture Evaluation: Application status of design patterns and SOLID principles
Supported Languages
- 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 50+ other languages
How to Use
Basic Code Review
このファイルをレビューしてください:
[ファイルパスまたはコード]
Pull request review
以下のPRをレビュー:
変更内容: [変更の説明]
ファイル: [変更されたファイルのリスト]
重点項目:
- セキュリティ
- パフォーマンス
- コードの可読性
Review from a Specific Perspective
セキュリティの観点からこのコードをレビュー:
- SQL インジェクション
- XSS 脆弱性
- 認証・認可の問題
- 機密情報の漏洩
Improvement Suggestions for Legacy Code
このレガシーコードのリファクタリング提案:
- モダンな書き方への変換
- パフォーマンス改善
- テスタビリティ向上
Review Perspectives
1. Security
Check Items:
- OWASP Top 10 Vulnerabilities
- Injection attacks (SQL, command, XSS, etc.)
- Implementation of authentication and authorization
- Data validation and sanitization
- Appropriate use of encryption and hashing
- Hardcoding of sensitive information
- Session management
- CSRF and CORS configuration
- Vulnerabilities in dependencies
Example Output:
## セキュリティ問題
### [CRITICAL] SQL インジェクション脆弱性
**場所**: user_controller.py:45
**問題**: ユーザー入力を直接SQLクエリに連結しています
**影響**: データベースの不正アクセス、データ漏洩の可能性
**現在のコード**:
```python
query = f"SELECT * FROM users WHERE username = '{username}'"
cursor.execute(query)
Recommended Fix:
query = "SELECT * FROM users WHERE username = ?"
cursor.execute(query, (username,))
### 2. パフォーマンス
**チェック項目**:
- アルゴリズムの時間計算量
- 不要なループやネスト
- データベースクエリの最適化(N+1問題)
- メモリリークの可能性
- 非効率なデータ構造
- キャッシュの活用
- 遅延読み込み
- バッチ処理の機会
- 非同期処理の活用
**出力例**:
```markdown
## パフォーマンス改善
### [HIGH] N+1クエリ問題
**場所**: blog_service.ts:78-85
**問題**: ループ内でデータベースクエリを実行しています
**影響**: 100記事で101回のクエリが実行され、レスポンス時間が大幅に増加
**現在のコード**:
```typescript
for (const post of posts) {
post.author = await db.users.findById(post.authorId);
}
Recommended Fix:
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%
### 3. コード品質
**チェック項目**:
- 命名規則の一貫性
- 関数の単一責任原則
- DRY原則(重複の排除)
- マジックナンバーの除去
- コメントの適切性
- エラーハンドリング
- 型安全性
- null/undefined チェック
- コードの複雑度(サイクロマティック複雑度)
**出力例**:
```markdown
## コード品質
### [MEDIUM] 関数が長すぎる(単一責任原則違反)
**場所**: 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);
}
Effect: Improved testability, improved maintainability, improved reusability
### 4. アーキテクチャとデザインパターン
**チェック項目**:
- SOLID原則の適用
- デザインパターンの適切な使用
- レイヤーの分離(関心の分離)
- 依存性注入
- インターフェースの設計
- モジュール性
- スケーラビリティ
- 拡張性
### 5. テスト
**チェック項目**:
- テストの存在
- テストカバレッジ
- テストの品質(AAA パターン)
- エッジケースのカバー
- モックの適切な使用
- テストの独立性
- テストの可読性
### 6. エラーハンドリングとロギング
**チェック項目**:
- 適切な例外処理
- エラーメッセージの明確性
- スタックトレースの保持
- リソースのクリーンアップ
- ロギングレベルの適切性
- 機密情報の非ログ化
### 7. ドキュメンテーション
**チェック項目**:
- コメントの適切性
- API ドキュメント
- 複雑なロジックの説明
- TODO/FIXME の管理
- README の充実度
## レビュー出力形式
### 標準レビューレポート
```markdown
# コードレビュー結果
## サマリー
- **総合評価**: B+ (良好)
- **Critical問題**: 0件
- **High問題**: 2件
- **Medium問題**: 5件
- **Low問題**: 8件
- **改善提案**: 12件
## 重要な問題
### [HIGH] セキュリティ: CSRF保護の欠如
**ファイル**: api/routes.py:45-67
**説明**: POSTエンドポイントにCSRF保護がありません
**推奨**: FlaskのCSRF保護を有効化
**優先度**: 即時対応推奨
### [HIGH] パフォーマンス: 同期的なファイルI/O
**ファイル**: upload_handler.js:89
**説明**: 大きなファイルを同期的に読み込んでいます
**影響**: サーバーブロッキング、タイムアウトの可能性
**推奨**: 非同期I/Oまたはストリーミング処理に変更
## 改善提案
### コード重複の削減
3つのコントローラーで類似の検証ロジックが重複しています。
共通のバリデーターユーティリティの作成を推奨します。
### 型安全性の向上
TypeScriptの`any`型が15箇所で使用されています。
適切な型定義またはインターフェースの作成を推奨します。
## ベストプラクティス
✅ 適切に実装されている点:
- エラーハンドリングが適切
- 一貫した命名規則
- ユニットテストのカバレッジ良好(85%)
## 推奨アクション
1. **即時対応** (Critical/High):
- CSRF保護の実装
- 非同期I/Oへの変更
2. **短期対応** (Medium):
- コード重複の削減
- 型安全性の向上
- 複雑な関数のリファクタリング
3. **長期改善** (Low):
- ドキュメント拡充
- テストカバレッジ向上
- コードコメント改善
Language-Specific Checklist
JavaScript/TypeScript
==Use instead of===usevarUse instead ofconst/letuse- Proper error handling for Promises
- Proper use of async/await
- TypeScript:
anyAvoid excessive use of - React: useEffect dependency array
- Memory leaks (event listeners, timers)
Python
- Compliance with PEP 8 style guide
- Proper use of list/dict comprehension
withResource management with statements- Use of type hints (Python 3.5+)
- Avoidance of global variables
- Proper exception catching (avoiding broad except)
Java
- Utilizing the Stream API
- Proper use of Optional
- try-with-resources for resources
- Overriding equals() and hashCode()
- Recommendation of immutable objects
- Thread safety
Go
- Thorough error handling
- Resource cleanup with defer
- Avoiding goroutine leaks
- Proper use of context
- Pointer vs value receivers
- Avoiding race conditions
Custom rules
Project-specific rules can be defined:
カスタムレビュールール:
- すべてのAPI エンドポイントにレート制限を実装
- データベース移行はロールバック可能に
- すべての公開関数にJSDocコメント必須
- エラーレスポンスは標準フォーマットに従う
Integration with automation
CI/CD pipeline
# .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 }}
pre-commit hook
#!/bin/bash
# .git/hooks/pre-commit
claude-code review --staged --quick
Usage examples
Example 1: PR for adding a new feature
Input:
以下のPRをレビューしてください:
タイトル: ユーザー認証機能の追加
変更ファイル:
- src/auth/login.ts (新規)
- src/auth/jwt.ts (新規)
- src/middleware/auth.ts (新規)
- src/routes/api.ts (変更)
変更内容:
- JWT ベースの認証を実装
- ログインエンドポイントを追加
- 認証ミドルウェアを作成
Output: Comprehensive review of security, token management, and error handling
Example 2: Reviewing a bug fix
Input:
このバグ修正をレビュー:
問題: ユーザーリストの読み込みが遅い
修正内容: クエリの最適化とキャッシング追加
Output: Verification of performance improvements, evaluation of caching strategy, checking edge cases
Example 3: Refactoring
Input:
このリファクタリングをレビュー:
変更: 500行の関数を10個の小さな関数に分割
目的: 保守性とテスタビリティの向上
Output: Application status of SOLID principles, appropriateness of naming, validity of module division
Best practices
Timing for conducting reviews
- When creating a pull request: Grasp the overall picture of the changes
- Before committing: Early problem detection
- Regular code audits: Discovering opportunities to improve existing code
- Before refactoring: Determining improvement priorities
Tips for effective reviews
- Provide context: Explain the purpose and background of the changes
- Specify key points: Clearly state the aspects you especially want attention on
- Review in stages: Split large changes into smaller units
- Utilize feedback: Reflect the points raised in the next code
Utilizing review results
- Prioritization: Address in the order Critical → High → Medium → Low
- Share with the team: Use review results as learning material for the team
- Automation: Turn repeatedly pointed-out issues into linter rules
- Metrics tracking: Monitor the trend of issue occurrence rates
Limitations
- Execution testing is not possible: Only static analysis of code (no actual execution)
- Correctness of business logic: Consistency with requirements requires human judgment
- No guarantee of completeness: Not all bugs or issues can be detected
- Project-specific rules: By default, only general best practices
Integration tools
- GitHub/GitLab: Automatically post as PR comments
- Linters: Recommended for use together with ESLint, Pylint, RuboCop, etc.
- Static Analyzers: Complements SonarQube, CodeClimate, etc.
- Security Scanners: Combined use with Snyk and OWASP Dependency-Check
Version information
- Skill version: 1.0.0
- Last updated: 2025-01-22
Usage example:
このPRをレビューしてください:
ファイル: src/payment/processor.py
変更内容: クレジットカード決済処理の実装
重点チェック項目:
- セキュリティ(カード情報の取り扱い)
- エラーハンドリング
- トランザクション管理
- PCI DSS 準拠
With this prompt, a comprehensive code review report is generated!