Skip to content

swift format lint in CI and verify.sh (#1165) - #1300

Merged
Skeyelab merged 2 commits into
mainfrom
swift-format-lint-1165
Dec 3, 2026
Merged

Skeyelab merged 2 commits into
mainfrom
swift-format-lint-1165

Conversation

@Skeyelab

@Skeyelab Skeyelab commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Refs #1165

What

  • scripts/swift-format-lint.sh runs swift format lint --strict on every tracked Swift file outside spikes/ (422 files: App/, AppTests/, LiveActivity/, Watch/, Packages/, and the two Swift scripts). swift-format comes with the toolchain, so nothing to install. It changes no file, and any finding fails it.
  • CI runs it in the package tests leg, with Xcode's own swift-format. It is blocking from the start, since it passes today.
  • verify.sh runs it in every plan, next to the spelling check. It takes about a second. Without a Swift toolchain it says so and passes.
  • .swift-format has the config: 4 spaces, 130 columns, #if blocks not indented, and the full rules list.

The config, and why

Findings with swift-format's default config, before this PR (53,615 in all):

Finding Count Now
Indentation 45,461 layout: not checked
LineLength 6,055 layout: not checked
DoNotUseSemicolons 820 rule off
AddLines 583 layout: not checked
OrderedImports 218 rule off (211 are @testable import first)
OneVariableDeclarationPerLine 161 rule off
TrailingComma 113 layout: not checked
Spacing 113 layout: not checked
EndOfLineComment 38 layout: not checked
RemoveLine 20 layout: not checked
UseLetInEveryBoundCaseVariable 9 (5 places) on, fixed by hand
TrailingWhitespace 8 layout: not checked
NoAccessLevelOnExtensionDeclaration 7 rule off (private extension)
OneCasePerLine 5 (4 places) on, fixed by hand
ReplaceForEachWithForLoop 2 on, fixed by hand
NoBlockComments 2 on; both in spikes/, which isn't checked

Layout isn't checked. With 4 spaces, 130 columns and #if blocks not indented, the layout findings drop from about 52,400 to about 3,200 (1,270 lines over 130 columns, 1,021 indentation, 745 line breaks, and some spacing and commas). The rest is how the code is laid out by hand: several short statements on a line, and wrapped arguments lined up under the first. swift-format has no setting for either, and it has no switch for single layout findings, so the script passes --debug-disable-pretty-print, which turns the layout half of the linter off and leaves the rules. The layout settings in .swift-format still serve Xcode's "Format with swift-format" and a later reformat.

The rules list is complete on purpose. A rule left out of the list is off, and a rule name the toolchain doesn't know fails every file, so the list holds only rules that both CI's Xcode (Swift 6.3.3) and Swift 6.4.3 have.

Code changes

Eleven places, none changing behavior, to keep three rules on:

  • case let .x(y) to case .x(let y): TakeTelemetry, TelemetrySinks (3), RecordScreen.
  • A case with a value on its own line: DriveOnlyMoveOffer, WatchStatus.CodingKeys, Recorder.DeviceCopyDelete, LevelFeedTests.Outcome.
  • buffers.forEach { $0.deallocate() } to a for loop: DriveSpeedTest, PeakMetersLevelTests.

Also scripts/test-verify-plan.sh looked for the gate's old needs list (before scripts joined it), so verify.sh failed on any branch that touched ci.yml. It now looks for the current list.

Checked

  • The lint passes with swift-format 6.4.3 on Linux, and fails on a test line with forEach. CI runs it with Xcode's swift-format.
  • On Linux: spelling, the lint, Take control, vocabulary, the Python script tests, the mixer-sim tests and the verify plan and steps tests pass.
  • Not run locally: the package tests and the app builds (the package doesn't build on Linux), the website checks (no change there) and the two build lock tests (lockf is macOS only). This PR touches one line of App/RecordScreen.swift, so CI's macOS and iOS builds cover it.

Later, each its own PR

  • Turn on OrderedImports (218), OneVariableDeclarationPerLine (161), DoNotUseSemicolons (820) or NoAccessLevelOnExtensionDeclaration (7), with the cleanup.
  • A reformat, so layout can be checked too: swift format format with this config changes 276 of the 422 files, about 2,700 lines out and 5,600 in. It would split the one-line statements the code uses on purpose, so it is a style decision first.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VCgWWseQZtUzcSRzjqqQJQ

scripts/swift-format-lint.sh runs `swift format lint --strict` on every tracked Swift file outside spikes/, in
every verify.sh plan and in CI's package tests leg. .swift-format has the rules: four are off because the code
breaks them widely (DoNotUseSemicolons, OrderedImports, OneVariableDeclarationPerLine,
NoAccessLevelOnExtensionDeclaration), and layout isn't checked (--debug-disable-pretty-print), since the code is
laid out by hand.

Eleven places fixed by hand to keep three rules on, none changing behavior: `case let .x(y)` to `case .x(let y)`,
a case with a value on its own line, and `forEach` to `for`.

test-verify-plan.sh looked for the gate's old `needs` list, so any branch that touched ci.yml failed it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VCgWWseQZtUzcSRzjqqQJQ
@Skeyelab
Skeyelab enabled auto-merge (squash) December 3, 2026 06:35
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
App/RecordScreen.swift 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Skeyelab
Skeyelab merged commit cb26698 into main Dec 3, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant