Skip to content

Known formatters

Here is a list of all the formatters we tested. Feel free to send a PR to add other ones!

Contents

Single-language formatters:

Multilanguage formatters:

Cabal

cabal-fmt

command = "cabal-fmt"
options = ["--inplace"]
includes = ["*.cabal"]

Elm

elm-format

command = "elm-format"
options = ["--yes"]
includes = ["*.elm"]

Golang

gofmt

command = "gofmt"
options = ["-w"]
includes = ["*.go"]

gofumpt

command = "gofumpt"
includes = ["*.go"]

Haskell

hlint

command = "hlint"
includes = [ "*.hs" ]

Ormolu

Make sure to use ormolu 0.1.4.0+ as older versions don't adhere to the spec.

command = "ormolu"
options = [
 "--ghc-opt", "-XBangPatterns",
 "--ghc-opt", "-XPatternSynonyms",
 "--ghc-opt", "-XTypeApplications",
 "--mode", "inplace",
 "--check-idempotence",
]
includes = ["*.hs"]

stylish-haskell

command = "stylish-haskell"
options = [ "--inplace" ]
includes = [ "*.hs" ]

Lua

StyLua

command = "stylua"
includes = ["*.lua"]

Nix

Alejandra

command = "alejandra"
includes = ["*.nix"]

nixpkgs-fmt

command = "nixpkgs-fmt"
includes = ["*.nix"]

OCaml

ocamlformat

command = "ocamlformat"
options = ["-i"]
includes = ["*.ml", "*.mli"]

PureScript

purs-tidy

command = "purs-tidy"
includes = ["*.purs"]

Python

black

command = "black"
includes = ["*.py"]

Ruby

rufo

Rufo is an opinionated ruby formatter. By default it exits with status 3 on file change so you have to pass the -x option.

command = "rufo"
options = ["-x"]
includes = ["*.rb"]

Rust

cargo fmt is not supported as it doesn't follow the spec. It doesn't allow to pass arbitrary files to be formatter, an ability which treefmt relies on. Use rustfmt instead (which is what cargo fmt uses under the hood).

rustfmt

command = "rustfmt"
options = ["--edition", "2018"]
includes = ["*.rs"]

Scala

scalafmt

command = "scalafmt"
includes = ["*.scala"]

Shell

shellcheck

command = "shellcheck"
includes = ["*.sh"]

shfmt

command = "shfmt"
options = [
 "-i",
 "2",  # indent 2
 "-s",  # simplify the code
 "-w",  # write back to the file
]
includes = ["*.sh"]

Terraform

terraform

Make sure to use terraform 1.3.0 or later versions, as earlier versions format only one file at a time. See the details here.

command = "terraform"
options = ["fmt"]
includes = ["*.tf"]

Typst

typstfmt

command = "typstfmt"
includes = ["*.typ", "*.typst"]

Multi-language formatters

clang-format

A tool to format C/C++/Java/JavaScript/Objective-C/Protobuf/C# code.

command = "clang-format"
options = [ "-i" ]
includes = [ "*.c", "*.cpp", "*.cc", "*.h", "*.hpp" ]

Note: This example focuses on C/C++ but can be modified to be used with other languages.

Prettier

An opinionated code formatter that supports many languages.

command = "prettier"
options = ["--write"]
includes = [
 "*.css",
 "*.html",
 "*.js",
 "*.json",
 "*.jsx",
 "*.md",
 "*.mdx",
 "*.scss",
 "*.ts",
 "*.yaml",
]