Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsMay 29, 2026·3 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
SwiftLint Overview
Commande d'installation directe
npx -y tokrepo@latest install 038be131-5b15-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires