swiftlang/swift-format
52.9
Adequate · 30 September 2026
19k
lines of production code
Swift
primary language
2
measurements over time
What this system is
This system is a Swift source code formatting and linting tool that enforces style conventions and checks for violations. It provides a programmatic API and command-line interface to format code, lint for style issues, and manage configuration, supporting both SPM and CMake build systems. The tool includes a comprehensive rule set for formatting and linting, with features for selective code range processing, ignore files, and integration with CI pipelines.
How it got here
2019–2020 — CMake migration and subcommand restructuring
7 changes.
The project migrated its build system to CMake and restructured the swift-format tool into a modular architecture with distinct subcommands for formatting, linting, and configuration management. This period also introduced developer tooling such as pre-commit hooks and a formatting diff preview script, alongside performance testing and extensive dependency updates.
2021–2023 — API expansion and engine rewrite
13 changes.
This period focused on modernizing the swift-format core by replacing the legacy pretty-printing engine with a new token-stream architecture and introducing a comprehensive public API for programmatic integration. Significant efforts were made to expand linting capabilities through new rules, support for the Swift Testing library, and a unified diagnostic engine with color output. The work was heavily supported by extensive test coverage and the introduction of a dedicated test support module to ensure reliability across the restructured rules and configuration systems.
2024–2025 — Build system modernization and CI expansion
5 changes.
The project introduced a CMake-based build system to replace previous methods and expanded CI coverage across multiple Swift versions and platforms, including Windows. Significant improvements were made to file iteration logic, adding support for .swift-format-ignore files, symlink handling, and atomic writes that preserve permissions. Code generation was also refactored to use string-based content and centralized paths to decouple generation from file system operations.
Features
Add Lint Plugin for Source Code Checking
A new LintPlugin has been introduced to allow users to run swift-format in lint mode (checking for style violations without modifying files) via the \--strict\ flag. The plugin supports specifying target modules through the \--target\ argument and can use a custom configuration file via \--swift-format-configuration\. It is available for both Swift Package Manager and Xcode projects.
Plugins/LintPlugin · high confidence
Add macOS instruction execution counter
The project now includes a new C library component that exposes a \getInstructionsExecuted()\ function. On macOS, this function queries the operating system to return the total number of instructions executed by the process since launch; on all other platforms, it returns zero. This capability is exposed to Swift via a module map and can be used for performance profiling or metrics collection within the tool.
_Sources/\SwiftFormatInstructionCounter · high confidence
Added script to preview Swift code formatting changes
A new shell script, format-diff.sh, has been added to the Scripts directory. This tool allows developers to run the swift-format formatter on a specific .swift file and view a side-by-side diff of the original code versus the formatted result, using colordiff if available. This facilitates reviewing formatting changes before committing them.
Scripts · high confidence
Introduce CMake-based build system for swift-format
swift-format now supports building via CMake, replacing or supplementing previous build methods. This change adds CMake configuration files (cmake/modules) that handle target exports, Swift module installation paths, and host architecture detection (including x86\_64, aarch64, riscv64, and others), enabling users to build and install the tool using standard CMake workflows.
cmake · high confidence
Introduces CMake build system and pre-commit linting hooks
Developers can now build swift-format using CMake (CMakeLists.txt) in addition to Swift Package Manager, with vendor dependencies like ArgumentParser and SwiftSyntax fetched automatically. The project also adds pre-commit hooks (.pre-commit-hooks.yaml) to automatically format and lint Swift files on commit, and configures the Swift Package Index (.spi.yml) to host DocC documentation.
(repo-wide) · high confidence
New public SwiftFormat API for formatting and linting
The \Sources/SwiftFormat/API\ module now exposes a public programmatic interface for integrating swift-format into other tools. Users can configure formatting and linting behavior via the new \Configuration\ struct (with defaults in \Configuration+Default.swift\ and JSON serialization in \Configuration+Dump.swift\), control which code ranges to process using the \Selection\ enum (supporting both UTF-8 offsets and line numbers), and invoke the \SwiftFormatter\ and \SwiftLinter\ classes to process source code or syntax trees. The API also includes \Finding\ and \FindingCategorizing\ types for reporting style issues, \DebugOptions\ for advanced debugging, and \SwiftFormatError\ for error handling.
Sources/SwiftFormat/API · high confidence
Behavioural changes
Expanded CI coverage for Swift-format across multiple versions and platforms
The CI configuration now includes dedicated jobs for Swift-format on Ubuntu 22.04 (Jammy) for Swift versions 5.7 through 5.10, as well as nightly builds for Swift 6.0 and the main branch on macOS, Ubuntu, and Windows. This ensures the project is tested against a broader range of Swift toolchains and operating systems, including the newly added Windows Server 2019 environment.
.swiftci · high confidence
New diagnostic engine with color support and unified output
The linter now uses a new \DiagnosticsEngine\ and \Diagnostic\ model to unify findings, parser errors, and generic errors. Lint findings are emitted as warnings by default, and the output printer (\StderrDiagnosticPrinter\) now supports color diagnostics (using ANSI SGR codes) when stderr is a TTY, displaying errors in bold red, warnings in bold yellow, and notes in bold gray. A new \FileHandleTextOutputStream\ wrapper enables writing to file handles, and TTY detection is handled via a new \isTTY\ utility.
Sources/swift-format/Utilities · high confidence
Refactored code generation to use string-based content and centralized paths
The \generate-swift-format\ tool's internal file generation logic has been refactored to produce content as strings rather than writing directly to disk, introducing a \FileGenerator\ protocol and a \GenerateSwiftFormatPaths\ namespace for managing output locations. This change updates how generated files—such as the lint/format pipeline, rule registry, rule name cache, and rule documentation—are assembled, ensuring that the generation process is now string-based and decoupled from immediate file system operations.
_Sources/\GenerateSwiftFormat · high confidence
Refactored swift-format into a modular frontend architecture
The swift-format tool has been restructured into a new frontend architecture that separates configuration loading, linting, and formatting into distinct components. This change introduces a \ConfigurationLoader\ that caches configurations in memory to avoid repeated file system hits and improves error reporting for invalid JSON configurations by including specific coding paths. The \FormatFrontend\ now supports in-place formatting that preserves file permissions and only writes to disk if changes are detected, while also handling unparsable files gracefully based on the \--ignore-unparsable-files\ flag. The \LintFrontend\ similarly respects this flag to suppress diagnostics for files with syntax errors. Additionally, the configuration provider now supports passing JSON configuration data directly via command-line arguments and correctly resolves configuration files when reading from stdin by walking up from the current working directory.
Sources/swift-format/Frontend · high confidence
Renamed code generation tool to generate-swift-format
The code generation utility previously known as generate-pipeline has been renamed to generate-swift-format. This change updates the entry point in Sources/generate-swift-format/main.swift, which collects rules and generates pipeline extensions, rule registries, name caches, and documentation files.
Sources/generate-swift-format · high confidence
Replaced legacy pretty-printing engine with a new token-stream-based formatter
The \Sources/SwiftFormat/PrettyPrint\ module has been completely rewritten to use a new token-stream architecture. The new \PrettyPrinter\ class now constructs a linear stream of formatting tokens via \TokenStreamCreator\ (defining break kinds, newline behaviors, and printer control tokens) which are then processed by \PrettyPrintBuffer\ to generate output. This change introduces a new \Comment\ struct for structured comment handling and \Verbatim\ for precise indentation control, replacing the previous implementation to support features like formatting selections and improved whitespace linting.
Sources/SwiftFormat/PrettyPrint · high confidence
Support for .swift-format-ignore files and improved file iteration
SwiftFormat now respects \.swift-format-ignore\ files, allowing users to exclude specific files and directories from formatting and linting using gitignore-style patterns. The file iteration logic has been updated to follow symlink chains when the \--follow-symlinks\ flag is used, fix duplicate file reporting, and correctly handle the root working directory. Additionally, atomic file writes now preserve original file permissions, and hidden files (starting with \.\) are skipped on Windows.
Sources/SwiftFormat/Utilities · high confidence
SwiftFormat Core: New rules, test-library awareness, and selection support
The SwiftFormat core library now includes several new linting and formatting rules: NoEmptyLinesOpeningClosingBraces (prevents empty lines at the start and end of braces), UseExplicitNilCheckInConditions (replaces implicit nil checks with explicit ones), and SwiftTestingNamingConventions (enforces naming conventions for the Swift Testing library). The formatter now detects when a file imports XCTest or the new Testing library, allowing rules to adjust behavior for test code. Additionally, users can now format specific ranges of code using the --lines \<start\>:\<end\> command-line argument, and the tool supports file-level ignore directives for specific rules.
Sources/SwiftFormat/Core · high confidence
SwiftFormat rules restructured into new opt-in lint and format rules
The SwiftFormat rules module has been significantly reorganized and expanded. Several new opt-in rules have been introduced, including \AllPublicDeclarationsHaveDocumentation\ to enforce documentation on public declarations, \AlwaysUseLiteralForEmptyCollectionInit\ to rewrite empty collection initializations to literals, and \AvoidRetroactiveConformances\ to forbid \@retroactive\ usage. The \AlwaysUseLowerCamelCase\ rule now explicitly allows underscores in test function names, including those marked with the \@Test\ attribute from Swift Testing. Additionally, the \BeginDocumentationCommentWithOneLineSummary\ rule has been updated to recognize CJK full stops as sentence terminators and to ignore sentence terminators inside quotes. Existing rules like \OrderedImports\ and \NoAccessLevelOnExtensionDeclaration\ have received fixes for trivia handling and access level updates within conditional compilation blocks.
Sources/SwiftFormat/Rules · high confidence
swift-format restructured into subcommands with CMake build support
The swift-format tool has been reorganized to use a subcommand-based interface (Format, Lint, DumpConfiguration) instead of a single monolithic command, and the build system has migrated to CMake. Users will now invoke specific actions like \swift-format format\ or \swift-format lint\, and the \--version\ flag behavior has been updated to reflect the new structure.
Sources/swift-format · high confidence
swift-format restructured into subcommands with new formatting and configuration options
The swift-format tool has been reorganized into distinct subcommands (lint, format, dump-configuration), introducing several new capabilities for users. You can now format specific code ranges using either UTF-8 offsets (--offsets) or line numbers (--lines), and the tool supports reading from standard input when no file paths are provided. A new dump-configuration subcommand allows you to inspect the effective configuration in JSON format. Additionally, the linter now treats warnings as errors by default unless the --strict flag is used, and performance measurement via instruction counting is available with the --measure-instructions flag.
Sources/swift-format/Subcommands · high confidence
Test coverage
Added performance tests for the whitespace linter; Added pretty-printing tests for SwiftFormat; Added test coverage for SwiftFormat lint and format rules; Added tests for .swift-format-ignore support and file iteration utilities; Added tests for configuration decoding and line-range formatting selection; Added tests for documentation comment parsing and rule ignore directives; New test support module for SwiftFormat diagnostics and configuration.
Dependencies
71 commits updating dependencies (2 manifests)
A dependency / build maintenance change in (dependencies) — 71 commits (4 fixs), 2 files.
(dependencies) · medium confidence · unverified
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 59 → 53 (-6.6)
- Rubric changed (rubric-2026.09.11 → rubric-2026.09.18) — scores are not directly comparable.
Lenses
- Code Health 84 → 85 (+0.4)
- Architecture 97 → 95 (-1.7)
- Maturity 51 → 51 (+0.1)
- Readiness 60 → 43 (-17.0)
- Security 57 → 57 (+0.0)
Resolved (8)
- Change coupling: ModifierListSyntax+Convenience.swift ↔ NoAccessLevelOnExtensionDeclaration.swift (Sources/SwiftFormat/Core/ModifierListSyntax+Convenience.swift)
- Documentation: no installation or build instructions (README.md)
- Documentation: no usage examples (README.md)
- Duplicated block (14–15 lines × 2) (Plugins/FormatPlugin/plugin.swift)
- Duplicated block (22 lines × 2) (Plugins/FormatPlugin/plugin.swift)
- Hotspot: Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Hotspot: Sources/SwiftFormat/Rules/OrderedImports.swift (Sources/SwiftFormat/Rules/OrderedImports.swift)
- Off-boarding risk: anonymized user #1
New (12)
- Coverage not measured — Swift suite
- Dependency hygiene PARTLY measured — SwiftPM pinning read, dependency currency NOT established
- Duplicated block (15 lines × 2) (build-script-helper.py)
- Floating branch dependency: swift-syntax
- ImportsAnyTestingLibrary.swift.statementsImportAnyTestLibrary (cognitive 26) (Sources/SwiftFormat/Core/ImportsAnyTestingLibrary.swift)
- Line.description (cognitive 26) (Sources/SwiftFormat/Rules/OrderedImports.swift)
- Low cohesion: CommentMovingRewriter (LCOM4 4) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Low cohesion: Trivia (LCOM4 5) (Sources/SwiftFormat/Core/Trivia+Convenience.swift)
- Off the main sequence: SwiftFormat
- Off-boarding risk: anonymized user #1
- OrderedImports.swift.generateLines (cognitive 31) (Sources/SwiftFormat/Rules/OrderedImports.swift)
- Trivia.trimmingSuperfluousNewlines (cognitive 23) (Sources/SwiftFormat/Core/Trivia+Convenience.swift)
Changes since last survey
- 4 commits — 2 feature/other, 2 fixes
By area
- (repo) — 2 commits
- .github/workflows — 1 commit
- Sources/_SwiftFormatTestSupport — 1 commit
Notable commits
- fix: Merge pull request #1289 from rintaro/fix-release-branch-regex
- fix: Merge pull request #1298 from rintaro/fix-deprecated-parse-label
- change: Match release branches with a patch component in publish_release
- change: Use the 'languageFeatures' argument label when parsing
Written by watchdog.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
Survey your own repository
swiftlang/swift-format was measured the same way every project in this corpus was: the same rubric, at a pinned commit, with the result published in full. Point a surveyor at a repository you know and see whether you agree with it.
About this page
- The score is its most recent published measurement, taken on 30 September 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit b15dd59fad21f1770cdc888b1ca6e2937490001a — the exact code this score is about.
- Scored under rubric-2026.09.18 — the same rubric and the same method as every other entry in this index.
- Measured by watchdog.canine.dev using codehealth-analyzer preprod-cb25ca4feafa.