ocaml-ppx / ocamlformat

Auto-formatter for OCaml code
MIT License
632 stars 180 forks source link

Bug?: `--enable-outside-detected-project` does not use global configuration in projects without `.ocamlformat` #2509

Open lentil32 opened 10 months ago

lentil32 commented 10 months ago

Describe the bug

When dune-project exists and project-wise .ocamlformat does not exist, unconfigured default foramtting will be used. (macOS)

Expected Behavior Use global configuration if it is a project directory and no .ocamlformat file exist. Or, add --auto-adopt-global-config-when-local-absent option.

How to Reproduce

$XDG_CONFIG_HOME/ocamlformat:

profile=janestreet # 'default', 'janestreet', ...

In project directories, i.e., with dune-project file, or even in directories that is not OCaml project but .git exists,

$ ocamlformat --enable-outside-detected-project --print-config
...
space-around-variants=true
stritem-extension-indent=0
type-decl=compact
type-decl-indent=2
wrap-comments=false
wrap-fun-args=true
profile=default

Not in project directories,

$ ocamlformat --enable-outside-detected-project --print-config
...
type-decl-indent=2 (profile janestreet (file ../../.config/ocamlformat:1))
wrap-comments=false (profile janestreet (file ../../.config/ocamlformat:1))
wrap-fun-args=false (profile janestreet (file ../../.config/ocamlformat:1))
profile=janestreet (file ../../.config/ocamlformat:1)

See also

Julow commented 10 months ago

I agree that ocamlformat should use the global configuration when --enable-outside-detected-project and a project is detected but has no configuration.