@@ -1753,12 +1753,6 @@ let ocp_indent_janestreet_profile =
17531753 ; (" align_ops" , " true" )
17541754 ; (" align_params" , " always" ) ]
17551755
1756- let root =
1757- Option. map ! root ~f: Fpath. (fun x -> v x |> to_absolute |> normalize)
1758-
1759- let enable_outside_detected_project =
1760- ! enable_outside_detected_project && Option. is_none root
1761-
17621756let parse_line config ~from s =
17631757 let update ~config ~from ~name ~value =
17641758 let name = String. strip name in
@@ -1828,7 +1822,7 @@ let parse_line config ~from s =
18281822 | name -> update ~config ~from ~name ~value: " true" )
18291823 | _ -> Error (`Malformed s)
18301824
1831- let is_project_root dir =
1825+ let is_project_root ~ root dir =
18321826 match root with
18331827 | Some root -> Fpath. equal dir root
18341828 | None ->
@@ -1843,11 +1837,13 @@ let dot_ocamlformat_ignore = ".ocamlformat-ignore"
18431837
18441838let dot_ocamlformat_enable = " .ocamlformat-enable"
18451839
1846- let rec collect_files ~segs ~ignores ~enables ~files =
1840+ let rec collect_files ~enable_outside_detected_project ~root ~segs ~ignores
1841+ ~enables ~files =
18471842 match segs with
18481843 | [] | [" " ] -> (ignores, enables, files, None )
18491844 | "" :: upper_segs ->
1850- collect_files ~segs: upper_segs ~ignores ~enables ~files
1845+ collect_files ~enable_outside_detected_project ~root ~segs: upper_segs
1846+ ~ignores ~enables ~files
18511847 | _ :: upper_segs ->
18521848 let sep = Fpath. dir_sep in
18531849 let dir = String. concat ~sep (List. rev segs) |> Fpath. v in
@@ -1867,9 +1863,11 @@ let rec collect_files ~segs ~ignores ~enables ~files =
18671863 let f_2 = Fpath. (dir / dot_ocp_indent) in
18681864 if Fpath. exists f_2 then `Ocp_indent f_2 :: files else files
18691865 in
1870- if is_project_root dir && not enable_outside_detected_project then
1871- (ignores, enables, files, Some dir)
1872- else collect_files ~segs: upper_segs ~ignores ~enables ~files
1866+ if is_project_root ~root dir && not enable_outside_detected_project
1867+ then (ignores, enables, files, Some dir)
1868+ else
1869+ collect_files ~enable_outside_detected_project ~root ~segs: upper_segs
1870+ ~ignores ~enables ~files
18731871
18741872let read_config_file conf filename_kind =
18751873 match filename_kind with
@@ -1985,13 +1983,14 @@ let is_in_listing_file ~listings ~filename =
19851983 warn " ignoring %a, %s" Fpath. pp listing_file err ;
19861984 None )
19871985
1988- let build_config ~file ~is_stdin =
1986+ let build_config ~enable_outside_detected_project ~ root ~ file ~is_stdin =
19891987 let vfile = Fpath. v file in
19901988 let file_abs = Fpath. (vfile |> to_absolute |> normalize) in
19911989 let dir = Fpath. (file_abs |> split_base |> fst) in
19921990 let segs = Fpath. segs dir |> List. rev in
19931991 let ignores, enables, files, project_root =
1994- collect_files ~segs ~ignores: [] ~enables: [] ~files: []
1992+ collect_files ~enable_outside_detected_project ~root ~segs ~ignores: []
1993+ ~enables: [] ~files: []
19951994 in
19961995 let files =
19971996 match (xdg_config, enable_outside_detected_project) with
@@ -2036,9 +2035,10 @@ let build_config ~file ~is_stdin =
20362035 {conf with disable= not conf.disable}
20372036 | None -> conf
20382037
2039- let build_config ~file ~is_stdin =
2038+ let build_config ~enable_outside_detected_project ~ root ~ file ~is_stdin =
20402039 let conf, warn_now =
2041- collect_warnings (fun () -> build_config ~file ~is_stdin )
2040+ collect_warnings (fun () ->
2041+ build_config ~enable_outside_detected_project ~root ~file ~is_stdin )
20422042 in
20432043 if not conf.quiet then warn_now () ;
20442044 conf
@@ -2107,14 +2107,21 @@ type action =
21072107 | Check of [`Impl | `Intf ] input list
21082108 | Print_config of t
21092109
2110- let make_action action inputs =
2110+ let make_action ~ enable_outside_detected_project ~ root action inputs =
21112111 let make_file ?(with_conf = fun c -> c) ?name kind file =
2112- let conf = with_conf (build_config ~file ~is_stdin: false ) in
2112+ let conf =
2113+ with_conf
2114+ (build_config ~enable_outside_detected_project ~root ~file
2115+ ~is_stdin: false )
2116+ in
21132117 let name = Option. value ~default: file name in
21142118 {kind; name; file= File file; conf}
21152119 in
21162120 let make_stdin ?(name = " <standard input>" ) kind =
2117- let conf = build_config ~file: name ~is_stdin: false in
2121+ let conf =
2122+ build_config ~enable_outside_detected_project ~root ~file: name
2123+ ~is_stdin: false
2124+ in
21182125 {kind; name; file= Stdin ; conf}
21192126 in
21202127 match (action, inputs) with
@@ -2128,7 +2135,9 @@ let make_action action inputs =
21282135 let root = Option. value root ~default: (Fpath. cwd () ) in
21292136 (Fpath. (root / dot_ocamlformat |> to_string), true )
21302137 in
2131- let conf = build_config ~file ~is_stdin in
2138+ let conf =
2139+ build_config ~enable_outside_detected_project ~root ~file ~is_stdin
2140+ in
21322141 Ok (Print_config conf)
21332142 | (`No_action | `Output _ | `Inplace | `Check ), `No_input ->
21342143 Error " Must specify at least one input file, or `-` for stdin"
@@ -2159,6 +2168,12 @@ let make_action action inputs =
21592168 | `Check , `Stdin (name , kind ) -> Ok (Check [make_stdin ?name kind])
21602169
21612170let validate () =
2171+ let root =
2172+ Option. map ! root ~f: Fpath. (fun x -> v x |> to_absolute |> normalize)
2173+ in
2174+ let enable_outside_detected_project =
2175+ ! enable_outside_detected_project && Option. is_none root
2176+ in
21622177 if ! disable_outside_detected_project then
21632178 warn
21642179 " option `--disable-outside-detected-project` is deprecated and will \
@@ -2167,7 +2182,9 @@ let validate () =
21672182 let open Result in
21682183 validate_action ()
21692184 >> = fun action ->
2170- validate_inputs () >> = fun inputs -> make_action action inputs
2185+ validate_inputs ()
2186+ >> = fun inputs ->
2187+ make_action ~enable_outside_detected_project ~root action inputs
21712188 with
21722189 | Error e -> `Error (false , e)
21732190 | Ok action -> `Ok action
0 commit comments