Skip to content

Commit 09513e0

Browse files
committed
Improve a bit the break rules
1 parent 9fa3287 commit 09513e0

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

lib/Ast.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,9 +1521,7 @@ end = struct
15211521
(* String literals using the heavy syntax are not simple. *)
15221522
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> false
15231523
(* 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))
1524+
| Pexp_constant {pconst_desc= Pconst_string (_, _, None); _} -> true
15271525
| Pexp_constant _ -> true
15281526
| Pexp_field _ | Pexp_ident _ | Pexp_send _
15291527
|Pexp_construct (_, None)

lib/Cmts.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ let rec place t loc_tree ?prev_loc ?deep_loc locs cmts =
303303
(** Relocate comments, for Ast transformations such as sugaring. *)
304304
let relocate (t : t) ~src ~before ~after =
305305
if t.debug then
306-
Format.eprintf "relocate %a to %a and %a@\n%!" Location.fmt src
307-
Location.fmt before Location.fmt after ;
306+
Format.eprintf "relocate %a to %a and %a@\n%!"
307+
Location.fmt src Location.fmt before Location.fmt after ;
308308
let merge_and_sort x y =
309309
List.rev_append x y
310310
|> List.sort ~compare:(Comparable.lift Location.compare_start ~f:Cmt.loc)

lib/Conf_decl.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ let rec pp_from fs = function
187187
| `Profile (s, p) -> Format.fprintf fs " (profile %s%a)" s pp_from_src p
188188
| `Updated (x, None) -> pp_from_src fs x
189189
| `Updated (x, Some r) ->
190-
Format.fprintf fs "%a -- Warning (redundant): %a" pp_from_src x pp_from
191-
r
190+
Format.fprintf fs "%a -- Warning (redundant): %a"
191+
pp_from_src x pp_from r
192192

193193
let loc_udapted_from = function
194194
| `Commandline -> Location.in_file "<command-line>"

lib/Fmt_ast.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,13 +1520,14 @@ and fmt_args_grouped ?epi:(global_epi = noop) c ctx args =
15201520
let xexp = sub_exp ~ctx x in
15211521
is_simple c.conf (expression_width c) xexp
15221522
in
1523-
let should_break_after x = not (is_simple x)
1524-
and should_break_before ((_lbl, exp) as y) =
1523+
let should_break_before x = not (is_simple x)
1524+
and should_break_after ((_lbl, exp) as y) =
15251525
match exp.pexp_desc with
15261526
(* Heavy syntax strings are not grouped. *)
15271527
| Pexp_constant {pconst_desc= Pconst_string (_, _, Some _); _} -> true
15281528
(* Non-simple strings are grouped but end a group. *)
1529-
| Pexp_constant {pconst_desc= Pconst_string (_, _, None); _} -> false
1529+
| Pexp_constant {pconst_desc= Pconst_string (str, _, None); _} ->
1530+
String.length str * 3 > c.conf.fmt_opts.margin.v
15301531
| _ -> not (is_simple y)
15311532
in
15321533
let break x y =

test/passing/tests/infix_arg_grouping.ml.ref

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

0 commit comments

Comments
 (0)