@codacy/tools-swiftlint-0
v0.23.1
Published
SwiftLint adapter — CLI-mode Swift linter
Readme
@codacy/tools-swiftlint-0
Table of Contents
Overview
Swift linter using the SwiftLint binary. Uses the CLI execution strategy — spawns swiftlint via spawnTool() and parses its JSON output.
| Property | Value |
| -------------- | -------------------------------------- |
| Tool ID | SwiftLint |
| Codacy UUID | 9046d2e3-9a3d-4f9c-b31d-a0940a994c50 |
| Strategy | CLI |
| Languages | Swift |
| Binary | swiftlint |
| File patterns | **/*.swift |
| Pinned version | 0.63.2 |
| Pattern count | 250 |
Updating patterns
# Re-fetch pattern metadata from the Codacy API
pnpm prefetch
# Commit the result
git add src/patterns.jsonPattern IDs follow the format SwiftLint_force_cast, SwiftLint_cyclomatic_complexity, etc. Rule IDs use snake*case and are prefixed with SwiftLint* to form the Codacy pattern ID.
Updating the SwiftLint version
- Update
preferredVersioninsrc/adapter.ts - Update the download URL template if the release format changed
- Run
pnpm prefetchto check for new/removed rules - Run
pnpm testto verify compatibility - If the major version changes, create a new adapter package (
swiftlint-1/)
Development
pnpm build # Build with tsup
pnpm test # Run tests (mocked tests always run; integration tests require swiftlint in PATH)To install SwiftLint locally:
# macOS
brew install swiftlint
# Linux (requires Swift toolchain for full rule coverage)
# Download from https://github.com/realm/SwiftLint/releasesNotes for maintainers
Preset mappings (
src/pattern-mappings.json): the test-only rules are gated on the test framework they check.quickuses SwiftLint's ownquick/quickspectags;nimblematchesnimble_operatorandprefer_nimble;xctestcovers the seven XCTest rules. Quick and Nimble are separate entities because Nimble is usable on its own, and both are matched case-sensitively (Quick,Nimble) — neither Swift manifest parser normalizes case. XCTest ships with Xcode and appears in no manifest, so it is detected by a file signal on the*Tests.swiftnaming Xcode and SwiftPM both generate. The twoswiftui-tagged rules stay universal: SwiftUI is also an Apple framework, and unlike XCTest it leaves no file-name trace, so a mapping key for it would have no producer and its patterns would be dead rather than merely off.JSON output quirk: SwiftLint's
--reporter jsonoutput haslineandcharacterfields as strings, not numbers. The adapter usesparseInt()to convert them.Absolute file paths: SwiftLint reports absolute file paths in its JSON output. The adapter converts them to paths relative to
repositoryRootusingpath.relative().Version subcommand: SwiftLint uses
swiftlint version(no--prefix), notswiftlint --version.Config generation: When Codacy patterns are provided, the adapter generates a
.swiftlint.ymlwithonly_rules:to restrict analysis to the requested rules.Linux SourceKit limitation: On Linux, SwiftLint requires the Swift toolchain (SourceKit) for full rule coverage. Without it, some syntax-aware rules may not fire. The adapter emits a warning at the start of analysis on Linux.
macOS portable zip: The
portable_swiftlint.zipfor macOS may extract to a nested directory structure. Theinstall()method recursively searches the extraction directory for the binary.Download assets:
- macOS (any arch):
portable_swiftlint.zip - Linux amd64:
swiftlint_linux_amd64.zip - Linux arm64:
swiftlint_linux_arm64.zip
- macOS (any arch):
Exit codes: 0 = no issues, 1 = issues found (or fatal), 2 = config error. Both 0 and 1 are treated as success.
Category normalization: patterns.json categories are passed through if valid; unknown categories are normalized to "BestPractice".
