Skip to content

Commit

Permalink
Display a warning for new enable/disable-outside-detected-project beh…
Browse files Browse the repository at this point in the history
…avior
  • Loading branch information
gpetiot committed Oct 4, 2023
1 parent bc91e42 commit 27988d9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 31 deletions.
18 changes: 13 additions & 5 deletions doc/manpage_ocamlformat.mld
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ OPTIONS (CODE FORMATTING STYLE)
file defined in $XDG_CONFIG_HOME (or in $HOME/.config if
$XDG_CONFIG_HOME is undefined) is used.

Warning: in the next release, OcamlFormat will be enabled by default,
the presence of a project root will not be checked unless
[--disable-outside-detected-project] is used.

If the disable option is not set, an .ocamlformat-ignore file
specifies files that OCamlFormat should ignore. Each line in an
.ocamlformat-ignore file specifies a filename relative to the
Expand Down Expand Up @@ -470,11 +474,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 +534,15 @@ 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. Warning: in the next release,
OCamlFormat will be enabled by default, the presence of a project
root will not be checked unless --disable-outside-detected-project
is used.

--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 @@ -274,14 +274,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 @@ -346,7 +338,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
51 changes: 35 additions & 16 deletions lib/bin_conf/Bin_conf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ let info =
$(b,ocamlformat) file defined in $(b,\\$XDG_CONFIG_HOME) (or in \
$(b,\\$HOME/.config) if $(b,\\$XDG_CONFIG_HOME) is undefined) is \
used."
; `P
"$(b,Warning:) in the next release, OcamlFormat will be enabled by \
default, the presence of a project root will not be checked unless \
[--disable-outside-detected-project] is used."
; `P
"If the $(b,disable) option is not set, an $(b,.ocamlformat-ignore) \
file specifies files that OCamlFormat should ignore. Each line in \
Expand Down Expand Up @@ -116,32 +120,45 @@ 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).\n\
$(b,Warning:) in the next release, OCamlFormat will be enabled by \
default, the presence of a project root will not be checked unless \
$(b,--disable-outside-detected-project) is used."
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
declare_option
~set:(fun inplace conf -> {conf with inplace})
Arg.(value & flag & info ["i"; "inplace"] ~doc ~docs)

(* Other Flags *)

let check =
let doc =
"Check whether the input files already are formatted. Mutually \
Expand Down Expand Up @@ -578,7 +595,9 @@ let build_config ~enable_outside_detected_project ~root ~file ~is_stdin =
in
warn ~loc:(Location.in_file file)
"Ocamlformat disabled because [--enable-outside-detected-project] is \
not set and %s"
not set and %s. In the next release, OcamlFormat will be enabled by \
default, the presence of a project root will not be checked unless \
[--disable-outside-detected-project] is used."
why ) ;
Operational.update conf ~f:(fun f ->
{f with disable= {f.disable with v= true}} ) )
Expand Down
2 changes: 1 addition & 1 deletion test/projects/outside_detected_project.expected
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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: ../outside_detected_project)
Warning: Ocamlformat disabled because [--enable-outside-detected-project] is not set and no [.ocamlformat] was found within the project (root: ../outside_detected_project). In the next release, OcamlFormat will be enabled by default, the presence of a project root will not be checked unless [--disable-outside-detected-project] is used.
(* The following code should not be formatted *)
type t = {
foooooo : string;
Expand Down

0 comments on commit 27988d9

Please sign in to comment.