Skip to content

Commit

Permalink
Revert "Strings of length < 80 are trivial and simple"
Browse files Browse the repository at this point in the history
This reverts commit 55ebbe5.
  • Loading branch information
Julow committed Oct 3, 2023
1 parent 55ebbe5 commit f37470f
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 27 deletions.
10 changes: 8 additions & 2 deletions lib/Ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ module Exp = struct
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
(* Short strings are trivial. *)
| Pexp_constant {pconst_desc= Pconst_string (str, _, None); _} ->
String.length str < 80
String.length str < 30
| Pexp_constant _ | Pexp_field _ | Pexp_ident _ | Pexp_send _ -> true
| Pexp_construct (_, exp) -> Option.for_all exp ~f:is_trivial
| Pexp_prefix (_, e) -> is_trivial e
Expand Down Expand Up @@ -1474,7 +1474,13 @@ end = struct
let rec is_simple (c : Conf.t) width ({ast= exp; _} as xexp) =
let ctx = Exp exp in
match exp.pexp_desc with
| Pexp_constant _ -> Exp.is_trivial exp
(* String literals using the heavy syntax are not simple. *)
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
(* Only strings fitting on the line are simple. *)
| Pexp_constant {pconst_desc= Pconst_string (_, loc, None); _} ->
Exp.is_trivial exp
|| (Location.height loc = 1 && fit_margin c (width xexp))
| Pexp_constant _ -> true
| Pexp_field _ | Pexp_ident _ | Pexp_send _
|Pexp_construct (_, None)
|Pexp_variant (_, None) ->
Expand Down
18 changes: 10 additions & 8 deletions lib/Conf_decl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ let status_doc ppf = function

let generated_flag_doc ~allow_inline ~doc ~kind ~default ~status =
let default = if default then "set" else "unset" in
Format.asprintf "%s The flag is $(b,%s) by default.%s%a" doc default
Format.asprintf "%s The flag is $(b,%s) by default.%s%a"
doc default
(in_attributes allow_inline kind)
status_doc status

Expand All @@ -217,7 +218,8 @@ let generated_doc conv ~allow_inline ~doc ~kind ~default ~status =
let default =
if String.is_empty default_doc then "none" else default_doc
in
Format.asprintf "%s The default value is $(b,%s).%s%a" doc default
Format.asprintf "%s The default value is $(b,%s).%s%a"
doc default
(in_attributes allow_inline kind)
status_doc status

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

let pp_deprecated s ppf {dmsg= msg; dversion= v} =
Format.fprintf ppf "Value `%s` is deprecated since version %a. %s" s
Version.pp v msg
Format.fprintf ppf "Value `%s` is deprecated since version %a. %s"
s Version.pp v msg

let pp_deprecated_with_name ~opt ~val_ ppf {dmsg= msg; dversion= v} =
Format.fprintf ppf
"option `%s`: value `%s` is deprecated since version %a. %s" opt val_
Version.pp v msg
"option `%s`: value `%s` is deprecated since version %a. %s"
opt val_ Version.pp v msg

let status_doc s ppf = function
| `Valid -> ()
Expand Down Expand Up @@ -360,8 +362,8 @@ module Value_removed = struct
| Some {name; version; msg} ->
Format.kasprintf
(fun s -> Error (`Msg s))
"value `%s` has been removed in version %a.%s" name Version.pp
version (maybe_empty msg)
"value `%s` has been removed in version %a.%s"
name Version.pp version (maybe_empty msg)
| None -> Arg.conv_parser conv s
in
Arg.conv (parse, Arg.conv_printer conv)
Expand Down
10 changes: 6 additions & 4 deletions lib/Translation_unit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ module Error = struct
Out_channel.write_all n ~data:next ;
ignore
(Stdlib.Sys.command
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2" p n) ) ;
(Printf.sprintf "git diff --no-index -u %S %S | sed '1,4d' 1>&2"
p n ) ) ;
Stdlib.Sys.remove p ;
Stdlib.Sys.remove n

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

let with_optional_box_debug ~box_debug k =
if box_debug then Fmt.with_box_debug k else k
Expand Down
3 changes: 2 additions & 1 deletion lib/box_debug.ml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ let break fs n o =
if !debug then
fprintf fs
"<div class=\"break\">(%i,%i)<span class=\"tooltiptext\">break %i \
%i</span></div>" n o n o
%i</span></div>"
n o n o

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

Expand Down
8 changes: 4 additions & 4 deletions test/passing/tests/doc_comments-no-wrap.mli.ref
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ end
#use "import.cinaps" ;;

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

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

(** {[
Expand Down
8 changes: 4 additions & 4 deletions test/passing/tests/doc_comments.mli.ref
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,14 @@ end
#use "import.cinaps" ;;

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

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

(** {[
Expand Down
4 changes: 2 additions & 2 deletions test/passing/tests/infix_arg_grouping.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ vbox 1
;;

user_error
( "version mismatch: .ocamlformat requested " ^ value ^ " but version is "
^ Version.version )
( "version mismatch: .ocamlformat requested "
^ value ^ " but version is " ^ Version.version )
;;

hvbox 1
Expand Down
3 changes: 2 additions & 1 deletion test/rpc/rpc_test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ let start ?versions () =
log
"An error occured while initializing and configuring ocamlformat:\n\
%s\n\
%!" msg ;
%!"
msg ;
`No_process )

let get_client ?versions () =
Expand Down
3 changes: 2 additions & 1 deletion test/rpc/rpc_test_fail.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ let start () =
log
"An error occured while initializing and configuring ocamlformat:\n\
%s\n\
%!" msg ;
%!"
msg ;
`No_process )

let get_client () =
Expand Down

0 comments on commit f37470f

Please sign in to comment.