Rowland Carlson

How do you autoformat elixir code

2022-06-23

Using entr, a program that reruns commands on file change,
I can autoformat elixir code with the following:

while true; do
  find lib/ test/ | entr -d mix format
done

Run this command from the root directory of a project,
And all elixir files will be formatted on save.

Without the while loop,
Entr will run mix format on each file saved,
But won't detect new files added to the project.

Note that this is an infinite loop,
And that entr -d restarts mix format each time you break,
So use tmux or kill to exit the loop.