Source-Code Formatting

Learn about formatting of Elixir code.

We'll cover the following...

The Elixir core team wanted to standardize the format of source code that was submitted to them for inclusion in the various Elixir core projects. They made it easy for submitters by including a source-code formatting tool in Elixir 1.6. This tool is pretty smart. It knows not only the syntax of Elixir but also the parse tree, meaning that it’ll often move things between lines, drop commas, add parentheses, and so on.

This is done using the mix format command. It can format single files, directory trees, and whole projects (see mix help format for information). This formatting replaces the files it touches, so we should make sure to check in before running it.

Let’s have a look at some before-and-after formatting.

Use of formatting

What happens ...