Skip to content

Commit 27c6f24

Browse files
JulowGuillaume Petiot
authored and
Guillaume Petiot
committed
Revert "Strings of length < 80 are trivial and simple"
This reverts commit 55ebbe5.
1 parent 8deba41 commit 27c6f24

9 files changed

+40
-27
lines changed

lib/Ast.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ module Exp = struct
152152
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
153153
(* Short strings are trivial. *)
154154
| Pexp_constant {pconst_desc= Pconst_string (str, _, None); _} ->
155-
String.length str < 80
155+
String.length str < 30
156156
| Pexp_constant _ | Pexp_field _ | Pexp_ident _ | Pexp_send _ -> true
157157
| Pexp_construct (_, exp) -> Option.for_all exp ~f:is_trivial
158158
| Pexp_prefix (_, e) -> is_trivial e
@@ -1518,7 +1518,13 @@ end = struct
15181518
let rec is_simple (c : Conf.t) width ({ast= exp; _} as xexp) =
15191519
let ctx = Exp exp in
15201520
match exp.pexp_desc with
1521-
| Pexp_constant _ -> Exp.is_trivial exp
1521+
(* String literals using the heavy syntax are not simple. *)
1522+
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
1523+
(* Only strings fitting on the line are simple. *)
1524+
| Pexp_constant {pconst_desc= Pconst_string (_, loc, None); _} ->
1525+
Exp.is_trivial exp
1526+
|| (Location.height loc = 1 && fit_margin c (width xexp))
1527+
| Pexp_constant _ -> true
15221528
| Pexp_field _ | Pexp_ident _ | Pexp_send _
15231529
|Pexp_construct (_, None)
15241530
|Pexp_variant (_, None) ->

lib/Conf_decl.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ let status_doc ppf = function
208208

209209
let generated_flag_doc ~allow_inline ~doc ~kind ~default ~status =
210210
let default = if default then "set" else "unset" in
211-
Format.asprintf "%s The flag is $(b,%s) by default.%s%a" doc default
211+
Format.asprintf "%s The flag is $(b,%s) by default.%s%a"
212+
doc default
212213
(in_attributes allow_inline kind)
213214
status_doc status
214215

@@ -217,7 +218,8 @@ let generated_doc conv ~allow_inline ~doc ~kind ~default ~status =
217218
let default =
218219
if String.is_empty default_doc then "none" else default_doc
219220
in
220-
Format.asprintf "%s The default value is $(b,%s).%s%a" doc default
221+
Format.asprintf "%s The default value is $(b,%s).%s%a"
222+
doc default
221223
(in_attributes allow_inline kind)
222224
status_doc status
223225

