Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mimoo
Last active June 8, 2021 01:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mimoo/61a0ef76de8a5b856b3330c02ca7a9e6 to your computer and use it in GitHub Desktop.
Save mimoo/61a0ef76de8a5b856b3330c02ca7a9e6 to your computer and use it in GitHub Desktop.
how to use ocamlformat?

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment