Swift
gspot checks Swift packages and Xcode projects. SwiftLint and SwiftFormat run before each commit. Before each push, gspot builds the package or the Xcode scheme, finds declarations that nothing uses, and measures test coverage:
| Check | Stage | Level | What it does |
|---|---|---|---|
swift/swiftlint |
commit |
basic |
Lints Swift files with the SwiftLint files of each scope and nested folder, and treats warnings as errors. |
swift/swiftformat |
commit |
basic |
Checks the layout of every Swift file against the shipped SwiftFormat rules. |
swift/build |
push |
basic |
Builds the package or Xcode scheme once per scope, and reports the compiler errors and the warnings in your own sources. A package build treats warnings as errors. |
swift/swiftlint-analyze |
manual |
basic |
Runs the SwiftLint analyzer rules over the compiler log of the build: unused imports and captured variables. |
swift/periphery |
push |
basic |
Scans the built project for declarations nothing uses. |
swift/skip-reasons |
commit |
basic |
Checks that skip calls and disabled traits name a nonempty reason, and unavailable tests carry an explanation. |
swift/security |
commit |
basic |
Finds always-accessible Keychain items, MD5 and SHA-1 hashes, each secret in UserDefaults, a plist read, or a log, and SQLite calls whose SQL text interpolates a value. |
swift/tests |
push |
basic |
Measures each source target in Xcode projects and Swift packages against coverage.min_line_percent and its coverage.swift_target minimum. |
xcode/plutil |
commit |
basic |
Parses every property list and entitlements file with plutil. |
xcode/build-settings |
commit |
basic |
Reports a target without strict concurrency, a run-script phase with no declared files, and a run-script phase that runs the linter or the formatter. |
xcode/xcstrings |
commit |
basic |
Checks that each string catalog parses and translates every string into all its locales. |
xcode/assets |
commit |
basic |
Checks that each asset Contents.json parses, and that its image set holds each file it names. |
xcode/unused-assets |
commit |
basic |
Finds asset sets that no source or Xcode build setting names. |
xcode/files-without-target |
commit |
basic |
Finds the Swift files in the tree that no target of the project names. |
xcode/entitlements |
commit |
basic |
Checks each entitlement against xcode.allowed_entitlements, when the settings hold that list. |
xcode/app-transport-security |
commit |
basic |
Refuses a property list that allows arbitrary loads, which turns transport security off for every host. |
To limit which module may import which, see Import rules.
Before you start
Section titled “Before you start”Install the Swift toolchain, then install gspot with mise, as the Quickstart shows. With an Xcode
project, the build and coverage checks need macOS, with Xcode chosen through xcode-select. swift/periphery,
swift/swiftlint-analyze, and xcode/plutil run only on macOS.
Compiler warnings
Section titled “Compiler warnings”swift/build fails on a compiler warning in your own sources. A Swift package builds with warnings as errors. An Xcode
scheme builds without that flag, because Xcode builds the packages that the project depends on with their warnings
turned off, and the compiler refuses both options together. gspot reads the warnings of the build instead and reports
each one whose file is in your repository.
Xcode projects
Section titled “Xcode projects”gspot init writes the Xcode project, scheme, and destination that it finds into gspot.toml. To set them yourself:
[swift]xcode_project = "App.xcodeproj"xcode_scheme = "App"xcode_destination = "generic/platform=iOS Simulator"When gspot.toml sets swift.xcode_project, the build, Periphery, analyzer, and coverage checks use that project or
workspace. The xcode configuration also checks property lists, string catalogs, asset catalogs, unused assets, Swift
files that no target lists, the App Transport Security settings, and the entitlements against
xcode.allowed_entitlements.
Analyzer
Section titled “Analyzer”swift/swiftlint-analyze runs the SwiftLint analyzer on the build log, and only when you name it:
gspot check --only swift/swiftlint-analyzeWhen the analyzer reports an unused import that your code needs, list that import in swift.allowed_unused_imports.
Lint rules in test folders
Section titled “Lint rules in test folders”gspot writes a .swiftlint.yml into each Tests or *Tests folder, which turns off force_unwrapping and
no_magic_numbers in tests. When an editor extension passes --config to SwiftLint, SwiftLint ignores these
test-folder files, so set the extension to run SwiftLint without --config.
Coverage
Section titled “Coverage”To set a minimum line coverage for one Swift target, write a [[coverage.swift_target]] record by hand:
[[coverage.swift_target]]name = "Orders"min_line_percent = 80name is a target in the coverage report. When min_line_percent is lower than coverage.min_line_percent, add a
reason. Then run gspot install and gspot check --only swift/tests.