Skip to content

Commit f37470f

Browse files
committed
Revert "Strings of length < 80 are trivial and simple"
This reverts commit 55ebbe5.
1 parent 55ebbe5 commit f37470f

File tree

9 files changed

+40
-27
lines changed

9 files changed

+40
-27
lines changed

lib/Ast.ml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ module Exp = struct
146146
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
147147
(* Short strings are trivial. *)
148148
| Pexp_constant {pconst_desc= Pconst_string (str, _, None); _} ->
149-
String.length str < 80
149+
String.length str < 30
150150
| Pexp_constant _ | Pexp_field _ | Pexp_ident _ | Pexp_send _ -> true
151151
| Pexp_construct (_, exp) -> Option.for_all exp ~f:is_trivial
152152
| Pexp_prefix (_, e) -> is_trivial e
@@ -1474,7 +1474,13 @@ end = struct
14741474
let rec is_simple (c : Conf.t) width ({ast= exp; _} as xexp) =
14751475
let ctx = Exp exp in
14761476
match exp.pexp_desc with
1477-
| Pexp_constant _ -> Exp.is_trivial exp
1477+
(* String literals using the heavy syntax are not simple. *)
1478+
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
1479+
(* Only strings fitting on the line are simple. *)
1480+
| Pexp_constant {pconst_desc= Pconst_string (_, loc, None); _} ->
1481+
Exp.is_trivial exp
1482+
|| (Location.height loc = 1 && fit_margin c (width xexp))
1483+
| Pexp_constant _ -> true
14781484
| Pexp_field _ | Pexp_ident _ | Pexp_send _
14791485
|Pexp_construct (_, None)
14801486
|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
@@ -55,7 +55,8 @@ module Error = struct
5555
Out_channel.write_all n ~data:next ;
5656
ignore
5757
(Stdlib.Sys.command
58-
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2" p n) ) ;
58+
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2"
59+
p n ) ) ;
5960
Stdlib.Sys.remove p ;
6061
Stdlib.Sys.remove n
6162

@@ -113,8 +114,8 @@ module Error = struct
113114
if debug then print_diff input_name ~prev ~next ;
114115
if iteration <= 1 then
115116
Format.fprintf fmt
116-
"%s: %S was not already formatted. ([max-iters = 1])\n%!" exe
117-
input_name
117+
"%s: %S was not already formatted. ([max-iters = 1])\n%!"
118+
exe input_name
118119
else (
119120
Format.fprintf fmt
120121
"%s: Cannot process %S.\n\
@@ -179,7 +180,8 @@ let check_margin (conf : Conf.t) ~filename ~fmted =
179180
List.iteri (String.split_lines fmted) ~f:(fun i line ->
180181
if String.length line > conf.fmt_opts.margin.v then
181182
Format.fprintf Format.err_formatter
182-
"Warning: %s:%i exceeds the margin\n%!" filename i )
183+
"Warning: %s:%i exceeds the margin\n%!"
184+
filename i )
183185

184186
let with_optional_box_debug ~box_debug k =
185187
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)