From 526d3c25f86b308c75cb52a20fc3f0f1891cda1a Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 18 Sep 2023 16:51:00 +0200 Subject: [PATCH 1/4] Add failing test --- test/passing/dune.inc | 18 ++++++++++++++++++ test/passing/tests/module_type.mli | 4 ++++ test/passing/tests/module_type.mli.err | 1 + test/passing/tests/module_type.mli.ref | 5 +++++ 4 files changed, 28 insertions(+) create mode 100644 test/passing/tests/module_type.mli create mode 100644 test/passing/tests/module_type.mli.err create mode 100644 test/passing/tests/module_type.mli.ref diff --git a/test/passing/dune.inc b/test/passing/dune.inc index 478e2cf8bb..18598598e6 100644 --- a/test/passing/dune.inc +++ b/test/passing/dune.inc @@ -3897,6 +3897,24 @@ (package ocamlformat) (action (diff tests/module_type.ml.err module_type.ml.stderr))) +(rule + (deps tests/.ocamlformat ) + (package ocamlformat) + (action + (with-stdout-to module_type.mli.stdout + (with-stderr-to module_type.mli.stderr + (run %{bin:ocamlformat} --margin-check %{dep:tests/module_type.mli}))))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/module_type.mli.ref module_type.mli.stdout))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/module_type.mli.err module_type.mli.stderr))) + (rule (deps tests/.ocamlformat ) (package ocamlformat) diff --git a/test/passing/tests/module_type.mli b/test/passing/tests/module_type.mli new file mode 100644 index 0000000000..30cf318687 --- /dev/null +++ b/test/passing/tests/module_type.mli @@ -0,0 +1,4 @@ +(* Wrapping an empty sig *) +module Foo + (A : FOO) + (B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end diff --git a/test/passing/tests/module_type.mli.err b/test/passing/tests/module_type.mli.err new file mode 100644 index 0000000000..fdf08943fd --- /dev/null +++ b/test/passing/tests/module_type.mli.err @@ -0,0 +1 @@ +Warning: tests/module_type.mli:3 exceeds the margin diff --git a/test/passing/tests/module_type.mli.ref b/test/passing/tests/module_type.mli.ref new file mode 100644 index 0000000000..546d8c45b6 --- /dev/null +++ b/test/passing/tests/module_type.mli.ref @@ -0,0 +1,5 @@ +(* Wrapping an empty sig *) +module Foo + (A : FOO) + (B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig +end From 15b187747aea26c78424725f1d44c991e4697eec Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 18 Sep 2023 16:51:27 +0200 Subject: [PATCH 2/4] Make sure not to break out-of-margin emtpy-sig --- lib/Fmt_ast.ml | 2 +- test/passing/tests/module_type.mli.ref | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 36d43f5d88..b7cd4f8fef 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -3463,7 +3463,7 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) = { opn= None ; pro= Some (before $ str "sig" $ fmt_if empty " ") ; psp= fmt_if (not empty) "@;<1000 2>" - ; bdy= within $ fmt_signature c ctx s + ; bdy= within $ (if empty then noop else fmt_signature c ctx s) ; cls= noop ; esp= fmt_if (not empty) "@;<1000 0>" ; epi= diff --git a/test/passing/tests/module_type.mli.ref b/test/passing/tests/module_type.mli.ref index 546d8c45b6..30cf318687 100644 --- a/test/passing/tests/module_type.mli.ref +++ b/test/passing/tests/module_type.mli.ref @@ -1,5 +1,4 @@ (* Wrapping an empty sig *) module Foo (A : FOO) - (B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig -end + (B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end From ef5a9d9392b3a7f32daeda3b3b584baef7b05c61 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 18 Sep 2023 17:54:58 +0200 Subject: [PATCH 3/4] Update CHANGES --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index af7d19de1b..2594d2cb1c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,12 @@ Items marked with an asterisk (\*) are changes that are likely to format existing code differently from the previous release when using the default profile. This started with version 0.26.0. +## unreleased + +### Fixed + +- Remove trailing space inside a wrapping empty signature (#2443, @Julow) + ## 0.26.1 (2023-09-15) ### Changed From 62da6a155a5c87cddb057ffe12208112507847a2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 19 Sep 2023 11:16:06 +0200 Subject: [PATCH 4/4] fmt --- lib/Fmt_ast.ml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index b7cd4f8fef..b96dff413b 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -3463,7 +3463,7 @@ and fmt_module_type c ?(rec_ = false) ({ast= mty; _} as xmty) = { opn= None ; pro= Some (before $ str "sig" $ fmt_if empty " ") ; psp= fmt_if (not empty) "@;<1000 2>" - ; bdy= within $ (if empty then noop else fmt_signature c ctx s) + ; bdy= (within $ if empty then noop else fmt_signature c ctx s) ; cls= noop ; esp= fmt_if (not empty) "@;<1000 0>" ; epi=