# swift

> Swift sources and their XCTest and Swift Testing tests: lint and analyzer rules for each level, one format, a clean build, no unused code, a reason on each disabled test, and a coverage floor.

Swift sources and their XCTest and Swift Testing tests: lint and analyzer rules for each level, one format, a clean build, no unused code, a reason on each disabled test, and a coverage floor. The [Swift guide](/languages/swift/) explains the setup.

## Checks

| Check                                                                   | Stage    | Level         | What it does                                                                                                                     |
| ----------------------------------------------------------------------- | -------- | ------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| [`swift/swiftlint`](/reference/checks/swift/swiftlint/)                 | `commit` | `recommended` | Lints Swift files with the SwiftLint files of each scope and nested folder, and treats warnings as errors.                       |
| [`swift/swiftformat`](/reference/checks/swift/swiftformat/)             | `commit` | `recommended` | Checks the layout of every Swift file against the shipped SwiftFormat rules.                                                     |
| [`swift/build`](/reference/checks/swift/build/)                         | `push`   | `recommended` | Builds the package or Xcode scheme incrementally to report compiler errors.                                                      |
| [`swift/swiftlint-analyze`](/reference/checks/swift/swiftlint-analyze/) | `manual` | `recommended` | Runs the SwiftLint analyzer rules over the compiler log of the build: unused imports and captured variables.                     |
| [`swift/periphery`](/reference/checks/swift/periphery/)                 | `push`   | `recommended` | Scans the built project for declarations nothing uses.                                                                           |
| [`swift/skip-reasons`](/reference/checks/swift/skip-reasons/)           | `commit` | `recommended` | Checks that skip calls and disabled traits name a nonempty reason, and unavailable tests carry an explanation.                   |
| [`swift/coverage`](/reference/checks/swift/coverage/)                   | `push`   | `recommended` | Measures each source target in Xcode projects and Swift packages against `coverage.lines` and its `coverage.swift_target` floor. |

## Settings

| Setting                                                                                             | What it sets                                                                                                                                          |
| --------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`coverage.lines`](/reference/gspot-toml/#coverage.lines)                                           | The minimum percentage of source lines covered by tests.                                                                                              |
| [`coverage.branches`](/reference/gspot-toml/#coverage.branches)                                     | The minimum percentage of source branches covered by tests.                                                                                           |
| [`coverage.functions`](/reference/gspot-toml/#coverage.functions)                                   | The minimum percentage of source functions covered by tests.                                                                                          |
| [`coverage.statements`](/reference/gspot-toml/#coverage.statements)                                 | The minimum percentage of source statements covered by tests.                                                                                         |
| [`coverage.swift_target`](/reference/gspot-toml/#coverageswift_target)                              | Line coverage floors for named Swift targets.                                                                                                         |
| [`swift.xcode_project`](/reference/gspot-toml/#swift.xcode_project)                                 | The Xcode project or workspace, relative to the repository root, which init fills in when it finds one; without it, the checks use the Swift package. |
| [`swift.xcode_scheme`](/reference/gspot-toml/#swift.xcode_scheme)                                   | The shared scheme the build, the analyzer, and Periphery use.                                                                                         |
| [`swift.xcode_destination`](/reference/gspot-toml/#swift.xcode_destination)                         | The xcodebuild destination.                                                                                                                           |
| [`tools.swiftlint.always_keep_imports`](/reference/gspot-toml/#tools.swiftlint.always_keep_imports) | Imports the analyzer keeps although it sees no use of them.                                                                                           |

## Selected when

gspot selects it in a scope with file extensions `.swift`, or project files `Package.swift`.

## Rules for coding agents

| Rule file                                                   | Installed when                                                     |
| ----------------------------------------------------------- | ------------------------------------------------------------------ |
| `.gspot/configurations/language/swift/rules/SWIFT-TESTS.md` | The repository has files marked `swift-test`, `swift-test-target`. |
| `.gspot/configurations/language/swift/rules/SWIFT.md`       | Always                                                             |
| `.gspot/configurations/language/swift/rules/SWIFTUI.md`     | The repository has files marked `swift-import:SwiftUI`.            |
| `.gspot/configurations/language/swift/rules/UIKIT.md`       | The repository has files marked `swift-import:UIKit`.              |

## Tools and versions

| Tool        | Version                  |
| ----------- | ------------------------ |
| swiftlint   | `0.63.2`                 |
| swiftformat | `0.61.1`                 |
| periphery   | `3.6.0`                  |
| swift       | Any, install it yourself |
| xcodebuild  | Any, install it yourself |

## Files gspot writes

gspot writes `.gspot/configurations/language/swift/swiftlint.yml`, `.gspot/configurations/language/swift/swiftformat`, `.gspot/configurations/language/swift/periphery.yml`, and `.gspot/configurations/language/swift/semgrep.yml` (with the [`security`](/reference/configurations/security/) configuration).

## Kept out of Git

`.build`, `DerivedData`, and `Pods`.
