Skip to content

Commit 0636bfe

Browse files
Guillaume PetiotJulow
Guillaume Petiot
andauthored
Add back --disable-outside-detected-project (#2439)
Co-authored-by: Jules Aguillon <[email protected]>
1 parent 3a10235 commit 0636bfe

File tree

8 files changed

+69
-27
lines changed

8 files changed

+69
-27
lines changed

Diff for: CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ profile. This started with version 0.26.0.
88

99
### Changed
1010

11+
- Added back the flag `--disable-outside-detected-project` (#2439, @gpetiot)
12+
It was removed in version 0.22.
1113
- \* Consistent formatting of comments (#2371, @Julow)
1214
- Documentation comments are now formatted by default (#2390, @Julow)
1315
Use the option `parse-docstrings = false` to disable.

Diff for: doc/manpage_ocamlformat.mld

+6-5
Original file line numberDiff line numberDiff line change
@@ -470,11 +470,6 @@ OPTIONS (REMOVED)
470470
--align-variants-decl=VAL
471471
This option has been removed in version 0.22.
472472

473-
--disable-outside-detected-project=VAL
474-
This option has been removed in version 0.22. OCamlFormat is
475-
disabled outside of a detected project by default, to enable the
476-
opposite behavior use `enable-outside-detected-project`.
477-
478473
--doc-comments-val=VAL
479474
This option has been removed in version 0.16. If you are using
480475
`doc-comments-val=before` in combination with
@@ -535,6 +530,12 @@ OPTIONS
535530
--disable-conf-files
536531
Disable .ocamlformat configuration files.
537532

533+
--disable-outside-detected-project
534+
If no .ocamlformat config files have been detected, disable the
535+
formatting. OCamlFormat is disabled outside of a detected project
536+
by default, to enable the opposite behavior use
537+
--enable-outside-detected-project.
538+
538539
--doc
539540
Parse input as an odoc documentation.
540541

Diff for: lib/Conf.ml

+1-9
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,6 @@ module V = struct
277277
let v0_22 = Version.make ~major:0 ~minor:22 ~patch:None
278278
end
279279

280-
let disable_outside_detected_project =
281-
let msg =
282-
"OCamlFormat is disabled outside of a detected project by default, to \
283-
enable the opposite behavior use `enable-outside-detected-project`."
284-
in
285-
let names = ["disable-outside-detected-project"] in
286-
Decl.removed_option ~names ~since:V.v0_22 ~msg
287-
288280
let profile =
289281
let doc =
290282
"Select a preset profile which sets $(i,all) options, overriding lower \
@@ -349,7 +341,7 @@ let profile =
349341
{conf with profile= elt; fmt_opts= p} )
350342
(fun conf -> conf.profile)
351343

352-
let options = Store.[elt disable_outside_detected_project; elt profile]
344+
let options = Store.[elt profile]
353345

354346
(** Options affecting formatting *)
355347
module Formatting = struct

Diff for: lib/bin_conf/Bin_conf.ml

+25-13
Original file line numberDiff line numberDiff line change
@@ -116,23 +116,35 @@ let enable_outside_detected_project =
116116
(List.map File_system.project_root_witness ~f:(fun name ->
117117
Format.sprintf "$(b,%s)" name ) )
118118
in
119-
let doc =
120-
Format.sprintf
121-
"Read $(b,.ocamlformat) config files outside the current project when \
122-
no project root has been detected for the input file. The project \
123-
root of an input file is taken to be the nearest ancestor directory \
124-
that contains a %s file. If $(b,.ocamlformat) config files are \
125-
located in the same directory or parents they are applied, if no \
126-
$(b,.ocamlformat) file is found then the global configuration \
127-
defined in $(b,\\$XDG_CONFIG_HOME/.ocamlformat) (or in \
128-
$(b,\\$HOME/.config/.ocamlformat) if $(b,\\$XDG_CONFIG_HOME) is \
129-
undefined) is applied."
130-
witness
119+
let enable =
120+
let doc_enable =
121+
Format.sprintf
122+
"Read $(b,.ocamlformat) config files outside the current project \
123+
when no project root has been detected for the input file. The \
124+
project root of an input file is taken to be the nearest ancestor \
125+
directory that contains a %s file. If $(b,.ocamlformat) config \
126+
files are located in the same directory or parents they are \
127+
applied, if no $(b,.ocamlformat) file is found then the global \
128+
configuration defined in $(b,\\$XDG_CONFIG_HOME/.ocamlformat) (or \
129+
in $(b,\\$HOME/.config/.ocamlformat) if $(b,\\$XDG_CONFIG_HOME) is \
130+
undefined) is applied."
131+
witness
132+
in
133+
Arg.info ["enable-outside-detected-project"] ~doc:doc_enable ~docs
134+
in
135+
let disable =
136+
let doc_disable =
137+
"If no $(b,.ocamlformat) config files have been detected, disable the \
138+
formatting. OCamlFormat is disabled outside of a detected project by \
139+
default, to enable the opposite behavior use \
140+
$(b,--enable-outside-detected-project)."
141+
in
142+
Arg.info ["disable-outside-detected-project"] ~doc:doc_disable ~docs
131143
in
132144
Term.(
133145
const (fun enable_outside_detected_project conf ->
134146
{conf with enable_outside_detected_project} )
135-
$ Arg.(value & flag & info ["enable-outside-detected-project"] ~doc ~docs) )
147+
$ Arg.(value & vflag false [(true, enable); (false, disable)]) )
136148

137149
let inplace =
138150
let doc = "Format in-place, overwriting input file(s)." in
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
File "main.ml", line 1:
2+
Warning: Ocamlformat disabled because [--enable-outside-detected-project] is not set and no [.ocamlformat] was found within the project (root: ../disable_outside_detected_project)
3+
(* The following code should not be formatted *)
4+
type t = {
5+
foooooo : string;
6+
baaaaar : Baaaaar.t;
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(lang dune 1.11)
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
(* The following code should not be formatted *)
2+
type t = {
3+
foooooo : string;
4+
baaaaar : Baaaaar.t;
5+
}

Diff for: test/projects/dune

+22
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,28 @@
4141
(action
4242
(diff outside_detected_project.expected outside_detected_project.output)))
4343

44+
(rule
45+
(deps
46+
disable_outside_detected_project/dune-project
47+
disable_outside_detected_project/main.ml)
48+
(package ocamlformat)
49+
(enabled_if
50+
(<> %{os_type} Win32))
51+
(action
52+
(with-outputs-to
53+
disable_outside_detected_project.output
54+
(chdir
55+
disable_outside_detected_project
56+
(run ocamlformat --disable-outside-detected-project main.ml)))))
57+
58+
(rule
59+
(alias runtest)
60+
(package ocamlformat)
61+
(enabled_if
62+
(<> %{os_type} Win32))
63+
(action
64+
(diff disable_outside_detected_project.expected disable_outside_detected_project.output)))
65+
4466
(rule
4567
(deps
4668
(source_tree outside_detected_project_with_name))

0 commit comments

Comments
 (0)