This skill should be used when the user asks to "check code quality", "find memory leaks", "detect thread safety issues", "scan for retain cycles", "audit Swift code", "find force unwraps", or needs guidance on iOS code quality patterns and best practices.
From ios-dev-toolkitnpx claudepluginhub nbkm8y5/claude-plugins --plugin ios-dev-toolkitThis skill uses the workspace's default tool permissions.
references/accessibility-localization.mdreferences/memory-management.mdreferences/optional-safety.mdreferences/swiftui-antipatterns.mdreferences/thread-safety.mdscripts/detect_infinite_loops.pyscripts/scan_code_quality.pySearches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides implementation of event-driven hooks in Claude Code plugins using prompt-based validation and bash commands for PreToolUse, Stop, and session events.
Comprehensive code quality auditing for iOS/Swift projects covering memory management, thread safety, optional handling, SwiftUI patterns, accessibility, and more.
For quick automated analysis:
python3 scripts/scan_code_quality.py /path/to/project code_quality_report.md
python3 scripts/detect_infinite_loops.py /path/to/project loop_risks_report.md
This generates reports on:
For comprehensive human-guided audits, follow the workflows below.
Use when reviewing entire codebase or establishing quality baseline.
Run automated scans first (if desired for quick wins)
python3 scripts/scan_code_quality.py /path/to/project
python3 scripts/detect_infinite_loops.py /path/to/project
Review scan results - Fix critical issues immediately
Deep dive by category - Use reference checklists:
references/memory-management.mdreferences/thread-safety.mdreferences/swiftui-antipatterns.mdreferences/optional-safety.mdreferences/accessibility-localization.mdCompile findings - Create prioritized issue list
Create action plan - Organize by severity and effort
Use before major releases or App Store submissions.
Critical items only (these can crash or severely impact users):
Memory leaks - Run automated scan, check for:
Thread safety - Verify:
Force unwraps - Search and eliminate:
! in production code (except IBOutlets)as! force caststry! without justificationAccessibility - Validate:
Use when addressing specific issues or learning a domain.
Pick a category:
references/memory-management.mdreferences/thread-safety.mdreferences/swiftui-antipatterns.mdreferences/optional-safety.mdreferences/accessibility-localization.mdThen:
Use when reviewing pull requests or new features.
Run automated scan on changed files
# Scan specific files
python3 scripts/scan_code_quality.py /path/to/feature-branch
Quick checklist for new code:
Review against anti-patterns - Check relevant reference
Verify tests - New code should have tests
Each reference provides comprehensive checklists with examples:
references/memory-management.mdreferences/thread-safety.mdreferences/swiftui-antipatterns.mdreferences/optional-safety.mdreferences/accessibility-localization.mdscripts/scan_code_quality.pyScans Swift files for common issues.
Usage:
python3 scripts/scan_code_quality.py <project_path> [output_file]
Detects:
Output: Markdown report with severity levels and suggestions
scripts/detect_infinite_loops.pyDetects loop and calculation risks.
Usage:
python3 scripts/detect_infinite_loops.py <project_path> [output_file]
Detects:
Output: Markdown report with risk levels
All reports follow this structure:
# Issue Category
**File:** `path/to/File.swift:123`
**Issue:** Description of the problem
**Code:**
```swift
// Problematic code snippet
Suggestion: How to fix it
Severity Levels:
## Tips for Effective Audits
### For Large Projects
1. **Start with automated scans** - Get quick overview
2. **Prioritize by severity** - Fix critical issues first
3. **Batch similar issues** - More efficient remediation
4. **Create tracking issues** - Don't lose track of findings
### For New Projects
1. **Run early and often** - Catch issues when easy to fix
2. **Set up CI integration** - Automated checks on PRs
3. **Create team guidelines** - Document decisions
4. **Use as learning tool** - Teach team best practices
### For Legacy Code
1. **Focus on hot paths** - Audit code that runs frequently
2. **Prioritize user-facing** - Fix what users encounter
3. **Document known issues** - Track technical debt
4. **Incremental improvement** - Don't try to fix everything at once
## False Positives
Some patterns the automated scanners flag are actually acceptable:
### Acceptable Force Unwraps
- `@IBOutlet weak var tableView: UITableView!`
- `let url = URL(string: "https://known-valid.com")!`
- `let image = UIImage(systemName: "star")!` (system symbols)
- Test assertions: `let result = try! sut.parse(validInput)`
### Acceptable Implicitly Unwrapped
- IBOutlets in view controllers
- Test mock properties
- Framework-required patterns
### Acceptable Strong Self
- Non-escaping closures
- GCD sync operations
- SwiftUI view builders
**Always review flagged issues** - Automated tools aren't perfect.
## Integration with Development Workflow
### Pre-commit Hook
```bash
#!/bin/bash
python3 .skills/ios-code-quality-auditor/scripts/scan_code_quality.py . /tmp/audit.md
if grep -q "CRITICAL" /tmp/audit.md; then
echo "❌ Critical code quality issues found"
cat /tmp/audit.md
exit 1
fi
- name: Code Quality Audit
run: |
python3 scripts/scan_code_quality.py . audit_report.md
# Upload artifact or fail on critical issues
## Code Quality Checklist
- [ ] No force unwraps introduced
- [ ] Proper memory management
- [ ] Thread-safe UI updates
- [ ] SwiftUI patterns correct
- [ ] Accessibility labels added
- [ ] Strings localized
Pattern 1: Timer retain cycle
// Bad
timer = Timer.scheduledTimer(target: self, selector: #selector(tick), ...)
// Good
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
self?.tick()
}
Pattern 2: UI update from background
// Bad
Task {
let data = await fetchData()
tableView.reloadData() // ⚠️ May not be on main thread
}
// Good
Task {
let data = await fetchData()
await MainActor.run {
tableView.reloadData()
}
}
Pattern 3: Force unwrap in production
// Bad
let user = currentUser! // ⚠️ Crash if nil
// Good
guard let user = currentUser else { return }
Pattern 4: SwiftUI state management
// Bad
@ObservedObject var viewModel = ViewModel() // Recreated on render
// Good
@StateObject private var viewModel = ViewModel()
Pattern 5: Optional chaining
// Bad
if let user = user {
if let address = user.address {
if let city = address.city {
print(city)
}
}
}
// Good
if let city = user?.address?.city {
print(city)
}
The Python scripts are starting points. Consider adding:
The goal isn't perfect code - it's robust, maintainable code that serves users well. Use these audits to:
Happy auditing! 🔍✨