audit-swiftui-previews

Audit macOS SwiftUI previews for correctness, current APIs, and production conventions.

2|1|Updated Jun 7, 2026
One-click install
npx skills add https://github.com/yigitkonur/plugin-swiftui --skill audit-swiftui-previews-yigitkonur
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: audit-swiftui-previews
Source: https://github.com/yigitkonur/plugin-swiftui/tree/main/plugins/swiftui/skills/audit-swiftui-previews
Command: npx skills add https://github.com/yigitkonur/plugin-swiftui --skill audit-swiftui-previews-yigitkonur

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? SwiftUI previews in macOS projects often contain stale or broken patterns: legacy PreviewProvider structs, bare @State declarations inside #Preview bodies that fail to compile, visionOS-only windowStyle overloads, and missing SwiftData containers or environment injections that crash the Xcode canvas. This Skill systematically detects these defects in existing macOS SwiftUI code. ## Core Features & Use Cases - Nine-rule defect index (prev-01 to prev-09): Detects legacy PreviewProvider structs, missing @Previewable tags, hand-rolled EnvironmentKey boilerplate instead of @Entry, manual .frame sizing instead of preview traits, the visionOS-only windowStyle overload, missing in-memory ModelContainer, missing @Environment injection, wrong .environmentObject injector for @Observable models, and repeated inline containers that should be a shared PreviewModifier. - Hybrid lint engine: Runs tier-1 ripgrep tells plus a tier-2 ast-grep structural rule for bare @State inside #Preview bodies, emitting unified JSON and SARIF output with per-file parse probes. - Grounded verification: Confirms every finding against a corpus of 1,857 real macOS apps via the swiftui-ctx CLI and Apple documentation fetched through Sosumi, with findings written to disk in a unified schema. - Use Case: Point it at a macOS SwiftUI project and receive a structured audit report under swiftui-audits/previews/ with severity, confidence, and suggested fixes for every preview defect. ## Quick Start Audit the SwiftUI previews in my macOS project and report any legacy PreviewProvider structs, missing @Previewable tags, or canvas-crash risks.

Frequently Asked Questions about audit-swiftui-previews

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

FAQPage Schema
How do I audit SwiftUI previews in a macOS project?

Run the shared lint runner with --skill audit-swiftui-previews against your source directory. It locates candidates with grep and ast-grep rules, then each located file is read in full to confirm defects before findings are written to swiftui-audits/previews/.

Why does my SwiftUI preview crash the Xcode canvas?

A #Preview instantiates the view for real, so a @Query or SwiftData view without an in-memory ModelContainer, or a view reading @Environment with no injected dependency, traps the canvas. Inject .modelContainer(for:inMemory:true) or .environment(_:) with a sample model.

What is the difference between #Preview and PreviewProvider?

The #Preview macro is the modern form introduced with Xcode 15 and macOS 14, replacing the legacy struct-based PreviewProvider. PreviewProvider still exists and is not deprecated, but it is flagged as stale for new code.

Does this skill auto-fix the preview defects it finds?

No. Every defect in this domain is flag-only because the correct preview body depends on the view's real dependencies and sample data. Each finding includes a suggested fix grounded in real macOS code examples, but nothing is applied automatically.

Can I use the windowStyle preview overload on macOS?

No. The Preview(_:windowStyle:traits:body:) overload is visionOS-only and will not compile on a Mac target. On macOS, use the plain #Preview macro without a windowStyle argument.