swiftlint
Configures and enforces SwiftLint in Swift projects using build tool plugins, run scripts, and CI. Covers .swiftlint.yml configuration, disabled_rules, opt_in_rules, only_rules, analyzer_rules, baselines, autocorrect, swiftlint:disable suppressions, reporter formats (sarif, json, checkstyle), strict and lenient modes, SwiftLintBuildToolPlugin via SimplyDanny/SwiftLintPlugins, swift package plugin swiftlint, Xcode run script phases, CI integration, multiple configuration files, and rollout strategies for existing codebases. Use when setting up SwiftLint, configuring lint rules, suppressing warnings, creating baselines, choosing between build tool plugin and run script, or integrating SwiftLint into CI.
What this skill does
# 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)).
For full suppression syntax, see [references/rules-suppressions-and-baselines.md](references/rules-suppressions-and-baselines.md).
## Baselines
Baselines let you adopt SwiftLint in an existing codebase without fixing every legacy violation first.
**Create a baseline:**
```sh
swiftlint --write-baseline .swiftlint.baseline
```
This records all current violations. Future runs compare against this baseline and only report new violations.
**Use the baseline:**
```sh
swiftlint --baseline .swiftlint.baseline
```
In CI, pass `--baseline` so only new violations fail the build. Burn down the baseline over time by fixing legacy violations and regenerating.
For baseline workflows and rollout strategy, see [references/rules-suppressions-and-baselines.md](references/rules-suppressions-and-baselines.md).
## Autocorrect
SwiftLint can fix some violations automatically:
```sh
swiftlint --fix
# or the legacy alias:
swiftlint --autocorrect
```
**Warnings:**
- **Never run `--fix` as a pre-compile build phase.** Auto-fixes modify source files. If run automatically on every build, this creates an unpredictable edit-build loop and can mask real issues.
- Run `--fix` manually or in a dedicated CI step, then review the diff.
- Not all rules support autocorrect. Check `swiftlint rules` — the "Correctable" column shows which rules can auto-fix.
- Always commit or stash before running `--fix`.
## CI Integration
CI is the primary enforcement surface. A CI check ensures no one merges code that increases the violation count.
**Recommended CI pattern:**
```yaml
# GitHub Actions example
- name: Lint
run: |
brew install swiftlint
swiftlint --strict --reporter sarif > swiftlint.sarif
```
Key CI options:
| Flag | Effect |
|------|--------|
| `--strict` | Exits non-zero on warnings (not just errors) |
| `--reporter sarif` | GitHub Advanced Security compatible output |
| `--reporter json` | Machine-readable output |
| `--reporter checkstyle` | Jenkins/SonarQube compatible |Related in Cloud & DevOps
appbuilder-action-scaffolder
IncludedCreate, implement, deploy, and debug Adobe Runtime actions with consistent layout, validation, and error handling. Use this skill whenever the user needs to add actions to an App Builder project, understand action structure (params, response format, web/raw actions), configure actions in the manifest, use App Builder SDKs (State, Files, Events, database), deploy and invoke actions via CLI, debug action issues, or implement patterns such as webhook receivers, custom event providers, journaling consumers, large payload redirects, action sequence pipelines, and Asset Compute workers. Also trigger when users mention serverless functions in Adobe context, action logging, IMS authentication for actions, or cron-style scheduled actions.
orchestrating-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. Use this skill when the user needs a multi-step Data Cloud pipeline, cross-phase troubleshooting, or data space and data kit management. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase sf data360 workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching phase-specific skill), the task is STDM/session tracing/parquet telemetry (use observing-agentforce), standard CRM SOQL (use querying-soql), or Apex implementation (use generating-apex).
github-project-automation
IncludedAutomate GitHub repository setup with CI/CD workflows, issue templates, Dependabot, and CodeQL security scanning. Includes 12 production-tested workflows and prevents 18 errors: YAML syntax, action pinning, and configuration. Use when: setting up GitHub Actions CI/CD, creating issue/PR templates, enabling Dependabot or CodeQL scanning, deploying to Cloudflare Workers, implementing matrix testing, or troubleshooting YAML indentation, action version pinning, secrets syntax, runner versions, or CodeQL configuration. Keywords: github actions, github workflow, ci/cd, issue templates, pull request templates, dependabot, codeql, security scanning, yaml syntax, github automation, repository setup, workflow templates, github actions matrix, secrets management, branch protection, codeowners, github projects, continuous integration, continuous deployment, workflow syntax error, action version pinning, runner version, github context, yaml indentation error
sf-datacloud
IncludedSalesforce Data Cloud product orchestrator for connect→prepare→harmonize→segment→act workflows. TRIGGER when: user needs a multi-step Data Cloud pipeline, asks to set up or troubleshoot Data Cloud across phases, manages data spaces or data kits, or wants a cross-phase `sf data360` workflow. DO NOT TRIGGER when: work is isolated to a single phase (use the matching sf-datacloud-* skill), the task is STDM/session tracing/parquet telemetry (use sf-ai-agentforce-observability), standard CRM SOQL (use sf-soql), or Apex implementation (use sf-apex).
fabric-cli
IncludedUse this skill for Fabric.so CLI workflows with the `fabric` terminal command: diagnose/install/login, search or browse a Fabric library, save notes/links/files, create folders, ask the Fabric AI assistant, manage tasks/workspaces, generate shell completion, check subscription usage, produce JSON output, and use Fabric as persistent agent memory. Do not use for Microsoft Fabric/Azure/Power BI `fab`, Daniel Miessler's Fabric framework, Python Fabric SSH, Fabric.js, or textile/fashion fabric.
lark
IncludedLark/Feishu CLI skills: lark-cli operations for docs, markdown, sheets, base, calendar, im, mail, task, okr, drive, wiki, slides, whiteboard, apps, approval, attendance, contact, vc, minutes, event. Use when the user needs to operate Lark/Feishu resources via lark-cli, send messages, manage documents, spreadsheets, calendars, tasks, OKRs, deploy web pages, or any Feishu/Lark workspace operations.