How to disable ocamlformat in the vendor folder?

201 Views Asked by At

I have OCaml project and in vendor folder I have some libraries that are not of my own, I don't want to run ocamlformat on them I tried this

# .ocamlformat
profile = default
version = 0.24.1
# .ocamlformat-ignore
vendor/*

But when I run dune build @fmt I see a lot of errors regarding the vendor folder

(cd _build/default && /home/geckos/.opam/coq-of-solidity/bin/ocamlformat --intf vendor/ocaml-solidity/src/solidity-typechecker/solidity_typechecker.mli) > _build/default/vendor/ocaml-solidity/src/solidity-typechecker/.formatted/solidity_typechecker.mli
ocamlformat: Error while parsing /home/geckos/code/coq-of-solidity/_build/default/vendor/ocaml-solidity/.ocamlformat:
             Project should be formatted using ocamlformat version "0.15.0", but the installed version is "0.24.1"
             For option "align-cases": This option has been removed in version 0.22.
             For option "align-constructors-decl": This option has been removed in version 0.22.
             For option "align-variants-decl": This option has been removed in version 0.22.
             For option "let-open": This option has been removed in version 0.17. Concrete syntax will now always be preserved.
2

There are 2 best solutions below

0
On

Having vendor/** in your .ocamlformat-ignore file should fix your issue. No need to have a line for each sublevel of your vendor directory.

1
On

There's an FAQ entry explaining this in the documentation:

It is possible to disable OCamlFormat for the files of a directory by having an .ocamlformat file containing disable in this directory, or listing the files to ignore in an .ocamlformat-ignore file.

For now it is not possible to recursively ignore all subdirectories and files from a parent directory, you need to list all the descendants of the directory to ignore them, e.g.:

dir/*
dir/*/*
dir/*/*/*

It is also possible to add an .ocamlformat-ignore file containing * in every directory that needs to be ignored.

Edit: This FAQ entry is apparently outdated. It should also be possible to use vendor/"", as @gpetiot points out in the other answer. As the current maintainer he should know. (I've also submitted a PR to update the documentation)