Improve Developer Experience with pre-commit

Git offers a powerful tool in your arsenal with its hooks, but sharing hooks with your team is something that's painful at best.

Enter pre-commit. It allows you and your team to setup and share the same set of git hooks regardless of language, and have them version controlled.

Like [asdf]({{< relref "/post/2020/06/29/asdf-todays-version-manager" >}}) this is another multi-language environment tool, which is something I favor for multiple reasons. The first is there is a strong possibility as a software engineer that you're going to be working in multiple languages throughout your career, and likely even within the same team in a given organization, and so if you can learn tools that aren't specific to that language while still delivering the necessary value, they are preferable.

Install & setup:

brew install pre-commit
pre-commit sample-config

For Elixir specifically:

# .pre-commit-config.yaml

repos:
  - repo: https://gitlab.com/jvenom/elixir-pre-commit-hooks
    # replace the rev with the git SHA you'd like to use
    rev: e3c9551aeff388c286026b3036a384d371173c42
    hooks:
      - id: mix-format
      - id: mix-test

For detailed instructions, or those of you not on MacOS, you can checkout the official docs.

From there, ensure the tasks and their dependencies are installed:

pre-commit install

Now on each commit all of the specified hooks will run, in this case Elixir's default formatter, and your test suite.

And you're off to the races. Be sure to checkout the options for other hooks such as only pre-push.

And let me know via email or Twitter how you improve your developer experience.