This package formats generated source code before it is written to disk. Each language target dispatches to a language-specific formatter. Languages without a formatter pass through unchanged.
Dispatch
Format(target, fileName, data) in format.go routes by target and file extension:
All other targets/extensions return data unchanged.
Embedded Binaries
The formatters that run via WASM have their binaries embedded into the Go binary at compile time using //go:embed:
| File |
Source |
How to rebuild |
clangfmt.wasm |
Built from LLVM source |
cd formatters/clangfmt && ./build.sh |
dprint-plugin-typescript.wasm |
Pre-built from dprint releases |
Download from dprint plugin registry |
dprint-plugin-ruff.wasm |
Pre-built from dprint releases |
Download from dprint plugin registry |
dprint-plugin-java.wasm |
Pre-built from dprint releases |
Download from dprint plugin registry |
dprint-plugin-mago.wasm |
Pre-built from dprint releases |
Download from dprint plugin registry |
rubyfmt.wasm |
Built from Rust source |
cd formatters/rubyfmt && ./build.sh |
wazero (WASM)
wazero is a zero-dependency WebAssembly runtime for Go.
dprint (dprint.go): The TypeScript, Python, Java, and PHP formatters use the dprint plugin ABI. A single WASM module is instantiated per language at startup and reused for all formatting calls. Communication happens through shared memory buffers and exported functions (format, set_file_path, get_formatted_text, etc.).
rubyfmt (rubyfmt.go): The Ruby formatter uses the simpler WASI stdin/stdout model. The WASM module is compiled once at startup, then a fresh instance is created per format call (each needs a unique module name). The Rust WASI binary imports env.__wasi_init_tp which is stubbed as a no-op. WASI proc_exit(0) is treated as success.
Native
Go files use the standard library go/format.Source(). Terraform files use the hclwrite package from HashiCorp (inlined MPL-2.0 code from the Terraform CLI).
WASM Build Tag
Files that depend on wazero are gated with //go:build !js || !wasm. When compiling to WASM itself (e.g. for browser use), dprint_wasm.go provides stub implementations that return data unchanged.
Build Projects
Formatter build tooling lives in the formatters/ directory at the repo root:
formatters/rubyfmt/ — Rust/Cargo project for compiling rubyfmt to WASI WASM