Hello, new user! Welcome! đź‘‹
If you are here, you are probably interested in using a formatting tool for your code base, so that you do not have to worry about formatting it by hand, and to speed up code review by focusing on the important parts.
OCamlFormat is probably what you are after!
OCamlFormat works by parsing then outputting again the same OCaml source file in a consistent style.
OCamlFormat can be installed with opam
:
opam install ocamlformat
Alternatively, see ocamlformat.opam
for manual build instructions.
Setting up your project to use the default profile and the OCamlFormat version you installed (hopefully the last one) in this .ocamlformat
file is considered good practice:
profile = default
version = 0.20.0
To manually invoke OCamlformat the general command is:
ocamlformat [OPTION]... [SRC]...
See ocamlformat --help
or man ocamlformat
for the detail about options.
You can also view it online.
The most common usecase involves using the dune
build system, once your project is correctly setup (see Dune's manual) you can reformat your project using:
dune build @fmt
- forum: https://discuss.ocaml.org/tags/ocamlformat
- github: https://github.com/ocaml-ppx/ocamlformat
- issues: https://github.com/ocaml-ppx/ocamlformat/issues
See CONTRIBUTING for how to help out.
OCamlFormat is MIT-licensed.