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 diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 36d43f5d88..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 $ 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/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..30cf318687 --- /dev/null +++ b/test/passing/tests/module_type.mli.ref @@ -0,0 +1,4 @@ +(* Wrapping an empty sig *) +module Foo + (A : FOO) + (B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end