swift-code-review
npx machina-cli add skill jeremieb/swift-unit-test-instructions/swift-code-review --openclawSwift Code Review
Instructions
Step 1: Read All Provided Files
Read every file mentioned or pasted before writing any comments. Do not review code you have not fully read.
If reviewing a PR, ask for:
- The feature or bug being fixed
- The files changed
- Any context about constraints or trade-offs
Step 2: Apply the Review Checklist
Architecture (MVVM)
- Business logic is in ViewModel or Service — not in View/ViewController body
- External dependencies (network, storage, time) are injected via protocol, not hardcoded
- No
URLSession.shared,UserDefaults.standard, orDate()called directly from Views - No global singletons used without injection support
- Thin View layer: no conditional business logic, no data fetching in
onAppearwithout ViewModel delegation
Swift Quality
- No force unwraps (
!) in production paths - Errors propagated via
throwsorResult— not silently swallowed -
letpreferred overvarwhere value does not change - No magic numbers or hardcoded strings — use named constants or localizable strings
- One primary type per file
Concurrency
-
async/awaitused for all new async code (not completion handlers) -
@MainActorapplied to ViewModel and any type that updates UI state - No
DispatchQueue.main.asyncin ViewModel or Service layers - No
sleep()anywhere -
Sendableconformance considered for types crossing actor boundaries -
Taskobjects are stored and cancelled if the parent scope is deallocated
Testing
- New business logic has corresponding tests
- New dependencies are injectable (protocol-backed)
- Existing tests still compile and pass
- No test changes that weaken coverage of critical paths
Naming
- Types:
UpperCamelCase - Functions / variables:
lowerCamelCase - Booleans: assertion form (
isLoading,hasError,canSubmit,isPremium) - Avoid abbreviations unless universally understood (
url,id,api) - Test methods:
test_when_<Condition>_should_<ExpectedOutcome>() - Protocol names: noun or adjective, not
Protocolsuffix (preferUserRepositoryoverUserRepositoryProtocolwhere unambiguous, butProtocolsuffix is acceptable for clarity)
SwiftUI Specific
-
@StateObject/@Stateused in the View that owns the instance -
@ObservedObject/@Bindingused for passed-in instances - No
@EnvironmentObjectused for types that should be injected explicitly -
#Previewcompiles and shows correct content - Accessibility labels on interactive elements that lack visible text
UIKit Specific
- ViewControllers are thin: no network calls, no business logic
-
IBOutletandIBActionlimited to UI wiring only - Memory management: no retain cycles in closures (use
[weak self]) - No layout code hardcoded in
viewDidLoadthat belongs in a dedicated setup method
Step 3: Format the Review
Group by severity. Be specific. Include file name and line number or code excerpt.
## Code Review: [File or Feature Name]
### Critical — Must Fix
These block approval. Fix before merge.
- **[Issue title]** in `FileName.swift`
```swift
// Problematic code
Why: [Clear explanation of the problem and risk] Fix:
// Suggested fix
Suggested — Should Fix
Strong recommendations that improve correctness, testability, or maintainability.
- [Issue] — [file] — [brief explanation and fix direction]
Minor — Nice to Have
Style, preference, or low-risk improvements. Non-blocking.
- [Note]
Approved
What is done well — acknowledge good patterns explicitly.
- [What works well and why]
### Step 4: Final Verdict
End with one of:
- **Approved** — ready to merge as-is
- **Approved with suggestions** — can merge, but consider the Suggested items
- **Changes requested** — Critical items must be resolved before merge
## Examples
### Example 1: ViewModel review
User says: "Review my LoginViewModel"
Actions:
1. Read `LoginViewModel.swift`
2. Read `LoginViewModelTests.swift` (if it exists)
3. Apply checklist
4. Note: is it testable? Are dependencies injected? Is async correct?
5. Output structured feedback
### Example 2: PR review across multiple files
User says: "Review my PR for the checkout feature — here are the changed files"
Actions:
1. Read all changed files
2. Understand the feature end-to-end
3. Apply checklist to each file
4. Identify cross-file issues (e.g., a service that's not injectable, a missing mock)
5. Output grouped review by file, then overall verdict
### Example 3: Quick sanity check
User says: "Is this code correct?"
Actions:
1. Read the code
2. Focus checklist on correctness (async, force unwraps, error handling)
3. Brief response: "This looks correct, but note X" or list Critical issues
## Troubleshooting
**Too many issues to list**: Focus on Critical and top Suggested. List remaining Minor issues as a bullet group: "Additional minor style notes: [list]". Do not overwhelm with exhaustive nit-picking.
**Reviewer disagreement on style**: If the project has a style guide (`CLAUDE.md` or linting config), defer to it. Otherwise, note it as Minor and avoid blocking on pure preference.
**Legacy code with known issues**: When reviewing a small change in a large legacy file, focus the review scope on the changed lines. Do not audit the entire file — note "broader refactoring needed in this file" as a separate future work item.
Source
git clone https://github.com/jeremieb/swift-unit-test-instructions/blob/main/skills/swift-code-review/SKILL.mdView on GitHub Overview
This skill analyzes Swift, SwiftUI, and UIKit code for MVVM compliance, testing standards, naming conventions, async correctness, and anti-patterns. It produces structured feedback grouped by severity to guide fixes before merge. It is ideal when reviewers say review this code, check this PR, code review, is this correct, or give me feedback on implementation.
How This Skill Works
You provide the relevant files or PR context. The reviewer follows a three step workflow: Step 1 read all provided files thoroughly, Step 2 apply a comprehensive review checklist covering Architecture, Swift quality, Concurrency, Testing, Naming, and SwiftUI/UIKit specifics, Step 3 format the findings as a structured review grouped by severity with file references and code excerpts.
When to Use It
- When a developer asks to review a code change or PR
- When validating MVVM compliance and separation of concerns
- When checking asynchronous code and testing standards
- When auditing naming conventions and anti patterns
- When you need actionable feedback with severity levels
Quick Start
- Step 1: Read all provided files to understand scope and context
- Step 2: Apply the review checklist across Architecture, Swift Quality, Concurrency, Testing, Naming, and UI frameworks
- Step 3: Deliver the structured review by severity with file references and suggested fixes
Best Practices
- Ensure business logic resides in ViewModel or a Service, not in the View or ViewController body
- Inject external dependencies via protocols instead of hardcoding services
- Avoid direct calls to URLSession.shared, UserDefaults.standard, or Date in Views
- Prefer let over var for immutable values and avoid magic numbers or hardcoded strings
- Aim for one primary type per file and clear, descriptive naming
Example Use Cases
- Reviewing a PR that adds a SwiftUI screen and its corresponding ViewModel for MVVM alignment
- Auditing a UIKit screen to ensure the ViewController delegates networking to a Service
- Examining a data fetch flow to confirm async await usage and removal of completion handlers
- Verifying tests exist for new business logic and that dependencies are protocol backed
- Flagging anti patterns such as global singletons or excessive inline data processing