Skip to content

Adopt swift-format for linting and formatting#163

Merged
yysskk merged 2 commits into
mainfrom
ci/swift-format
Jul 7, 2026
Merged

Adopt swift-format for linting and formatting#163
yysskk merged 2 commits into
mainfrom
ci/swift-format

Conversation

@yysskk

@yysskk yysskk commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Summary

Adds lint/format enforcement using the Swift toolchain's first-party swift format (swiftlang/swift-format, bundled since Swift 6) — no third-party lint dependency.

  • .swift-format: 4-space indentation, 160-column line length, respectsExistingLineBreaks so adoption churn stays minimal; everything else is the official default rule set.
  • One-time normalization of Sources, Tests, the example app, and Package.swift with swift format --in-place: bracket indentation (the codebase had misaligned ]) closers), trailing commas in multiline collections, one variable per declaration, ordered imports (@testable last), and blank-line normalization. Purely mechanical.
  • Manual fixes for things the formatter does not rewrite:
    • The four .forEach { … } side-effect loops flagged by ReplaceForEachWithForLoop are now for-in loops.
    • First commit: wrapped 160+ character lines (worst was 301 chars), renamed single-letter locals (iindex, mmaskedCorners), dropped redundant = nil initializations, removed a stale 2017 TODO.
  • CI job swift-format (macos-26, same setup-xcode selection as the build jobs so CI's swift-format version matches contributors' local toolchain):
    1. swift format lint --strict --recursive --parallel …
    2. swift format --in-place … + git diff --exit-code — fails if the tree is not formatter-clean and surfaces the diff in the log.

Existing job names are unchanged, so the required status checks on main are unaffected.

Verification

  • swift format lint --strict passes with zero findings (swift-format 6.3.0), and the formatter is idempotent on the tree.
  • All 70 package tests and 8 example tests pass locally on the iPhone 17 simulator (Xcode 26.5).

yysskk added 2 commits July 7, 2026 07:17
No behavior change.

- Wrap the 160+ character lines (the worst was 301 characters) in
  TabView, SwipeMenuView, and SwipeMenuViewController.
- Rename single-letter locals (i -> index, m -> maskedCorners).
- Drop redundant '= nil' optional initializations in the options.
- Remove the stale 2017 'case infinity' TODO; nothing tracks it.
- Trailing whitespace/newline fixes.
Add a .swift-format configuration (4-space indent, 160-column lines,
existing line breaks respected) and normalize the codebase with the
Swift 6 toolchain's built-in formatter: bracket indentation, trailing
commas in multiline collections, one variable per declaration, ordered
imports, and blank-line normalization. The four .forEach side-effect
loops flagged by the ReplaceForEachWithForLoop rule are rewritten as
for-in loops.

A new swift-format CI job runs 'swift format lint --strict' and then
verifies the tree is formatter-clean via git diff --exit-code. It
selects the same Xcode as the build jobs so the bundled swift-format
matches what contributors run locally. Existing job names are
unchanged, so the required status checks are unaffected.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the full diff. This is a mechanical formatting-only change: adds a .swift-format config, applies swift format --in-place across Sources/Tests/Example, converts the four flagged .forEach side-effect loops to for-in, and adds a CI job that lints and verifies formatter-cleanliness.

Spot-checked the non-trivial rewrites for behavior preservation:

  • The wrapped multi-line string literal in SwipeMenuViewController.swift's assertionFailure uses a trailing \ to suppress the line break, so the message text is unchanged.
  • The padding/height local-variable hoists in TabView.swift (indicator positioning, circle indicator frame) compute the same values as before, just de-duplicated.
  • Trailing commas added to multi-line arrays/NSLayoutConstraint.activate([...]) calls and import reordering are semantically inert in Swift.
  • The new format CI job is independent (no needs: wiring), so it doesn't affect the existing required checks.

No bugs, logic changes, or security issues found. Approving.

@yysskk yysskk merged commit bd3fead into main Jul 7, 2026
12 checks passed
@yysskk yysskk deleted the ci/swift-format branch July 7, 2026 16:53
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