swiftlang/swift-format
52.7
Adequate · 14 November 2026
22.2k
lines of production code
Swift
primary language
5
measurements over time
What this system is
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 cca.canine.dev from the codebase's own history, inside the signed delivery this page is composed from.
How this codebase got here
Score
- CAI 53 → 53 (+0.1)
- Rubric changed (rubric-2026.10.5 → rubric-2026.11.4) — scores are not directly comparable.
Lenses
- Code Health 90 → 82 (-8.2)
- Architecture 88 → 96 (+8.5)
- Maturity 51 → 59 (+8.3)
- Readiness 43 → 40 (-3.4)
- Security 57 → 57 (+0.0)
Resolved (76)
- Concentrated knowledge decay
- Duplicated block (10 lines × 2) (Sources/_SwiftFormatTestSupport/DiagnosingTestCase.swift)
- Duplicated block (11 lines × 3) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (15 lines × 2) (Sources/SwiftFormat/Rules/ReturnVoidInsteadOfEmptyTuple.swift)
- Duplicated block (25 lines × 2) (Sources/_SwiftFormatTestSupport/DiagnosingTestCase.swift)
- Duplicated block (6 lines × 2) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (7 lines × 2) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (7 lines × 3) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (8–10 lines × 5) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Low cohesion: CommentMovingRewriter (LCOM4 4) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Members sharing a duplicated core (5 members, 50+ identical tokens) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- MethodTooLong: OrderedImports.orderImports (Sources/SwiftFormat/Rules/OrderedImports.swift)
- Most significant orphaned file (Sources/SwiftFormat/PrettyPrint/PrettyPrint.swift)
- Most significant orphaned file (Sources/SwiftFormat/PrettyPrint/WhitespaceLinter.swift)
- No ADRs found
- Off-boarding risk: anonymized user #1
- OrderedImports.orderImports (cognitive 37) (Sources/SwiftFormat/Rules/OrderedImports.swift)
- OrderedImports.orderImports (cyclomatic 28) (Sources/SwiftFormat/Rules/OrderedImports.swift)
- Orphaned file (Package.swift)
- Orphaned file (Plugins/FormatPlugin/plugin.swift)
- …and 56 more
New (129)
- ClassTooLong: Comment (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- ClassTooLong: OverlongLineReflower (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.exceedsMaxLineLength (cognitive 40) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.exceedsMaxLineLength (cyclomatic 20) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.pragmaLineIndices (cognitive 25) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.printReflowedBlockComment (cognitive 93) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.printReflowedBlockComment (cyclomatic 58) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.printReflowedLineComment (cognitive 27) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.printReflowedLineComment (cyclomatic 19) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.reflowBlockBodyLines (cognitive 20) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Comment.reflowBlockBodyLines (cyclomatic 16) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Duplicated block (11 lines × 3) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (16 lines × 2) (Sources/SwiftFormat/Rules/ReturnVoidInsteadOfEmptyTuple.swift)
- Duplicated block (43–44 lines × 2) (Sources/_SwiftFormatTestSupport/DiagnosingTestCase.swift)
- Duplicated block (6 lines × 2) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (7 lines × 2) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (8 lines × 2) (Sources/SwiftFormat/PrettyPrint/Comment.swift)
- Duplicated block (8 lines × 3) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Duplicated block (8–10 lines × 5) (Sources/SwiftFormat/PrettyPrint/TokenStreamCreator.swift)
- Edited copies of one member (3 members, 10+ corresponding lines) (Sources/SwiftFormat/Rules/NoParensAroundConditions.swift)
- …and 109 more
Changes since last survey
- 15 commits — 9 feature/other, 6 fixes
By area
- Sources/SwiftFormat — 12 commits
- Tests/SwiftFormatTests — 2 commits
- (repo) — 1 commit
Notable commits
- fix: Add back comment reflowing (revert #1327). (#1328)
- fix: Fix multiline string literal handling with partial selections and whitespace-only linting. (#1335)
- fix: Fix selection boundary handling in TokenStreamCreator and PrettyPrintBuffer (#1337)
- fix: Fix trailing comma handling at the end of a line-range selection (#1332)
- fix: Merge pull request #1327 from tshortli/revert-reflow-comments
- fix: Revert "Add configurable Markdown-aware comment reflowing (reflowComments) (#1324)"
- change: Add configurable Markdown-aware comment reflowing (reflowComments) (#1324)
- change: Apply SyntaxFormatRules consistently across format and lint with selections. (#1333)
- change: Disable formatting after trailing comments at the end of a selection (#1334)
- change: Don't treat != as a sentence terminator in doc comment summaries (#1305)
- change: Format and lint blank lines when selections start or end on blank lines (#1338)
- change: Handle CRLF line endings in multiline string literal segments (#1339)
- change: Handle CRLF line endings when formatting and linting selections (#1336)
- change: Reflow over-length comments with clang-format-style forward carry. (#1330)
- change: Support line and offset selections when linting (#1326)
Written by cca.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 14 November 2026 at a pinned commit. It is not a live figure and does not change until the project is measured again.
- Measured at commit 48dd21a196e5001c573445fef09a8e6debad124a — the exact code this score is about.
- Scored under rubric-2026.11.4 — the same rubric and the same method as every other entry in this index.
- Measured by Canine Code Analyzer (cca.canine.dev) using cca measure-2026.11.65+preprod-3c33c1882dc1.