Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent break after string constant argument #2453

Merged
merged 4 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ profile. This started with version 0.26.0.

- Remove trailing space inside a wrapping empty signature (#2443, @Julow)
- Fix extension-point spacing in structures (#2450, @Julow)
- \* Consistent break after string constant argument (#2453, @Julow)

## 0.26.1 (2023-09-15)

Expand Down
12 changes: 6 additions & 6 deletions lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1467,15 +1467,15 @@ and fmt_args_grouped ?epi:(global_epi = noop) c ctx args =
| Pexp_fun _ | Pexp_function _ -> Some false
| _ -> None
in
let epi =
match (lbl, last) with
| _, true -> None
| Nolabel, _ -> Some (fits_breaks "" ~hint:(1000, -1) "")
| _ -> Some (fits_breaks "" ~hint:(1000, -3) "")
let break_after =
match (ast.pexp_desc, c.conf.fmt_opts.break_string_literals.v) with
| Pexp_constant _, `Auto when not last ->
fits_breaks "" ~hint:(1000, -2) ""
| _ -> noop
in
hovbox
(Params.Indent.fun_args_group c.conf ~lbl ast)
(fmt_label_arg c ?box ?epi (lbl, xarg))
(fmt_label_arg c ?box (lbl, xarg) $ break_after)
gpetiot marked this conversation as resolved.
Show resolved Hide resolved
$ fmt_if_k (not last) (break_unless_newline 1 0)
in
let fmt_args ~first ~last args =
Expand Down
2 changes: 2 additions & 0 deletions test/passing/tests/break_string_literals-never.ml.err
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ Warning: tests/break_string_literals.ml:7 exceeds the margin
Warning: tests/break_string_literals.ml:11 exceeds the margin
Warning: tests/break_string_literals.ml:48 exceeds the margin
Warning: tests/break_string_literals.ml:51 exceeds the margin
Warning: tests/break_string_literals.ml:63 exceeds the margin
Warning: tests/break_string_literals.ml:68 exceeds the margin
10 changes: 10 additions & 0 deletions test/passing/tests/break_string_literals-never.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ let _ = "abc@,def\n\n ghi"
let _ = "abc@,def\n\n"

let _ = "abc@,def@\n\n"

let _ =
Pp.textf
"Failed to parse environment variable: %s=%s\nPermitted values: if-exists always never\nDefault: %s"
var v (to_string default)

let _ =
Pp.textf
"Failed to parse environment variable: %s=%s Permitted values: if-exists always never Default: %s"
var v (to_string default)
14 changes: 14 additions & 0 deletions test/passing/tests/break_string_literals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,17 @@ let _ = "abc@,def\n\nghi"
let _ = "abc@,def\n\n ghi"
let _ = "abc@,def\n\n"
let _ = "abc@,def@\n\n"

let _ =
Pp.textf
"Failed to parse environment variable: %s=%s\n\
Permitted values: if-exists always never\n\
Default: %s"
var v (to_string default)

let _ =
Pp.textf
"Failed to parse environment variable: %s=%s \
Permitted values: if-exists always never \
Default: %s"
var v (to_string default)
13 changes: 13 additions & 0 deletions test/passing/tests/break_string_literals.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,16 @@ let _ = "abc@,def\n\n ghi"
let _ = "abc@,def\n\n"

let _ = "abc@,def@\n\n"

let _ =
Pp.textf
"Failed to parse environment variable: %s=%s\n\
Permitted values: if-exists always never\n\
Default: %s"
var v (to_string default)

let _ =
Pp.textf
"Failed to parse environment variable: %s=%s Permitted values: \
if-exists always never Default: %s"
var v (to_string default)
3 changes: 2 additions & 1 deletion test/passing/tests/js_args.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ let () =
messages :=
Message_store.create (Session_id.of_string "")
(* Tuareg indents these lines too far to the left. *)
"herd-retransmitter" Message_store.Message_size.Byte
"herd-retransmitter"
Message_store.Message_size.Byte

let () =
raise
Expand Down