explaingit

nicklockwood/swiftformat

8,800SwiftAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

Command-line and Xcode tool that automatically reformats Swift source code to a consistent style, fixing indentation, redundant syntax, and naming conventions across an entire codebase.

Mindmap

mindmap
  root((SwiftFormat))
    What It Does
      Reformats Swift code
      Removes redundant syntax
      Fixes naming style
    Usage Modes
      Command-line tool
      Xcode extension
      Git pre-commit hook
      Build step
    Installation
      Homebrew
      Swift Package Manager
    Configuration
      Plain text config file
      Per-rule on and off toggle
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Auto-format all Swift files in a project to a consistent team style in one command.

USE CASE 2

Add a git pre-commit hook so Swift files are formatted automatically before every commit.

USE CASE 3

Run SwiftFormat as an Xcode build step so code is reformatted each time you compile.

USE CASE 4

Configure individual formatting rules on or off via a plain text config file in your project folder.

Tech stack

SwiftXcodeHomebrewSwift Package Manager

Getting it running

Difficulty · easy Time to first run · 5min

Primarily a macOS and Xcode tool, also supports Linux and Windows.

MIT, use freely for any purpose including commercial, modify and distribute, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
How do I install SwiftFormat via Homebrew and run it on my entire Xcode project folder?
Prompt 2
Show me how to set up a SwiftFormat pre-commit git hook so my Swift files are formatted before every commit.
Prompt 3
How do I configure SwiftFormat to use 4-space indentation and disable the trailing comma rule in my project?
Prompt 4
How do I add SwiftFormat as an Xcode build phase so it runs automatically every time I compile?
Open on GitHub → Explain another repo

← nicklockwood on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.