Skip to content

Commit 55ebbe5

Browse files
committed
Strings of length < 80 are trivial and simple
1 parent 94e4c3c commit 55ebbe5

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
@@ -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 < 30
149+
String.length str < 80
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,13 +1474,7 @@ 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-
(* 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
1477+
| Pexp_constant _ -> Exp.is_trivial exp
14841478
| Pexp_field _ | Pexp_ident _ | Pexp_send _
14851479
|Pexp_construct (_, None)
14861480
|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
@@ -55,8 +55,7 @@ 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"
59-
p n ) ) ;
58+
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2" p n) ) ;
6059
Stdlib.Sys.remove p ;
6160
Stdlib.Sys.remove n
6261

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

186184
let with_optional_box_debug ~box_debug k =
187185
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)