ScriptsMay 29, 2026·3 min read

SwiftLint — Enforce Swift Style and Conventions

A tool to enforce Swift style and conventions based on the community Swift style guide, with over 200 built-in rules and auto-correction support.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
SwiftLint Overview
Direct install command
npx -y tokrepo@latest install 038be131-5b15-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

SwiftLint checks Swift code against a set of style rules derived from the community Swift style guide. It integrates into Xcode build phases, CI pipelines, and editors to catch style violations and potential bugs before code review.

What SwiftLint Does

  • Analyzes Swift source files against 200+ configurable lint rules
  • Auto-corrects fixable violations with the --fix flag
  • Supports custom rules defined via regular expressions in .swiftlint.yml
  • Integrates as an Xcode build phase to show warnings inline
  • Reports results in multiple formats including JSON, HTML, and Xcode-compatible output

Architecture Overview

SwiftLint is written in Swift and uses SourceKit to parse Swift source files into an abstract syntax tree. Each rule is implemented as a self-contained module that inspects the AST or raw token stream. The configuration layer reads .swiftlint.yml to enable, disable, or customize rules per project or directory.

Self-Hosting & Configuration

  • Install via Homebrew (brew install swiftlint), Mint, CocoaPods, or download the binary from GitHub releases
  • Create a .swiftlint.yml file in your project root to configure enabled/disabled rules
  • Add a Run Script build phase in Xcode to run SwiftLint on each build
  • Set excluded paths to skip generated code or third-party dependencies
  • Configure custom_rules with regex patterns for project-specific conventions

Key Features

  • Over 200 built-in rules covering style, naming, metrics, and potential bugs
  • Auto-correction for many violations with swiftlint --fix
  • Per-directory configuration with nested .swiftlint.yml files
  • Inline rule suppression using // swiftlint:disable comments
  • Support for analyzing Swift Package Manager projects and Xcode workspaces

Comparison with Similar Tools

  • SwiftFormat — focuses purely on formatting and code style normalization; SwiftLint covers broader lint categories including complexity and naming
  • swift-format (Apple) — the official Apple formatter with fewer rules; SwiftLint offers more community-driven rules
  • Periphery — detects unused code rather than style violations; complementary to SwiftLint
  • Tailor — an older Swift linter that is no longer actively maintained

FAQ

Q: Can I use SwiftLint with Swift Package Manager projects? A: Yes. Run swiftlint from the package root and it will analyze all Swift files. You can also add it as a build tool plugin.

Q: How do I suppress a specific rule for one line? A: Add // swiftlint:disable:next rule_name on the line above, or wrap a section with // swiftlint:disable rule_name and // swiftlint:enable rule_name.

Q: Does SwiftLint work in CI environments without macOS? A: SwiftLint requires SourceKit, which is bundled with the Swift toolchain. It runs on macOS and Linux where Swift is installed.

Q: How do I create custom rules? A: Define them in .swiftlint.yml under custom_rules with a regex, message, and severity. For complex logic, write a native rule as a Swift module.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets