This project uses SwiftLint to maintain consistent Swift code quality and catch common issues early in development.
brew install swiftlint# Basic lint check
swiftlint lint
# Auto-fix some issues
swiftlint --fix
# Lint specific files
swiftlint lint XRAiAssistant/XRAiAssistant/ContentView.swiftThe project includes a comprehensive .swiftlint.yml configuration with:
- Line length: Warning at 120, error at 150 characters
- Function length: Warning at 80, error at 120 lines
- File length: Warning at 400, error at 500 lines
- Type length: Warning at 300, error at 400 lines
empty_count- PreferisEmptyovercount == 0empty_string- PreferisEmptyover== ""trailing_closure- Use trailing closure syntax when appropriate
todo- Allow TODO comments during developmenttrailing_whitespace- Auto-fixable, non-critical
- No print statements: Warns about
print()usage, suggests proper logging - 3D/AI naming: Ensures consistent naming for Three.js, React Three Fiber, etc.
- Open your Xcode project
- Select your target → Build Phases
- Add "New Run Script Phase"
- Add this script:
if which swiftlint >/dev/null; then
swiftlint lint --config "${SRCROOT}/.swiftlint.yml"
else
echo "SwiftLint not installed. Install with: brew install swiftlint"
fi- In Xcode, go to Product → Scheme → Edit Scheme
- Select Build → Pre-actions
- Add "New Run Script Action"
- Use the same script as above
- Swift files: ~15-20 files
- Average file length: ~200-300 lines
- Main areas: ContentView, ChatViewModel, CodeSandbox services
- Long functions: Break down functions over 80 lines
- Print statements: Replace with proper logging
- Force unwrapping: Use safe unwrapping patterns
- Line length: Keep lines under 120 characters
Many issues can be auto-fixed:
# Fix formatting issues
swiftlint --fix
# Fix and format in one go
swiftlint --fix --format- Trailing whitespace
- Missing final newlines
- Spacing around operators
- Comma spacing
- Colon spacing
# Quick lint check
swiftlint lint --quiet
# Fix auto-fixable issues
swiftlint --fixBreak down functions over 80 lines:
// ❌ Too long
func handleUserInteraction() {
// 100+ lines of code
}
// ✅ Better
func handleUserInteraction() {
validateInput()
processRequest()
updateUI()
}
private func validateInput() { /* ... */ }
private func processRequest() { /* ... */ }
private func updateUI() { /* ... */ }// ❌ Avoid
print("Debug info: \(value)")
// ✅ Better
import os.log
private let logger = Logger(subsystem: "XRAiAssistant", category: "ContentView")
logger.debug("Debug info: \(value)")// ❌ Force unwrapping
let result = someOptional!
// ✅ Safe unwrapping
guard let result = someOptional else { return }
// or
if let result = someOptional {
// use result
}- Use "Three.js" (not "threejs" or "threeJS")
- Use "React Three Fiber" consistently
- Use "Babylon.js" (not "babylonjs")
- Keep AI provider methods under 60 lines
- Use clear variable names for model parameters
- Document complex AI workflows
- Separate JavaScript injection logic
- Use meaningful function names for bridge methods
- Keep WebView coordinators focused
For automated checking in CI:
# GitHub Actions example
- name: SwiftLint
run: |
brew install swiftlint
swiftlint lint --reporter github-actions-logging- SwiftLint Docs: https://github.com/realm/SwiftLint
- Configuration: See
.swiftlint.ymlin project root - Issues: Check GitHub Issues for SwiftLint-related problems
Maintaining clean, consistent code helps the entire XRAiAssistant development team! 🚀