Skip to main content
ClaudeWave
Skill732 repo starsupdated 15d ago

swiftlint

SwiftLint enforces Swift style and conventions by linting source files against a configurable rule set. This skill covers setting up SwiftLint via build tool plugins or run scripts, configuring rules through .swiftlint.yml, managing rule suppressions and baselines, integrating with CI pipelines, and planning rollout strategies for existing codebases. Use when implementing automated style enforcement, selecting appropriate linting rules, suppressing specific warnings, establishing code quality standards, or integrating linting into continuous integration workflows.

Install in Claude Code
Copy
git clone --depth 1 https://github.com/dpearson2699/swift-ios-skills /tmp/swiftlint && cp -r /tmp/swiftlint/skills/swiftlint ~/.claude/skills/swiftlint
Then start a new Claude Code session; the skill loads automatically.

SKILL.md

# SwiftLint

SwiftLint enforces Swift style and conventions by linting source files against a configurable rule set. It is the most widely adopted Swift linter. This skill covers setup, configuration, rule selection, suppression, CI integration, and rollout strategy.

SwiftLint is a **style enforcement tool**, not a style guide. For underlying Swift naming and design conventions, see `swift-api-design-guidelines`. For architecture patterns, see `swift-architecture`.

## Contents

- [Recommended Setup](#recommended-setup)
- [Configuration](#configuration)
- [Rule Selection Strategy](#rule-selection-strategy)
- [Suppressions](#suppressions)
- [Baselines](#baselines)
- [Autocorrect](#autocorrect)
- [CI Integration](#ci-integration)
- [Integration Decision Tree](#integration-decision-tree)
- [Multiple Configurations](#multiple-configurations)
- [Common Mistakes](#common-mistakes)
- [Review Checklist](#review-checklist)
- [References](#references)

---

## Recommended Setup

**Default: build tool plugin via `SimplyDanny/SwiftLintPlugins`.**

Add the plugin package to `Package.swift` or via Xcode's package dependencies:

```swift
// Package.swift
dependencies: [
  .package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "<reviewed-version>")
]
```

For SwiftPM targets, apply the plugin:

```swift
.target(
    name: "MyApp",
    plugins: [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")]
)
```

For Xcode projects without a `Package.swift`, add the package dependency in the project settings, then enable the plugin under the target's Build Phases or the package's plugin trust dialog.

The build tool plugin runs SwiftLint automatically on every build. No run script required.

> **First build**: Xcode prompts to trust the plugin. Select "Trust & Enable All" for the SwiftLintPlugins package.

For alternatives (run scripts, command plugin, Homebrew CLI), see [references/plugins-run-scripts-and-integrations.md](references/plugins-run-scripts-and-integrations.md).

## Configuration

Create `.swiftlint.yml` at the project root. SwiftLint discovers this file by walking up from each source file's directory.

```yaml
# .swiftlint.yml — conservative starter config
disabled_rules:
  - trailing_whitespace
  - todo

opt_in_rules:
  - empty_count
  - closure_spacing
  - force_unwrapping
  - sorted_imports
  - vertical_whitespace_opening_braces
  - private_swiftui_state
  - unhandled_throwing_task
  - accessibility_label_for_image

included:
  - Sources
  - Tests

excluded:
  - .build
  - DerivedData
  - "**/.build"
  - "**/Generated"

line_length:
  warning: 140
  error: 200

type_body_length:
  warning: 300
  error: 500

file_length:
  warning: 500
  error: 1000
```

Key configuration options:

| Key | Purpose |
|-----|---------|
| `disabled_rules` | Turn off default-enabled rules |
| `opt_in_rules` | Turn on rules not enabled by default |
| `only_rules` | Use _only_ the listed rules (mutually exclusive with `disabled_rules`/`opt_in_rules`) |
| `analyzer_rules` | Rules requiring compiler logs (run via `swiftlint analyze`) |
| `baseline` | Path to an existing baseline file used to suppress known violations |
| `write_baseline` | Path where SwiftLint should write a new baseline file |
| `included` | Paths to lint (default: current directory) |
| `excluded` | Paths to skip |
| `strict` | Elevate all warnings to errors |
| `lenient` | Downgrade all errors to warnings |
| `allow_zero_lintable_files` | Suppress the error when no Swift files are found |
| `reporter` | Output format: `xcode` (default), `json`, `checkstyle`, `sarif`, `csv`, `emoji`, etc. |

For full configuration details including severity tuning, environment-variable interpolation, and nested/remote configs, see [references/adoption-and-configuration.md](references/adoption-and-configuration.md).

## Rule Selection Strategy

SwiftLint ships with three rule categories:

1. **Default rules** — enabled automatically, cover widely accepted conventions
2. **Opt-in rules** — disabled by default, enable selectively via `opt_in_rules`
3. **Analyzer rules** — require compiler logs, enabled via `analyzer_rules`

Browse the full categorized list at <https://realm.github.io/SwiftLint/rule-directory.html>.

**Recommended approach for new projects:**

1. Start with defaults. Run `swiftlint rules` to see which rules are enabled.
2. Disable rules that conflict with your team's established conventions.
3. Add opt-in rules one at a time. Review violations before committing each addition.
4. Do not use `only_rules` unless you have a specific reason to start from zero.

**Recommended approach for existing codebases:**

1. Start with the default rule set.
2. Create a baseline (see [Baselines](#baselines)) to suppress all existing violations.
3. Enforce zero new violations in CI.
4. Burn down baseline violations incrementally.

Do not transcribe or memorize the rule directory. Look up rule identifiers and configuration options at the official rule directory when needed.

## Suppressions

Suppress SwiftLint for specific lines when a rule produces a false positive or when the violation is intentional and reviewed.

```swift
// swiftlint:disable:next force_cast
let view = object as! UIView

let legacy = try! JSONDecoder().decode(T.self, from: data) // swiftlint:disable:this force_try

// swiftlint:disable:previous large_tuple
```

Disable for a region:

```swift
// swiftlint:disable cyclomatic_complexity
func complexRouter(...) { ... }
// swiftlint:enable cyclomatic_complexity
```

Disable all rules (use sparingly):

```swift
// swiftlint:disable all
// ... generated or legacy code ...
// swiftlint:enable all
```

**Policy:**
- Prefer targeted single-rule suppressions over `all`.
- Always re-enable after the region ends.
- For generated code, prefer `excluded` paths in `.swiftlint.yml` over inline suppressions.
- For test targets with different tolerance, use a child configuration (see [Multiple Configurations](#multiple-configurations)).
accessorysetupkitSkill

Discover and configure Bluetooth and Wi-Fi accessories using AccessorySetupKit. Use when presenting a privacy-preserving accessory picker, defining discovery descriptors for BLE or Wi-Fi devices, handling accessory session events, migrating from CoreBluetooth permission-based scanning, or setting up accessories without requiring broad Bluetooth permissions.

activitykitSkill

Implement, review, or improve Live Activities and Dynamic Island experiences in iOS apps using ActivityKit. Use when building real-time updating widgets for the Lock Screen and Dynamic Island — delivery tracking, sports scores, ride-sharing status, workout timers, media playback, or any time-sensitive information that updates in real time. Also use when working with ActivityKit, ActivityAttributes, Activity lifecycle (request/update/end), Dynamic Island layouts (compact/minimal/expanded), push-to-update Live Activities, or Lock Screen live widgets.

adattributionkitSkill

Measure ad effectiveness with privacy-preserving attribution using AdAttributionKit. Use when registering ad impressions, handling attribution postbacks, updating conversion values, implementing re-engagement attribution, configuring publisher or advertiser apps, or replacing SKAdNetwork with AdAttributionKit for ad measurement.

alarmkitSkill

Implement AlarmKit alarms and countdown timers for iOS and iPadOS with Lock Screen, Dynamic Island, StandBy, and paired Apple Watch system UI. Covers AlarmManager scheduling, AlarmAttributes and AlarmPresentation, AlarmButton stop and snooze actions, authorization, state observation, countdown widget-extension handoff, and Live Activity integration. Use when building wake-up alarms, countdown timers, or alarm-style alerts that need Apple's system alarm experience.

app-clipsSkill

Build iOS App Clips with invocation URLs, App Clip Codes, NFC, QR codes, Safari banners, Maps, Messages, target setup, App Store Connect experiences, size/capability constraints, NSUserActivity routing, SKOverlay promotion, App Group/keychain handoff, ephemeral notifications, location confirmation, and full-app migration. Use when creating App Clips or wiring App Clip invocation, experience configuration, or full-app handoff.

app-intentsSkill

Implement App Intents for Siri, Shortcuts, Spotlight, widgets, Control Center, and Apple Intelligence on iOS. Covers AppIntent actions, AppEntity and EntityQuery models, AppShortcutsProvider phrases, IndexedEntity Spotlight indexing, WidgetConfigurationIntent, SnippetIntent, and assistant schemas. Use when exposing app actions or entities to system surfaces.

app-store-optimizationSkill

Optimize App Store product pages for search visibility and conversion. Use for App Store Optimization (ASO), keyword research, app name/subtitle/keyword-field strategy, conversion-focused descriptions and promotional text, screenshot captions and ordering, Custom Product Pages with assigned search keywords, In-App Events, Product Page Optimization tests, localized metadata, ratings/review strategy, and in-app review prompt timing with RequestReviewAction or AppStore.requestReview. Also use when routing ASO vs App Store review, privacy/ATT, or StoreKit implementation boundaries.

app-store-reviewSkill

Prepare for App Store review and prevent rejections. Covers App Store review guidelines, app rejection reasons, PrivacyInfo.xcprivacy privacy manifest requirements, required API reason codes, in-app purchase IAP and StoreKit rules, App Store Guidelines compliance, ATT App Tracking Transparency, EU DMA Digital Markets Act, HIG compliance checklist, app submission preparation, review preparation, metadata requirements, entitlements, widgets, and Live Activities review rules. Use when preparing for App Store submission, fixing rejection reasons, auditing privacy manifests, implementing ATT consent flow, configuring StoreKit IAP, or checking HIG compliance.