SW

swift-code-quality

Automates Swift code quality checks and enforcement for strict codebase standards.

Install

mkdir -p .claude/skills/swift-code-quality && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/16744" && unzip -o skill.zip -d .claude/skills/swift-code-quality && rm skill.zip

Installs to .claude/skills/swift-code-quality

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Swift code quality rules for mach-mono — 300-line file limit, @Observable, no singletons in views, no direct Defaults access, protocol-based services. Auto-loaded when editing .swift files.
189 chars✓ has a “when” trigger
Beginner

Key capabilities

  • Enforce a 300-line file limit for Swift files
  • Require the use of @Observable for UI-related classes
  • Prevent direct access to `Defaults` outside `NotchSettings.swift`
  • Ensure services are protocol-based
  • Ban singletons in views and services

How it works

The skill automatically loads when a `.swift` file is edited and checks the code against predefined quality rules.

Inputs & outputs

You give it
A Swift file (`.swift`) being edited
You get back
Identification of code quality violations based on defined rules

When to use swift-code-quality

  • Check file size limits
  • Enforce clean dependency injection
  • Validate Swift architecture

About this skill

Swift Code Quality Rules

Full reference: docs/AGENT-GUIDELINES.md → Swift Code Quality Rules.

File Size

LimitRule
300 linesHard limit — files exceeding this must be split
200 linesTarget — prefer smaller, focused files

When approaching 300 lines: extract cohesive responsibilities into separate files, use extensions in separate files for protocol conformances.

No Singletons in Views or Services

// ❌ BANNED
@Bindable var coordinator = NotchViewCoordinator.shared
let manager = SomeManager.shared

// ✅ REQUIRED — environment injection
@Environment(NotchViewModel.self) private var viewModel
@Environment(\.pluginManager) private var pluginManager

// ✅ REQUIRED — init injection
init(service: SomeServiceProtocol) { ... }

Allowed .shared exceptions: NSWorkspace, NSApplication, URLSession, URLCache, XPCHelperClient, FullScreenMonitor, QLThumbnailGenerator, QLPreviewPanel, NSScreenUUIDCache, SkyLightOperator, DefaultsNotchSettings (injection root only), ScreenDisplayRegistry (system-level screen cache).

No Direct Defaults Access

// ❌ BANNED everywhere except NotchSettings.swift
Defaults[.someSetting]
@Default(.someSetting) var setting

// ✅ REQUIRED
settings.someSetting
@Environment(\.bindableSettings) private var settings

Exception: NotchSettings.swift is the only file allowed direct Defaults access.

Observable State

// ✅ REQUIRED
@Observable
@MainActor
final class SomeViewModel { ... }

// ❌ BANNED
class SomeViewModel: ObservableObject {
    @Published var state: State
}

All UI-related protocols and classes must be @MainActor.

Protocol-Based Services

// Protocol in separate file
protocol SomeServiceProtocol: Sendable {
    func doThing() async throws
}

// Implementation
final class SomeService: SomeServiceProtocol { ... }

Never depend on concrete service types — always use the protocol.

File Organization Order

  1. Imports
  2. Type declaration + stored properties
  3. Initializers
  4. Public/internal methods
  5. Private methods
  6. Extensions (prefer separate files for large protocol conformances)

Commit Checklist Before Submitting Swift Changes

  • File stays under 300 lines (if split, both files build)
  • No new .shared access in views or services
  • No new direct Defaults[.] outside NotchSettings.swift
  • New state classes use @Observable @MainActor final class
  • New services have a protocol
  • bazelisk build //Apps/machNotch:machNotch passes

Codex Invocation

Use this skill for Swift file edits and reviews. Codex does not enforce Claude paths or user-invocable metadata, so the file-scope trigger is preserved in the description.

When not to use it

  • When developing Swift code that does not need to adhere to mach-mono quality standards
  • When working on files that are explicitly allowed exceptions, such as `NSWorkspace` for singletons

Limitations

  • The skill is specific to Swift code quality rules for mach-mono.
  • The skill applies rules to `.swift` files only.

How it compares

This skill automatically checks Swift code against a specific set of architectural and style rules, unlike manual code reviews that rely on human memory.

Compared to similar skills

swift-code-quality side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
swift-code-quality (this skill)03moNo flagsBeginner
swift-concurrency-expert45moNo flagsAdvanced
ios-dev-guidelines36moNo flagsBeginner
swiftui-performance-developer16moNo flagsIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry