# Erlfmt - opinionated formatter for Erlang

**URL:** <https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829>\
**Category:** Libraries\
**Tags:** erlang, code-formatters\
**Created:** [June 15, 2025, 2:28pm UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829 "2025-06-15T14:28:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![michalmuskala](https://erlangforums.com/user_avatar/erlangforums.com/michalmuskala/32/247_2.png) [@michalmuskala](https://erlangforums.com/u/michalmuskala)\
**Post date:** [June 15, 2025, 2:28pm UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829/1 "2025-06-15T14:28:18Z")

</div>

# Erlfmt

This is the main thread for **erlfmt, the opinionated formatter** for Erlang.

## Usage

In a `rebar3` project, you can add this to your `rebar.config` file:

```erlang
{project_plugins, [erlfmt]}.
{erlfmt, [write]}.

```

You’ll be able to then run:

```sh
$ rebar3 fmt # format all supported files in your project
$ rebar3 fmt --check # verify everything is formatted in CI

```

More detailed instructions are available in [documentation](https://github.com/WhatsApp/erlfmt/blob/main/doc/RebarUsage.md).

The formatter can also be used as a standalone [escript](https://github.com/WhatsApp/erlfmt?tab=readme-ov-file#escript).

## Design principles

Erlfmt has a set of [reasoned principles](https://github.com/WhatsApp/erlfmt?tab=readme-ov-file#design-principles) that it attempts to follow, and major choices are documented in [decision](https://github.com/WhatsApp/erlfmt/blob/main/doc/Readme.md) documents. Erlfmt will always preserve the exact AST of the code, changing only whitespace – this invariant is actively verified each time you format your code.  
Erlfmt is designed to work with the engineer by respecting some of their [formatting choices](https://github.com/WhatsApp/erlfmt?tab=readme-ov-file#manual-interventions).

## Incomplete code

Since erlfmt is intended to be used interactively in an editor for format-on-save, it can always format your code – in worst case it will reprint, without changing, sections of the file it can’t parse. Furthermore, it supports some edge cases that Erlang compiler considers errors, like trailing comas in containers (that are automatically removed) and `case` or `receive` expressions without clauses.

## OTP support

We’ve recently released [version 1.7.0](https://github.com/WhatsApp/erlfmt/releases/tag/v1.7.0) that adds support for new OTP 28 features like zip & strict generators in comprehensions, and nominal types. Minimum required version is OTP 21.

> **[GitHub - WhatsApp/erlfmt: An automated code formatter for Erlang](https://github.com/WhatsApp/erlfmt)**
>
> An automated code formatter for Erlang

---

<div class="post-metadata">

**Author:** ![gorenje](https://erlangforums.com/user_avatar/erlangforums.com/gorenje/32/2828_2.png) [@gorenje](https://erlangforums.com/u/gorenje)\
**Post date:** [June 17, 2025, 4:10pm UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829/2 "2025-06-17T16:10:24Z")

</div>

Hi @michalmuskala

I use erlfmt everyday - well on days that I’m coding Erlang - and love it, absolutely wonderful.

One thing I was wondering about is alignment of arrows, I tend to do this:

```erlang
    Data = #{
      <<"id">> => IdStr,
      <<"z">> => ZStr,
      <<"_alias">> => IdStr,
      <<"path">> => ZStr,
      <<"name">> => NameStr,
      <<"msg">> => jstr(ErrMsg),
      <<"format">> => <<"string">>
     },

```

but erlfmt removes that so I’ve got a `erlfmt:ignore` on the top of that.

Is there a way - is it already available - to get erlfmt to keep that alignment? I’m not a bookworm when it comes to the options of erlfmt, so please excuse my ignorance if its already possible …

Cheers again for a great tool!

Gerrit

---

<div class="post-metadata">

**Author:** ![paulo-f-oliveira](https://erlangforums.com/user_avatar/erlangforums.com/paulo-f-oliveira/32/1103_2.png) [@paulo-f-oliveira](https://erlangforums.com/u/paulo-f-oliveira)\
**Post date:** [June 18, 2025, 11:22pm UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829/3 "2025-06-18T23:22:24Z")

</div>

Hey, @gorenje.

`erlfmt`, as far as I’m aware, and the documentation shows, has only 2 “options”:

1. line length (`print_width`)
2. ignore this block (`erlfmt:ignore-begin ... erlfmt:ignore-end`)

and that’s by design:

> The second principle is to provide as little configuration as possible. This removes contention points and makes it easier to achieve the goal of consistent code. Instead of providing configuration, the formatter respects a limited set of choices made in the original code to preserve intent and make it easier to achieve beautiful code based on contextual hints.

---

<div class="post-metadata">

**Author:** ![gorenje](https://erlangforums.com/user_avatar/erlangforums.com/gorenje/32/2828_2.png) [@gorenje](https://erlangforums.com/u/gorenje)\
**Post date:** [June 19, 2025, 7:11am UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829/4 "2025-06-19T07:11:10Z")

</div>

> [@paulo-f-oliveira](#):
>
> The second principle is to provide as little configuration as possible.

Thanks for pointing that out, that makes it clear what erlfmt aims to achieve.

---

<div class="post-metadata">

**Author:** ![michalmuskala](https://erlangforums.com/user_avatar/erlangforums.com/michalmuskala/32/247_2.png) [@michalmuskala](https://erlangforums.com/u/michalmuskala)\
**Post date:** [June 19, 2025, 8:11pm UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829/5 "2025-06-19T20:11:45Z")

</div>

Thanks @gorenje for the kind words.

We generally don’t support aligning things vertically in erlfmt. The main issue is with when you add another line that’s longer than existing lines – you either need to keep things not aligned anymore or realign all of the lines. This increases the diff between versions making it include unrelated lines – decreasing utility of blames, and increasing the chance of merge conflicts.

And yes, as Paulo pointed out, we generally avoid options and try to keep things as minimal as possible.

---

<div class="post-metadata">

**Author:** ![michalmuskala](https://erlangforums.com/user_avatar/erlangforums.com/michalmuskala/32/247_2.png) [@michalmuskala](https://erlangforums.com/u/michalmuskala)\
**Post date:** [February 23, 2026, 2:53pm UTC](https://erlangforums.com/t/erlfmt-opinionated-formatter-for-erlang/4829/6 "2026-02-23T14:53:04Z")

</div>

I’ve just released a new maintenance release addressing some issues and with further improvements.

## v1.8.0 (23.02.2026)

### Enhancements

- Support unions in macro arguments
- Preserve empty lines inside `maybe` expression bodies
- Add `--out-full` option
- Bypass file server to improve IO performance

### Fixes

- Fix multiline sigil strings causing “formatter result not equivalent” error
- Fix non-idempotent formatting of multi-line binary strings
- Fix escript skip path losing shebang comments with `--require-pragma`
