Format Erlang code "to the standard": using Emacs' erlang-mode.
Used daily in CI on 2600Hz's Kazoo project à la gofmt
.
rebar3
pluginAdd the plugin to your rebar config:
{plugins, [rebar3_fmt]}.
Then just call your plugin directly in an existing application:
$ rebar3 fmt
make
.PHONY: fmt
FMT = _build/erlang-formatter-master/fmt.sh
$(FMT):
mkdir -p _build/
curl -f#SL 'https://codeload.github.com/fenollp/erlang-formatter/tar.gz/master' | tar xvz -C _build/
# Pick either this one to go through the whole project
fmt: TO_FMT ?= .
# Or this faster, incremental pass
#fmt: TO_FMT ?= $(shell git --no-pager diff --name-only HEAD origin/master -- '*.app.src' '*.config' '*.config.script' '*.erl' '*.escript' '*.hrl')
fmt: $(FMT)
$(if $(TO_FMT), $(FMT) $(TO_FMT))
# Example:
# TO_FMT='src/a.erl include/b/hrl' make fmt
Some alternatives (in no particular order) to this dependency-heavy utility:
%% -*- erlang-indent-level: 2; indent-tabs-mode: nil -*-
Just like the CAP theorem, I posit the TIA theorem: tabs, indentation, alignment, choose two.
-- Loïc HoguinMore at https://github.com/fenollp/erlang-formatter/issues
$ embedded at the end of a string causes wrong indentation
{} inside multiline strings are indented
Linebreak after fun but before ( breaks indentation
Defining type as a tuple containing a fun() followed by expression throws Emacs error
Binary in a multiline list comprehension nests wrongly
Feel free to report issues encountered with this tool. I will minify & report them.