Files
Vorleser-Kit/docs/CODING_STANDARDS.md
T

43 lines
2.5 KiB
Markdown

# Coding standards
## Language and concurrency
- Swift 6 language mode, **complete** strict concurrency. Zero warnings policy: `-warnings-as-errors` in release CI.
- Model shared mutable state as an `actor` (`SynthesisQueue`, `ReadingSession`). UI-facing types are `@MainActor`.
- No `DispatchQueue.main.async` in new code. Use `@MainActor` / `MainActor.run`. Exception: AX calls run on a dedicated serial queue, bridged with `withCheckedThrowingContinuation`.
- No `@unchecked Sendable` without 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 are `final class` or `struct`.
- 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.
- `public` only for API used across modules.
## Errors and logging
- Throw `VorleserError` across module boundaries. Internal errors may be module-specific, but they are mapped at the boundary.
- `Logger` per category (see ARCHITECTURE §16). Never interpolate selected text without `privacy: .private`; prefer counts.
- `fatalError` / `preconditionFailure` only 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 `accessibilityLabel` and 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.