Skip to main content

Use docker to run the new Elixir Code Formatter

·1 min

TL;DR: Run this to format your code:

docker run --rm -it -v $(pwd):/app -w /app leifg/elixir:edge mix format

The community has been very excited in the last couple of days about the Elixir 1.6 Code Formatter Announcement.

Of course you can use one of the many ElixirVersionManagementTools to try out the formatter. But if you don’t want to switch around between versions or if you (like me) stick to system Elixir, there is an easier way: Docker.

I already wrote about how to try out the latest Elixir in a Docker Container. The same principle applies here.

So here is how you format your code:

Update your edge Elixir image

docker pull leifg/elixir:edge

Setup your formatter options

Create a .formatter.exs file:

  inputs: [

Run the formatter in Docker

docker run --rm -it -v $(pwd):/app -w /app leifg/elixir:edge mix format

Explanation: you are going to mount your current directory in the docker container and then pass in the format command.