Auto-format all Swift files in a project to a consistent team style in one command.
Add a git pre-commit hook so Swift files are formatted automatically before every commit.
Run SwiftFormat as an Xcode build step so code is reformatted each time you compile.
Configure individual formatting rules on or off via a plain text config file in your project folder.
Primarily a macOS and Xcode tool, also supports Linux and Windows.
SwiftFormat is a tool that automatically rewrites Swift source code files to follow a consistent style. Rather than just adjusting spacing and indentation, it also makes higher-level corrections: removing redundant parentheses, adding or removing the implicit "self" keyword where the Swift style guide recommends it, and fixing other patterns that technically work but deviate from standard Swift conventions. The goal is that every developer on a team ends up with identically formatted code without anyone having to argue about it or fix it by hand during code review. You can use it in several ways. As a command-line tool, you point it at a folder and it rewrites every Swift file it finds. It also integrates directly into Xcode as a source editor extension, so you can format the file you're currently working on from a menu item. For projects that want automatic enforcement, it can run as a build step each time you compile, or as a git pre-commit hook that runs on any files you've changed before they're saved to version control. There are also plugins for VS Code, Sublime Text, and a Nova editor. Installation on macOS is typically done through Homebrew with a single terminal command, and it's also available through Swift Package Manager and several other package managers. Configuration is handled via a plain text file in your project folder, where you can turn individual formatting rules on or off and adjust options like indentation width or trailing comma behavior. The project is open source under the MIT license and available for macOS, Linux, and Windows. The README is extensive and covers all rules, configuration options, known issues, and answers to common questions in detail. The full README is longer than what was shown.
← nicklockwood on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.