Skip to content

Commit 8deba41

Browse files
Julowgpetiot
authored andcommitted
Strings of length < 80 are trivial and simple
1 parent 40a6b38 commit 8deba41

File tree

9 files changed

+27
-40
lines changed

9 files changed

+27
-40
lines changed

lib/Ast.ml

Lines changed: 2 additions & 8 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 < 30
155+
String.length str < 80
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,13 +1518,7 @@ 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-
(* 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
1521+
| Pexp_constant _ -> Exp.is_trivial exp
15281522
| Pexp_field _ | Pexp_ident _ | Pexp_send _
15291523
|Pexp_construct (_, None)
15301524
|Pexp_variant (_, None) ->

lib/Conf_decl.ml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ 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"
212-
doc default
211+
Format.asprintf "%s The flag is $(b,%s) by default.%s%a" doc default
213212
(in_attributes allow_inline kind)
214213
status_doc status
215214

@@ -218,8 +217,7 @@ let generated_doc conv ~allow_inline ~doc ~kind ~default ~status =
218217
let default =
219218
if String.is_empty default_doc then "none" else default_doc
220219
in
221-
Format.asprintf "%s The default value is $(b,%s).%s%a"
222-
doc default
220+
Format.asprintf "%s The default value is $(b,%s).%s%a" doc default
223221
(in_attributes allow_inline kind)
224222
status_doc status
225223

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

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

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

338336
let status_doc s ppf = function
339337
| `Valid -> ()
@@ -362,8 +360,8 @@ module Value_removed = struct
362360
| Some {name; version; msg} ->
363361
Format.kasprintf
364362
(fun s -> Error (`Msg s))
365-
"value `%s` has been removed in version %a.%s"
366-
name Version.pp version (maybe_empty msg)
363+
"value `%s` has been removed in version %a.%s" name Version.pp
364+
version (maybe_empty msg)
367365
| None -> Arg.conv_parser conv s
368366
in
369367
Arg.conv (parse, Arg.conv_printer conv)

lib/Translation_unit.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ 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"
63-
p n ) ) ;
62+
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2" p n) ) ;
6463
Stdlib.Sys.remove p ;
6564
Stdlib.Sys.remove n
6665

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

190188
let with_optional_box_debug ~box_debug k =
191189
if box_debug then Fmt.with_box_debug k else k

lib/box_debug.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ 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>"
105-
n o n o
104+
%i</span></div>" n o n o
106105

107106
let pp_keyword fs s = fprintf fs "<span class=\"keyword\">%s</span>" s
108107

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\""
405-
name type_ name )
404+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
405+
name )
406406
]} *)
407407

408408
(** {[
409409
List.iter all_fields ~f:(fun (name, type_) ->
410-
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\""
411-
name type_ name )
410+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
411+
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\""
405-
name type_ name )
404+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
405+
name )
406406
]} *)
407407

408408
(** {[
409409
List.iter all_fields ~f:(fun (name, type_) ->
410-
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\""
411-
name type_ name )
410+
printf "\nexternal get_%s\n: unit -> %s = \"get_%s\"" name type_
411+
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 "
9-
^ value ^ " but version is " ^ Version.version )
8+
( "version mismatch: .ocamlformat requested " ^ value ^ " but version is "
9+
^ Version.version )
1010
;;
1111

1212
hvbox 1

test/rpc/rpc_test.ml

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

8685
let get_client ?versions () =

test/rpc/rpc_test_fail.ml

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

8483
let get_client () =

0 commit comments

Comments
 (0)