SwiftLint is a tool that enforces Swift style and conventions, loosely based on the archived GitHub Swift Style Guide. It enforces rules generally accepted by the Swift community, as described in popular style guides like Kodeco's. Its rules are predominantly based on SwiftSyntax, with some rules hooking into Clang and SourceKit to access type information. It is aimed at Swift developers who want to keep their code consistent.
Install & use
Install
brew install swiftlint
Usage
# open realm/SwiftLint and follow its README
realm/SwiftLint is a third-party open-source project, listed here from public GitHub data. ImuTechz did not write it and has not reviewed or security-audited its code. Read the source and its permissions before you install or run it.
Features
Enforces Swift style and convention rules
Rules predominantly based on SwiftSyntax
Some rules use Clang and SourceKit for type information
Can be used as a Swift Package command plugin or build tool plugin
Installable via Homebrew, CocoaPods, Mint and Bazel
Highlights violations in the Xcode editor
Best for
Enforcing a consistent Swift code style
Catching style violations in Xcode
Adding linting to Swift Package builds
Pinning a specific SwiftLint version via CocoaPods
Pros
Enforces rules generally accepted by the Swift community
Rules are well described in popular style guides
Can be consumed as a Swift Package plugin or build tool plugin
CocoaPods install allows pinning to a specific version
Cons
Consuming plugins directly from the SwiftLint repository has drawbacks; the dedicated SwiftLintPlugins repository is recommended
CocoaPods install adds SwiftLint binaries, dependency binaries and the Swift binary library to Pods/, so checking that directory into Git is discouraged
Homebrew installs the latest version rather than a pinned one