ExFormat formats Elixir source code according to a standard set of rules
ExFormat formats Elixir source code according to a standard set of rules based on the elixir-style-guide. It tries its best to accommodate the user's intent by preserving intended layout and syntax. The documentation is available online.
Note: ExFormat is a prototype. For a production-ready version, please have a look at the latest code formatter that's under development by the Elixir core team.
As ExFormat works best with the unreleased Elixir v1.6, it is recommended to download the prebuilt escript (which embeds Elixir v1.6 in itself) and run it as an executable.
mix escript.install https://github.com/uohzxela/ex_format/raw/master/ex_format
If you haven't done so already, consider adding ~/.mix/escripts
directory to your PATH
environment variable.
# Change directory to your Elixir project
cd to/your/elixir/project
# Formats all files that match each wildcard
ex_format lib/**/*.ex config/**/*.exs
For those who are curious, the formatter is created by following these steps:
Hence, conceptually, this is a very simple formatter and is a good example of how pattern matching works in practice.
There are also contributions to Elixir tokenizer and parser to augment the AST with the necessary metadata for formatting, you can check these out here.