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
- Now every time you run
pre-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