2.5 KiB
2.5 KiB
Coding standards
Language and concurrency
- Swift 6 language mode, complete strict concurrency. Zero warnings policy:
-warnings-as-errorsin release CI. - Model shared mutable state as an
actor(SynthesisQueue,ReadingSession). UI-facing types are@MainActor. - No
DispatchQueue.main.asyncin new code. Use@MainActor/MainActor.run. Exception: AX calls run on a dedicated serial queue, bridged withwithCheckedThrowingContinuation. - No
@unchecked Sendablewithout a comment explaining the invariant. AVFoundation wrappers are the expected exception. - Never block an actor on I/O. Every network and AX call is async and cancellable.
- Respect cancellation: check
Task.isCancelled/try Task.checkCancellation()in loops over chunks/segments.
Structure
- One primary type per file. The file name matches the type.
- Protocols at module boundaries (
SpeechSynthesizing,SpeechModelCatalog,AudioPlaying,SelectionCapturing,PasteboardProtocol,AXClient). Concrete types arefinal classorstruct. - The composition root (
AppEnvironment) is the only place that instantiates concrete implementations. - No singletons except Apple-provided ones (
NSWorkspace.shared,NSPasteboard.general). Wrap even these behind protocols where tests need them. publiconly for API used across modules.
Errors and logging
- Throw
VorleserErroracross module boundaries. Internal errors may be module-specific, but they are mapped at the boundary. Loggerper category (see ARCHITECTURE §16). Never interpolate selected text withoutprivacy: .private; prefer counts.fatalError/preconditionFailureonly for programmer errors that tests would catch.
UI
- SwiftUI for views; AppKit for
NSPanel, services, the status item if needed. - Views have no logic beyond formatting. They bind to
SessionViewModel/SettingsViewModel. - Every interactive control has an
accessibilityLabeland a keyboard path. - Strings: use
String(localized:)from the start. English is the base, with German (de) as a second localisation in M8.
Style
- SwiftFormat default rules with 4-space indent and 120-column limit (
.swiftformat). - SwiftLint with
.swiftlint.yml. Warnings are fixed, not suppressed. A disable requires a reason comment. - Doc comments (
///) on all public API.
Git
- Small commits, one task per branch is optional. Conventional commit messages:
feat(ollama): stream PCM chunks (T1.4). - Never commit
Vorleser.xcodeproj,.build/,DerivedData/, or audio files outside the test targets'Fixtures/folders.