swift-coding-rules

Applies strict Swift coding rules covering type safety, concurrency, testing, and coverage verification.

Updated Oct 15, 2019
One-click install
npx skills add https://github.com/kkkaoru/dotfiles --skill swift-coding-rules-kkkaoru
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swift-coding-rules
Source: https://github.com/kkkaoru/dotfiles/tree/main/.agents/skills/swift-coding-rules
Command: npx skills add https://github.com/kkkaoru/dotfiles --skill swift-coding-rules-kkkaoru

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Swift codebases often accumulate inconsistent style, unsafe patterns like force unwraps and data races, and unverified changes. This Skill enforces a single canonical rule set (SW01–SW37) so every Swift change is planned, implemented, tested, and verified against the same strict standard. ## Core Features & Use Cases - Normative Rule Set: 37 uniquely identified rules covering optionals, error handling, ARC ownership, actor isolation, structured concurrency, SwiftUI state, and diagnostics. - Verification Gates: Requires zero warnings/errors, at least 95% line/function/branch coverage per changed file, and Thread/Address Sanitizer runs for concurrency or unsafe-memory changes. - Bilingual References: English normative rules in references/swift.md, a Japanese translation in references/swift.ja.mdx, and sources.md documenting official Swift research and version caveats. - Use Case: When asked to add a feature to a Swift package, the agent reads the rules, plans isolation and ownership boundaries, implements without force unwraps or unstructured tasks, adds Swift Testing cases, and reports exact build/test/coverage results before claiming completion. ## Quick Start Apply the swift-coding-rules skill to review and refactor the Swift files in this package, then run the build, tests, and coverage checks.

Frequently Asked Questions about swift-coding-rules

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce Swift coding standards in a project?

Adopt a single normative rule set like this one, which defines 37 rules (SW01–SW37) covering types, errors, concurrency, and testing. Pair it with the configured build, lint, format, and test toolchain so every change is verified against the same gates.

What Swift concurrency rules prevent data races?

Rules SW19–SW26 require checking isolation settings, protecting shared mutable state with actors, using checked Sendable conformances, preferring structured concurrency over unstructured Tasks, and treating cancellation and reentrancy explicitly. @unchecked Sendable and Task.detached need documented approval.

Should I use Swift Testing or XCTest for unit tests?

For new projects on a supported Swift 6 toolchain, prefer built-in Swift Testing with @Test, #expect, and #require and no extra package dependency. Keep XCTest for existing suites, UI automation, and performance measurement rather than rewriting them.

Are force unwraps allowed in Swift under these rules?

No. Rule SW07 prohibits new force unwraps, forced casts, and implicitly unwrapped optionals in both production and test code. Unavoidable framework contracts require explicit prior approval, documented lifetime guarantees, and compensating tests.

What code coverage is required for Swift changes?

Rule SW36 requires at least 95% line and function coverage per changed testable file, plus 95% branch coverage where the toolchain supports it. File-level reports must be inspected, and exemptions need documented justification and explicit approval.