📈 GH Trending Explorer 🎲 Surprise me

← all repos

nicklockwood / SwiftFormat

git clone https://github.com/nicklockwood/SwiftFormat.git 0.64.0 · 5d ago 🔥 on GitHub Trending today

A command-line tool and Xcode Extension for formatting Swift code

+0
stars, 24h · #15,473
+10
stars, 7 days · #8,286
+~0
stars, 30 days · #22,374
8.9k
★ total · +0% this week
722
forks · 297 open issues

Star history (as recorded here)

2026-10-20 · 8,937 ★ 2026-10-22 · 8,938 ★
LanguageSwift
LicenseMIT
Created2016-08-22 (10y ago)
Last pushtoday
Watchers75
OwnerUser

Seen on GitHub Trending

  • 2026-10-21 — #12 weekly in swift · +10 ★
  • 2026-10-20 — #12 weekly in swift · +10 ★

Links

README excerpt
Table of Contents
-----------------
- What?
- Why?
- How?
 - Command-line tool
 - Xcode source editor extension
 - Xcode build phase
 - Swift Package Manager plugin
 - Via Applescript
 - VSCode plugin
 - Sublime Text plugin
 - Nova plugin
 - Git pre-commit hook
 - GitHub Actions
 - On CI using Danger
 - Bazel build
 - Docker
 - Prerelease Builds
- Configuration
 - Options
 - Rules
 - Swift version
 - Config file
 - Globs
 - Linting
 - Error codes
 - Cache
 - Snapshot
 - File headers
 - Markdown formatting
- FAQ
- Known issues
- Tip Jar
- Credits
What is this?
----------------
SwiftFormat is a code library and command-line tool for reformatting Swift code on macOS, Linux or Windows.
SwiftFormat goes above and beyond what you might expect from a code formatter. In addition to adjusting white space it can insert or remove implicit `self`, remove redundant parentheses, and correct many other deviations from the standard Swift idioms.
Why would I want to do that?
-----------------------------
Many programmers have a preferred style for formatting their code, and others seem entirely blind to the existing formatting conventions of a project (to the enragement of their colleagues).
When collaborating on a project, it can be helpful to agree on a common coding style, but enforcing that manually is tedious and error-prone, and can lead to arguments if some participants take it more seriously than others.
Having a tool to automatically enforce a common style eliminates those issues, and lets you focus on the behavior of the code, not its presentation.
How do I install it?
---------------------
That depends - There are several ways you can use SwiftFormat:
1. As a command-line tool that you run manually, or as part of some other toolchain
2. As a Source Editor Extension that you can invoke via the Editor > SwiftFormat menu within Xcode
3. As a build phase in your Xcode project, so that it runs every time you press Cmd-R or Cmd-B, or
4. As a Git pre-commit hook, so that it runs on any files you've changed before you check them in
Command-line tool
-------------------
**Installation:**
You can install the `swiftformat` command-line tool on macOS or Linux using Homebrew. Assuming you already have Homebrew installed, just type:
 [code] 
To update to the latest version once installed:
 [code] 
Alternatively, you can install the tool on macOS or Linux by using Mint as follows:
 [code] 
If you use Nix, you can add SwiftFormat to a `devShell` using `nixpkgs`:
 [code] 
If you need to pin SwiftFormat to a specific version in your `devShell`, you can use `acevif/swiftformat-nix`:
 [code] 
Replace `aarch64-darwin` with your system, and replace `swiftformat_0_58_7` with the version you want to install.
Or if you prefer, you can check out and build SwiftFormat manually on macOS, Linux or Windows as follows:
 [code] 
Prebuilt command-line binaries are available from GitHub Releases. As of 0.64.0, the repository no longer includes a prebuilt binary, and new releases are no