Swift Code Formatting
Format Swift code in this project using Apple's swift-format tool to ensure consistent code style.
Quick Start
To format all Swift files in the project:
swift format --in-place --recursive Sources/
Common Commands
Format entire Sources directory
swift format --in-place --recursive Sources/
Format specific file
swift format --in-place path/to/File.swift
Check formatting without modifying (dry run)
swift format --recursive Sources/
Check version
swift format --version
Workflow
Check if swift-format is available
swift format --versionFormat the code
swift format --in-place --recursive Sources/Review changes
git diffRun tests to ensure formatting didn't break anything
swift testCommit the formatting changes
git add -A git commit -m "Format code with swift format"
What swift-format fixes
- Removes trailing whitespace
- Ensures consistent indentation
- Breaks long lines appropriately (default 80 chars)
- Fixes spacing around operators and brackets
- Ensures consistent brace placement
- Normalizes blank lines
Notes
- Always run tests after formatting to ensure no unintended changes
- Format before committing to keep diffs clean
- The
--in-placeflag modifies files directly - Without
--in-place, output goes to stdout
Converted and distributed by TomeVault — claim your Tome and manage your conversions.