This is kind of trivial but I figured it might be useful for other people. We created a hook config for using ocamlformat with pre-commit:
pre-commit is a tool that makes it easier to run checks on changed files before commiting them, and this makes it so you can auto-run ocamlformat and ensure no unformatted code gets into your repo.
-
Install pre-commit like
pip install pre-commit
- In your repo, add a .pre-commit-config.yaml like:
--- repos: - repo: https://github.com/arenadotio/pre-commit-ocamlformat rev: master # or pick a commit sha I guess hooks: - id: ocamlformat
- Run
pre-commit install
- Now every time you run
git commit
(orpre-commit run
), it will run every staged OCaml file through ocamlformat and complain if there are any changes:$ pre-commit run ocamlformat ocamlformat.....Failed - hook id: ocamlformat - files were modified by this hook $ git add . $ pre-commit run ocamlformat ocamlformat.....Passed