Skip to content

Commit

Permalink
Add back --disable-outside-detected-project (#2439)
Browse files Browse the repository at this point in the history
Co-authored-by: Jules Aguillon <[email protected]>
  • Loading branch information
Guillaume Petiot and Julow authored Nov 30, 2023
1 parent 3a10235 commit 0636bfe
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 27 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ profile. This started with version 0.26.0.

### Changed

- Added back the flag `--disable-outside-detected-project` (#2439, @gpetiot)
It was removed in version 0.22.
- \* Consistent formatting of comments (#2371, @Julow)
- Documentation comments are now formatted by default (#2390, @Julow)
Use the option `parse-docstrings = false` to disable.
Expand Down
11 changes: 6 additions & 5 deletions doc/manpage_ocamlformat.mld
Original file line number Diff line number Diff line change
Expand Up @@ -470,11 +470,6 @@ OPTIONS (REMOVED)
--align-variants-decl=VAL
This option has been removed in version 0.22.

--disable-outside-detected-project=VAL
This option has been removed in version 0.22. OCamlFormat is
disabled outside of a detected project by default, to enable the
opposite behavior use `enable-outside-detected-project`.

--doc-comments-val=VAL
This option has been removed in version 0.16. If you are using
`doc-comments-val=before` in combination with
Expand Down Expand Up @@ -535,6 +530,12 @@ OPTIONS
--disable-conf-files
Disable .ocamlformat configuration files.

--disable-outside-detected-project
If no .ocamlformat config files have been detected, disable the
formatting. OCamlFormat is disabled outside of a detected project
by default, to enable the opposite behavior use
--enable-outside-detected-project.

--doc
Parse input as an odoc documentation.

Expand Down
10 changes: 1 addition & 9 deletions lib/Conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,6 @@ module V = struct
let v0_22 = Version.make ~major:0 ~minor:22 ~patch:None
end

let disable_outside_detected_project =
let msg =
"OCamlFormat is disabled outside of a detected project by default, to \
enable the opposite behavior use `enable-outside-detected-project`."
in
let names = ["disable-outside-detected-project"] in
Decl.removed_option ~names ~since:V.v0_22 ~msg

let profile =
let doc =
"Select a preset profile which sets $(i,all) options, overriding lower \
Expand Down Expand Up @@ -349,7 +341,7 @@ let profile =
{conf with profile= elt; fmt_opts= p} )
(fun conf -> conf.profile)

let options = Store.[elt disable_outside_detected_project; elt profile]
let options = Store.[elt profile]

(** Options affecting formatting *)
module Formatting = struct
Expand Down
38 changes: 25 additions & 13 deletions lib/bin_conf/Bin_conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,35 @@ let enable_outside_detected_project =
(List.map File_system.project_root_witness ~f:(fun name ->
Format.sprintf "$(b,%s)" name ) )
in
let doc =
Format.sprintf
"Read $(b,.ocamlformat) config files outside the current project when \
no project root has been detected for the input file. The project \
root of an input file is taken to be the nearest ancestor directory \
that contains a %s file. If $(b,.ocamlformat) config files are \
located in the same directory or parents they are applied, if no \
$(b,.ocamlformat) file is found then the global configuration \
defined in $(b,\\$XDG_CONFIG_HOME/.ocamlformat) (or in \
$(b,\\$HOME/.config/.ocamlformat) if $(b,\\$XDG_CONFIG_HOME) is \
undefined) is applied."
witness
let enable =
let doc_enable =
Format.sprintf
"Read $(b,.ocamlformat) config files outside the current project \
when no project root has been detected for the input file. The \
project root of an input file is taken to be the nearest ancestor \
directory that contains a %s file. If $(b,.ocamlformat) config \
files are located in the same directory or parents they are \
applied, if no $(b,.ocamlformat) file is found then the global \
configuration defined in $(b,\\$XDG_CONFIG_HOME/.ocamlformat) (or \
in $(b,\\$HOME/.config/.ocamlformat) if $(b,\\$XDG_CONFIG_HOME) is \
undefined) is applied."
witness
in
Arg.info ["enable-outside-detected-project"] ~doc:doc_enable ~docs
in
let disable =
let doc_disable =
"If no $(b,.ocamlformat) config files have been detected, disable the \
formatting. OCamlFormat is disabled outside of a detected project by \
default, to enable the opposite behavior use \
$(b,--enable-outside-detected-project)."
in
Arg.info ["disable-outside-detected-project"] ~doc:doc_disable ~docs
in
Term.(
const (fun enable_outside_detected_project conf ->
{conf with enable_outside_detected_project} )
$ Arg.(value & flag & info ["enable-outside-detected-project"] ~doc ~docs) )
$ Arg.(value & vflag false [(true, enable); (false, disable)]) )

let inplace =
let doc = "Format in-place, overwriting input file(s)." in
Expand Down
7 changes: 7 additions & 0 deletions test/projects/disable_outside_detected_project.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
File "main.ml", line 1:
Warning: Ocamlformat disabled because [--enable-outside-detected-project] is not set and no [.ocamlformat] was found within the project (root: ../disable_outside_detected_project)
(* The following code should not be formatted *)
type t = {
foooooo : string;
baaaaar : Baaaaar.t;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(lang dune 1.11)
5 changes: 5 additions & 0 deletions test/projects/disable_outside_detected_project/main.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(* The following code should not be formatted *)
type t = {
foooooo : string;
baaaaar : Baaaaar.t;
}
22 changes: 22 additions & 0 deletions test/projects/dune
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,28 @@
(action
(diff outside_detected_project.expected outside_detected_project.output)))

(rule
(deps
disable_outside_detected_project/dune-project
disable_outside_detected_project/main.ml)
(package ocamlformat)
(enabled_if
(<> %{os_type} Win32))
(action
(with-outputs-to
disable_outside_detected_project.output
(chdir
disable_outside_detected_project
(run ocamlformat --disable-outside-detected-project main.ml)))))

(rule
(alias runtest)
(package ocamlformat)
(enabled_if
(<> %{os_type} Win32))
(action
(diff disable_outside_detected_project.expected disable_outside_detected_project.output)))

(rule
(deps
(source_tree outside_detected_project_with_name))
Expand Down

0 comments on commit 0636bfe

Please sign in to comment.