Swiftコードの品質レビュー。Swift 6のStrict Concurrency対応、プロトコル指向設計、値型/参照型の使用、エラーハンドリングをチェック。「Swiftコードをレビューして」「Swift 6対応を確認して」で使用。
Swift 6 Strict Concurrency、プロトコル指向設計、型の選択、エラーハンドリングを含むSwiftコードの品質レビューを実施します。「Swiftコードをレビューして」または「Swift 6対応を確認して」で起動し、PRや移行時のコード改善提案を行います。
/plugin marketplace add CAPHTECH/claude-marketplace/plugin install apple-platform-plugin@caphtech-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/error-handling-patterns.mdreferences/swift6-concurrency-checklist.mdSwiftコードの品質レビューを行い、Swift 6時代のベストプラクティスに基づく改善提案を行う。
Swiftコードベースに対して以下の観点でレビューを実施:
対象のSwiftコードを取得:
## Strict Concurrency 観点
### Sendable適合
- [ ] 共有される型にSendable適合があるか
- [ ] @unchecked Sendableの使用は適切か
- [ ] 暗黙的Sendable推論に依存していないか
### Actor分離
- [ ] 適切なActor境界が設定されているか
- [ ] @MainActorの過剰使用がないか
- [ ] nonisolatedの使用は適切か
### データ競合防止
- [ ] 可変状態の共有がないか
- [ ] Task間のデータ受け渡しは安全か
- [ ] クロージャのキャプチャは適切か
## プロトコル設計観点
### 適切な抽象化
- [ ] プロトコルが単一責任を持っているか
- [ ] 過度な抽象化になっていないか
- [ ] Protocol Extensionを活用しているか
### 関連型の設計
- [ ] Associated Typeの制約は適切か
- [ ] Primary Associated Typeを活用しているか(Swift 5.7+)
- [ ] where句による制約は明確か
### 依存性注入
- [ ] プロトコルによる依存性注入が可能か
- [ ] テスタビリティが確保されているか
## 型の選択観点
### 値型(struct, enum)
- [ ] 不変性が活かされているか
- [ ] CoWの意識があるか
- [ ] 値の意味論が適切か
### 参照型(class)
- [ ] 参照型が本当に必要か
- [ ] 継承は適切に使用されているか
- [ ] finalキーワードが適切に付与されているか
### 型の選択基準
- [ ] 同一性(identity)vs 同等性(equality)
- [ ] 可変性の要件
- [ ] パフォーマンス要件
## エラーハンドリング観点
### Swift Error Handling
- [ ] throws/try/catchが適切に使用されているか
- [ ] Result型の使用は適切か
- [ ] エラー型は具体的か(Error vs 具体的なError型)
### Optional処理
- [ ] 強制アンラップ(!)の使用は安全か
- [ ] guard letの活用
- [ ] nil合体演算子(??)のデフォルト値は適切か
### 失敗ケース
- [ ] fatalError/preconditionの使用は適切か
- [ ] 回復可能なエラーと回復不能なエラーの区別
## イディオム観点
### モダンSwift構文
- [ ] if/switch式の活用(Swift 5.9+)
- [ ] 末尾クロージャの適切な使用
- [ ] キーパス(\.)の活用
### コレクション処理
- [ ] map/filter/reduceの適切な使用
- [ ] lazy評価の検討
- [ ] Sequenceプロトコルの活用
### 型安全性
- [ ] タグ付き型(Newtypes)の活用
- [ ] Phantom Typesの検討
- [ ] @frozen/@usableFromInlineの適切な使用
# Swift Code Review Report
## 対象
- ファイル: `path/to/file.swift`
- Swift Version: 6.x
## サマリー
| カテゴリ | 問題数 | 重要度 |
|---------|--------|--------|
| Concurrency | 2 | 🔴 High |
| Protocol Design | 1 | 🟡 Medium |
| Type Choice | 0 | 🟢 OK |
| Error Handling | 1 | 🟡 Medium |
## 詳細
### 🔴 [Concurrency] データ競合リスク
**Location**: `UserManager.swift:45`
**Issue**:
クラスプロパティ`users`が複数のTaskからアクセス可能だが、Sendable適合がない。
**現状コード**:
```swift
class UserManager {
var users: [User] = [] // 危険: 複数Taskからアクセス可能
func addUser(_ user: User) {
users.append(user)
}
}
推奨修正:
actor UserManager {
private var users: [User] = []
func addUser(_ user: User) {
users.append(user)
}
}
理由: Swift 6のStrict Concurrencyでは、共有可変状態へのアクセスはコンパイルエラーになる。 Actorを使用することで、データ競合を防止できる。
...
## ガードレール
### 必須チェック項目
- Swift 6コンパイラ警告の確認
- Sendable適合の検証
- 強制アンラップの使用箇所確認
### 自動修正の制限
- Actor導入は手動確認必須
- プロトコル設計変更は影響範囲を確認
- エラーハンドリング変更はテスト必須
### レビュー対象外
- 生成コード(SwiftGen等)
- 外部ライブラリ
- テストコード(別スキルで対応)
## 関連スキル
- `swift-concurrency`: 並行処理の詳細レビュー
- `swift-protocol`: プロトコル設計の詳細支援
- `swiftui-component`: SwiftUI固有のレビュー
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.