Fourmolu vs gofmt
Fourmolu
fourmolu.github.iogofmt
go.devSide by side
| Figure | Fourmolu | gofmt |
|---|---|---|
| Price from | Free | Free |
| Free plan | Yes | Yes |
| Free trial | — | — |
| Open source | — | — |
| Web | Yes | — |
| Windows | Yes | Yes |
| macOS | — | Yes |
| Linux | Yes | Yes |
| Plans published | 1 | 1 |
| Spec score · Code Formatting Tools | 8.3 (#4) | 7.8 (#13) |
| Purpose | Fourmolu formats Haskell source code and is a configurable fork of Ormolu. | Gofmt automatically formats Go programs using tabs for indentation and blanks for alignment. |
Plans
In their own words
Fourmolu
Fourmolu is a configurable formatter for Haskell source code and a fork of Ormolu. It uses GHC’s parser and aims to keep diffs small, produce idempotent output, and handle large projects. Set formatting options in `fourmolu.yaml` or pass them on the command line. Controls include indentation, line length, import grouping, record layout, Haddock comments, Unicode output, and operator fixities. Fourmolu can find the relevant Cabal file to read default extensions and dependencies that help determine fixities. Magic comments can disable formatting for selected code, and command-line options can target a line region. There is an interactive browser demo with configurable formatting and program options. Installation instructions cover GHCup, Cabal, Stack, and dotslash; editor integration is documented through Haskell Language Server. The project recommends a GitHub Action to keep projects formatted. Its listed current release is v0.21.0.0. CPP handling is experimental and limited to simple cases where conditionals surround top-level declarations. Output always uses LF line endings, which can cause check mode to fail on CRLF files.
gofmt
gofmt is the Go source formatter distributed with Go installations, available on Linux, macOS, and Windows. It formats Go programs using tabs for indentation and spaces for alignment. With no path, it reads standard input; given a directory, it processes .go files recursively while skipping files whose names begin with a period. By default, reformatted source is written to standard output. Flags can show differences, list files that need formatting, apply rewrite rules, simplify code, or report all errors. The rewrite option uses patterns and replacements written as valid Go expressions. gofmt can also arrange documentation comments into canonical paragraphs, lists, headings, links, and code blocks. The Go project documents integrations for Vim, Emacs, Eclipse, and Sublime Text, plus Git pre-commit hooks and Mercurial. Since Go 1.18, it reads and formats files concurrently, with memory use limited in proportion to GOMAXPROCS. The executable is equivalent to go fmt. It is free, included in the Go installation, and distributed under a BSD-style license.