OCaml has a tool to format, OCamlformat, that is too configurable and hard to use.
First, it won't work if you don't have an empty file called .ocamlformat
at the root of your project.
Here's the man page but it's honestly too long and has no examples. Avoid configuring ocamlformat because then nobody will be able to understand your codebase. Use vanilla ocamlformat please.
To format every file in your project, do:
fd '\.ml[i]?$' | xargs -n1 ocamlformat -i
This presumes you have fd installed.
fd
will find all files that end with .ml
or .mli
, whereas xargs
will take every line of the result to pass it to ocamlformat
(with option -i
to write the changes directly to the files affected).