Faster mix format

Posted on November 7, 2023
Tags: elixir

EDIT: mix format has been updated now to only format the files which have changed so the workaround with git diff is no longer needed.

Running mix format on larger projectes can be very slow as every file is being checked. mix format can be given a list of files such as mix format user.ex api.ex finance.ex so that it formats only the given files.

You can do this by running mix format $(git diff --name-only).

time mix format
mix format  2.23s user 0.68s system 285% cpu 1.022 total

time mix format $(git diff --name-only)
mix format $(git diff --name-only)  0.26s user 0.11s system 51% cpu 0.725 total