Repolode
nicklockwood

nicklockwood/SwiftFormat

A command-line tool and Xcode extension that automatically reformats Swift code to a consistent style.

Stars
8,954
Forks
730
Open issues
289
Last commit
20 hours ago

What is it?

SwiftFormat is a code library and command-line tool for reformatting Swift code on macOS, Linux or Windows. Beyond adjusting whitespace, it can insert or remove implicit self, remove redundant parentheses, and correct many other deviations from standard Swift idioms.

It addresses the cost of enforcing a shared coding style on a team by applying rules automatically instead of by manual review. Formatting behavior is controlled by more than 150 rules and a set of options, which can be set on the command line, in a .swiftformat config file, or inline with swiftformat directives in source comments. A lint mode reports violations without modifying files, which suits CI checks.

It can be run from the terminal, as a Swift Package Manager plugin, as an Xcode build phase, or through a Source Editor Extension, with installation via Homebrew, Mint, Nix, Docker or GitHub Actions.

Key features

  • 01Adds or removes implicit self and removes redundant parentheses.
  • 02Provides over 150 formatting rules that can be enabled or disabled individually.
  • 03Reads project settings from a .swiftformat config file with per-directory overrides.
  • 04Offers a lint mode that reports violations without changing files.
  • 05Integrates with Xcode, Swift Package Manager, Git pre-commit hooks and GitHub Actions.

Use cases

  • Enforcing a shared Swift coding style across a team's repositories.
  • Running format checks in CI to block unformatted pull requests.
  • Formatting Swift files automatically on save or on commit.
  • Applying formatting to Swift code in an Xcode project during builds.

Quick start

  1. 1

    Install the command-line tool via Homebrew

    brew install swiftformat
  2. 2

    Format Swift files in the current directory

    swiftformat .

Things to know

  • Running swiftformat . overwrites Swift files in place, so commit your changes to version control first.

In collections

Topics

FAQ

What is SwiftFormat?
A command-line tool and Xcode extension that automatically reformats Swift code to a consistent style. SwiftFormat is a code library and command-line tool for reformatting Swift code on macOS, Linux or Windows. Beyond adjusting whitespace, it can insert or remove implicit self, remove redundant parentheses, and correct many other deviations from standard Swift idioms.
Is SwiftFormat free to use? What license does it have?
SwiftFormat is open source under the MIT license. Check the license terms before using it in commercial products.
Is SwiftFormat still maintained?
Actively maintained. The last commit to SwiftFormat was on Nov 6, 2026.
What can I use SwiftFormat for?
Enforcing a shared Swift coding style across a team's repositories. Running format checks in CI to block unformatted pull requests. Formatting Swift files automatically on save or on commit. Applying formatting to Swift code in an Xcode project during builds.
How do I install SwiftFormat?
Install the command-line tool via Homebrew: brew install swiftformat Format Swift files in the current directory: swiftformat .
Where can I get SwiftFormat?
The source code and installation instructions are on GitHub: https://github.com/nicklockwood/SwiftFormat

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects