ocamlformat icon indicating copy to clipboard operation
ocamlformat copied to clipboard

Bug: Honor ignored files before checking version

Open sir4ur0n opened this issue 6 months ago • 5 comments

Describe the bug When using .ocamlformat-ignore to ignore a directory, ocamlformat still checks the version of .ocamlformat files in this directory and fails if it's different.

How to Reproduce Steps to reproduce the behavior: Have this file structure:

- .ocamlformat-ignore
- .ocamlformat
- vendor/.ocamlformat
- vendor/a.ml
# .ocamlformat-ignore
vendor/**
# .ocamlformat
version=0.26.2
# vendor/.ocamlformat
version=0.27.0

Running ocamlformat (e.g. with dune fmt) fails:

File "vendor/.formatted/_unknown_", line 1, characters 0-0:
ocamlformat: Error while parsing <root directory>/_build/.sandbox/6d68df527a037d3db3fd364e008232ac/default/vendor/.ocamlformat:
             Project should be formatted using ocamlformat version "0.27.0", but the installed version is "0.26.2"

I think the version check should only run on non-ignored directories.

Workaround

# .ocamlformat
version=0.26.2
version-check=false

But it no longer checks the ocamlformat version at the root either, which is not great.

sir4ur0n avatar Jul 15 '25 09:07 sir4ur0n

I've been hitting the same issue. Is there any chance this gets fixed?

redianthus avatar Dec 07 '25 23:12 redianthus

Does the issue with the configuration in vendored directories go away with (vendored_dirs ..) ? Doc: https://dune.readthedocs.io/en/stable/reference/dune/vendored_dirs.html

Julow avatar Dec 08 '25 17:12 Julow

It does (as well as using (dirs :standard \ mysubdir)) but unfortunately, I can not use any of them for other reasons.

redianthus avatar Dec 08 '25 20:12 redianthus

@Julow Using (vendored_dirs ..) is indeed another workaround solution, but with other potentially undesirable effects (e.g. dune test will ignore this directory).

I think the original issue remains valid. The version check should not run on ignored directories.

sir4ur0n avatar Dec 09 '25 13:12 sir4ur0n

I think honoring ignored files before checking version is the right thing to do. Could you do it ?

Julow avatar Dec 17 '25 11:12 Julow