Skip to content

Commit 948e87a

Browse files
authored
Fix trailing space in empty signature (#2443)
* Make sure not to break out-of-margin emtpy-sig
1 parent 6734dfc commit 948e87a

File tree

6 files changed

+34
-1
lines changed

6 files changed

+34
-1
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Items marked with an asterisk (\*) are changes that are likely to format
44
existing code differently from the previous release when using the default
55
profile. This started with version 0.26.0.
66

7+
## unreleased
8+
9+
### Fixed
10+
11+
- Remove trailing space inside a wrapping empty signature (#2443, @Julow)
12+
713
## 0.26.1 (2023-09-15)
814

915
### Changed

lib/Fmt_ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3463,7 +3463,7 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) =
34633463
{ opn= None
34643464
; pro= Some (before $ str "sig" $ fmt_if empty " ")
34653465
; psp= fmt_if (not empty) "@;<1000 2>"
3466-
; bdy= within $ fmt_signature c ctx s
3466+
; bdy= (within $ if empty then noop else fmt_signature c ctx s)
34673467
; cls= noop
34683468
; esp= fmt_if (not empty) "@;<1000 0>"
34693469
; epi=

test/passing/dune.inc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3897,6 +3897,24 @@
38973897
(package ocamlformat)
38983898
(action (diff tests/module_type.ml.err module_type.ml.stderr)))
38993899

3900+
(rule
3901+
(deps tests/.ocamlformat )
3902+
(package ocamlformat)
3903+
(action
3904+
(with-stdout-to module_type.mli.stdout
3905+
(with-stderr-to module_type.mli.stderr
3906+
(run %{bin:ocamlformat} --margin-check %{dep:tests/module_type.mli})))))
3907+
3908+
(rule
3909+
(alias runtest)
3910+
(package ocamlformat)
3911+
(action (diff tests/module_type.mli.ref module_type.mli.stdout)))
3912+
3913+
(rule
3914+
(alias runtest)
3915+
(package ocamlformat)
3916+
(action (diff tests/module_type.mli.err module_type.mli.stderr)))
3917+
39003918
(rule
39013919
(deps tests/.ocamlformat )
39023920
(package ocamlformat)

test/passing/tests/module_type.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(* Wrapping an empty sig *)
2+
module Foo
3+
(A : FOO)
4+
(B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Warning: tests/module_type.mli:3 exceeds the margin
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(* Wrapping an empty sig *)
2+
module Foo
3+
(A : FOO)
4+
(B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end

0 commit comments

Comments
 (0)