Stok Footage

Continually experimenting with new ideas and techniques — Reconstructing, Developing, Modernising.

A Young Person’s Guide to Dyalizer — Start Clean, Stay Clean

The most dispiriting thing I encounter in projects when I think “…maybe I should add dialyzer to this project…” is the wall of information which confronts me the first time I use mix dialyzer.

One way I avoid running into this on my own projects is to add dialyxir to my project immediately after doing mix new, and then use this in the .git/hooks/pre-push to help me catch problems as soon after I introduce them as reasonable:

#!/usr/bin/env bash

set -e
trap 'echo interrupted; exit' INT

cd $(git rev-parse --show-toplevel)

if [ -f "mix.lock" ]; then
  if grep -q '  "credo": {' "mix.lock"; then
    mix credo --all
  fi
  if grep -q '  "dialyxir": {' "mix.lock"; then
    mix dialyzer --halt-exit-status
  fi
fi

if [ -f "mix.exs" ]; then
  mix compile --all-warnings --warnings-as-errors
  mix test
fi

If I want to push a “bad” commit then I can always use --no-verify on the push command.

I hope this helps someone, it has helped me.

Tags: , ,

Leave a Reply

Your email address will not be published. Required fields are marked *