Swift Code Quality Rules

VerifiedSafe

Swift code quality rules enforcing file size limits, @Observable, no singletons in views, no direct Defaults access, and protocol-based services.

Sby Skills Guide Bot
DevelopmentIntermediate
7/22/2026
Claude Code
#swift#code-quality#macos#architecture#conventions

Recommended for

Automated summary

A set of mach-mono-specific Swift quality rules, auto-loaded when editing .swift files, enforcing file-size limits, environment injection, @Observable state and protocol-based services.

Strengths

  • Concrete, checkable rules: hard 300-line limit, 200-line target, and a pre-commit checklist
  • Side-by-side ❌ banned and ✅ required snippets for singletons, Defaults access and ObservableObject
  • Explicit allowlist of permitted .shared exceptions, removing ambiguity
  • Loads automatically from the path glob, so no manual invocation is needed

Limitations

  • Tightly coupled to the mach-mono repo (NotchSettings.swift, bazelisk build //Apps/machNotch) and hard to reuse elsewhere
  • These are agent instructions only; nothing is enforced by an actual linter
  • Does not cover testing strategy or naming style beyond declaration ordering
When to use it

Use it whenever an agent edits or creates Swift code in the mach-mono repository and must follow local architecture conventions.

When not to use it

Not useful on another Swift project or for general SwiftUI questions, since the rules and exceptions reference mach-mono internals.

Security analysis

Safe
Quality score88/100

This skill is a pure style/convention guide for Swift code. It contains no executable instructions, no shell pipelines, no network access, and no handling of secrets or credentials. The only command mentioned is a routine `bazelisk build` in a checklist item, which the agent would run in the normal course of verifying a build. The declared scope is limited to `**/*.swift` files and it is not user-invocable, so blast radius is minimal.

No concerns found

How this analysis is made

Examples

Split an oversized view file
NotchContentView.swift is now 340 lines. Split it so every file stays under 300 lines, keeping protocol conformances in separate extension files, and make sure bazelisk build //Apps/machNotch:machNotch still passes.
Add a new view model
Create a new ViewModel for the plugin settings panel in mach-mono following our Swift quality rules — @Observable, @MainActor, final class, injected via @Environment instead of a .shared singleton.
Remove singleton and Defaults usage
Refactor this Swift view: replace the SomeManager.shared access with a protocol-based service injected in init, and swap the direct @Default(.someSetting) usage for @Environment(\.bindableSettings).

name: swift-code-quality description: 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. user-invocable: false paths: "**/*.swift"

Swift Code Quality Rules

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

File Size

| Limit | Rule | |---|---| | 300 lines | Hard limit — files exceeding this must be split | | 200 lines | Target — 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

From the file to a first result

The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.

View the source and supporting files

This download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.

1. Download the file

Download SKILL.md

From the root of a test project, save the file as .skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.

Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.

mkdir -p '.skill-downloads/swift-code-quality-rules-mrwaka00' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/swift-code-quality-rules-mrwaka00/download' --output '.skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md.part' && mv '.skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md.part' '.skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md'

2. Check prerequisites

Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.

No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.

The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.

3. Load the skill

After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.

Claude Code
test -f '.skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md' && test -s '.skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/swift-code-quality' && cp -R '.skill-downloads/swift-code-quality-rules-mrwaka00' '.claude/skills/swift-code-quality'

OpenSkills

OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.

Official OpenSkills installation
openskills install './.skill-downloads/swift-code-quality-rules-mrwaka00'

openskills read 'swift-code-quality-rules-mrwaka00'

Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.

For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.

openskills sync

Manual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.

4. Try a first task

Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:

Read .skill-downloads/swift-code-quality-rules-mrwaka00/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.

Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.

Related skills