@@ -325,13 +327,13 @@ module Value = struct
325327
| Some x -> (name, value, doc, `Deprecated x)
326328

327329
let pp_deprecated s ppf {dmsg= msg; dversion= v} =
328-
Format.fprintf ppf "Value `%s` is deprecated since version %a. %s" s
329-
Version.pp v msg
330+
Format.fprintf ppf "Value `%s` is deprecated since version %a. %s"
331+
s Version.pp v msg
330332

331333
let pp_deprecated_with_name ~opt ~val_ ppf {dmsg= msg; dversion= v} =
332334
Format.fprintf ppf
333-
"option `%s`: value `%s` is deprecated since version %a. %s" opt val_
334-
Version.pp v msg
335+
"option `%s`: value `%s` is deprecated since version %a. %s"
336+
opt val_ Version.pp v msg
335337

336338
let status_doc s ppf = function
337339
| `Valid -> ()
@@ -360,8 +362,8 @@ module Value_removed = struct
360362
| Some {name; version; msg} ->
361363
Format.kasprintf
362364
(fun s -> Error (`Msg s))
363-
"value `%s` has been removed in version %a.%s" name Version.pp
364-
version (maybe_empty msg)
365+
"value `%s` has been removed in version %a.%s"
366+
name Version.pp version (maybe_empty msg)
365367
| None -> Arg.conv_parser conv s
366368
in
367369
Arg.conv (parse, Arg.conv_printer conv)

lib/Translation_unit.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ module Error = struct
5959
Out_channel.write_all n ~data:next ;
6060
ignore
6161
(Stdlib.Sys.command
62-
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2" p n) ) ;
62+
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2"
63+
p n ) ) ;
6364
Stdlib.Sys.remove p ;
6465
Stdlib.Sys.remove n
6566

@@ -117,8 +118,8 @@ module Error = struct
117118
if debug then print_diff input_name ~prev ~next ;
118119
if iteration <= 1 then
119120
Format.fprintf fmt
120-
"%s: %S was not already formatted. ([max-iters = 1])\n%!" exe
121-
input_name
121+
"%s: %S was not already formatted. ([max-iters = 1])\n%!"
122+
exe input_name
122123
else (
123124
Format.fprintf fmt
124125
"%s: Cannot process %S.\n\
@@ -183,7 +184,8 @@ let check_margin (conf : Conf.t) ~filename ~fmted =
183184
List.iteri (String.split_lines fmted) ~f:(fun i line ->
184185
if String.length line > conf.fmt_opts.margin.v then
185186
Format.fprintf Format.err_formatter
186-
"Warning: %s:%i exceeds the margin\n%!" filename i )
187+
"Warning: %s:%i exceeds the margin\n%!"
188+
filename i )
187189

188190
let with_optional_box_debug ~box_debug k =
189191
if box_debug then Fmt.with_box_debug k else k

lib/box_debug.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ let break fs n o =
101101
if !debug then
102102
fprintf fs
103103
"<div class=\"break\">(%i,%i)<span class=\"tooltiptext\">break %i \
104-
%i</span></div>" n o n o
104+
%i</span></div>"
105+
n o n o
105106

106107
let pp_keyword fs s = fprintf fs "<span class=\"keyword\">%s</span>" s
107108

test/passing/tests/doc_comments-no-wrap.mli.ref

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ end
401401
#use "import.cinaps" ;;
402402

403403
List.iter all_fields ~f:(fun (name, type_) ->
404-
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
405-
name )
404+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\""
405+
name type_ name )
406406
]} *)
407407

408408
(** {[
409409
List.iter all_fields ~f:(fun (name, type_) ->
410-
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
411-
name )
410+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\""
411+
name type_ name )
412412
]} *)
413413

414414
(** {[

test/passing/tests/doc_comments.mli.ref

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,14 +401,14 @@ end
401401
#use "import.cinaps" ;;
402402

403403
List.iter all_fields ~f:(fun (name, type_) ->
404-
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
405-
name )
404+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\""
405+
name type_ name )
406406
]} *)
407407

408408
(** {[
409409
List.iter all_fields ~f:(fun (name, type_) ->
410-
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
411-
name )
410+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\""
411+
name type_ name )
412412
]} *)
413413

414414
(** {[

test/passing/tests/infix_arg_grouping.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ vbox 1
55
;;
66

77
user_error
8-
( "version mismatch: .ocamlformat requested " ^ value ^ " but version is "
9-
^ Version.version )
8+
( "version mismatch: .ocamlformat requested "
9+
^ value ^ " but version is " ^ Version.version )
1010
;;
1111

1212
hvbox 1

test/rpc/rpc_test.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ let start ?versions () =
7979
log
8080
"An error occured while initializing and configuring ocamlformat:\n\
8181
%s\n\
82-
%!" msg ;
82+
%!"
83+
msg ;
8384
`No_process )
8485

8586
let get_client ?versions () =

test/rpc/rpc_test_fail.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ let start () =
7777
log
7878
"An error occured while initializing and configuring ocamlformat:\n\
7979
%s\n\
80-
%!" msg ;
80+
%!"
81+
msg ;
8182
`No_process )
8283

8384
let get_client () =

0 commit comments

Comments
 (0)