A dprint process plugin that formats Swift using SwiftFormat.
Supported platforms: macOS (Apple Silicon + Intel) and Linux (x86_64 + aarch64). Windows is not supported in v1.
Requires dprint 0.40+ (process plugin schema v5).
What is dprint?
dprint is a fast, pluggable code formatter written in Rust. Instead of shipping one formatter per
language, it provides a single CLI and configuration file (dprint.json) that delegates to per-language plugins.
You run dprint fmt once and every configured plugin formats the files it owns — TypeScript, JSON, Markdown, TOML, and
more — with consistent caching, incremental formatting, and editor integration.
dprint plugins come in two flavors: Wasm plugins (sandboxed, portable, downloaded automatically) and process plugins (native executables for tools that cannot run inside Wasm). This plugin is a process plugin.
What is SwiftFormat?
SwiftFormat by Nick Lockwood is the de-facto community formatter for
Swift. It applies a large set of opinionated, configurable rules (indentation, spacing, redundant syntax removal, import
sorting, and much more) and is widely used in iOS, macOS, and server-side Swift projects. It reads options from
command-line flags and from a .swiftformat file discovered relative to each source file.
Why this project?
dprint has no official Swift plugin, and it cannot have a Wasm one: SwiftFormat depends on Apple's SwiftSyntax and cannot be compiled to dprint's Wasm sandbox. This repo fills that gap with a process plugin that spawns the SwiftFormat CLI over dprint's stdio protocol.
The payoff is a single formatting entry point for mixed-language repositories. Teams that already run dprint fmt for
TypeScript, JSON, and Markdown can format Swift the same way — same config file, same cache, same editor command —
without maintaining a separate SwiftFormat invocation. Each platform release bundles a pinned SwiftFormat binary, so
contributors get reproducible formatting whether or not they have SwiftFormat installed locally.
How it works
dprint CLI ←stdio v5→ dprint-plugin-swift (Rust) ←subprocess→ swiftformat
dprint streams each Swift file to the plugin over its stdio protocol. The plugin resolves the effective configuration,
builds a swiftformat stdin --stdinpath <path> command, pipes the source through the SwiftFormat CLI, and returns the
formatted result to dprint.
At runtime the plugin discovers the SwiftFormat binary in this order:
SWIFTFORMAT_PATHenvironment override (development)- A sibling
swiftformatnext to the plugin executable (bundled in the platform zip) swiftformatonPATH
Quick start
Add the plugin with the dprint CLI:
dprint add drluckyspin/dprint-plugin-swift
This adds a versioned, checksummed entry under plugins in your dprint.json. Add a swiftformat section for options:
Update to the latest release with dprint config update, or see
latest.json for the current URL and checksum.
Manual install
Alternatively, pin the plugin URL yourself:
You can also keep a .swiftformat file in your project — the plugin passes --stdinpath so SwiftFormat discovers it
automatically.
Quick start (exec plugin MVP)
If you already have swiftformat on your PATH and want to try formatting before installing this plugin:
Smoke test:
echo 'struct Example{let x:Int}' | swiftformat stdin --stdinpath /tmp/Example.swift
Configuration
See metadata/schema.json or the CDN schema for the full schema.
| Property | Description |
|---|---|
swiftVersion |
Swift language version (--swiftversion) |
configPath |
Explicit .swiftformat path (--config) |
lineWidth |
Max line width (--maxwidth) |
indentWidth |
Indent size (--indent) |
useTabs |
Use tabs (--tabs enabled) |
options |
Passthrough SwiftFormat rule flags |
dprint global settings (lineWidth, indentWidth, useTabs) are applied when not overridden in the plugin section.
SwiftFormat version matrix
| Plugin version | Bundled SwiftFormat |
|---|---|
| 0.1.0 | 0.61.1 |
Project layout
dprint-plugin-swift/
├── plugin/src/
│ ├── main.rs # Tokio runtime + handle_process_stdio_messages
│ ├── handler.rs # AsyncPluginHandler (dprint protocol)
│ ├── config.rs # Config resolution + CLI arg mapping
│ └── formatter/
│ ├── command.rs # Build swiftformat argv
│ └── swiftformat.rs # Subprocess + binary discovery
├── metadata/ # VERSION, schema.json, LICENSES (embedded in plugin)
├── scripts/ # Bash tooling (source log.bash)
├── testdata/ # Snapshot integration tests
├── vendor/swiftformat/ # Downloaded SwiftFormat binaries (gitignored)
├── Makefile # Single entry point for build/test/release
└── VERSION # Source of truth for the plugin semver
Development
All commands run through make (see make help).
make check # verify Rust, dprint, swiftformat make fetch-swiftformat # download SwiftFormat for host platform make build # build release plugin make test # run testdata snapshot tests make lint # clippy + rustfmt make bump-version # sync VERSION → Cargo.toml, metadata, README
Pin the plugin version in the root VERSION file, then run make bump-version. See RELEASE.md for the
full release checklist and AGENTS.md for a deeper tour of the architecture.
See also
| Project | Notes |
|---|---|
| dprint | The pluggable code formatter this extends |
| SwiftFormat | The Swift formatter this plugin drives |
| dprint plugins | Official and community formatting plugins |
Thanks to
- dprint for the formatter and process-plugin protocol
- SwiftFormat for the underlying Swift formatting engine
Contributing
Issues and pull requests are welcome. Use make for all build, test, and format operations, and run make test after
Rust changes.
License
MIT — see LICENSE. SwiftFormat is MIT-licensed and bundled in platform releases.