Skip to content

Commit

Permalink
Fix trailing space in empty signature (#2443)
Browse files Browse the repository at this point in the history
* Make sure not to break out-of-margin emtpy-sig
  • Loading branch information
Julow authored Sep 19, 2023
1 parent 6734dfc commit 948e87a
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/Fmt_ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
18 changes: 18 additions & 0 deletions test/passing/dune.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/passing/tests/module_type.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(* Wrapping an empty sig *)
module Foo
(A : FOO)
(B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end
1 change: 1 addition & 0 deletions test/passing/tests/module_type.mli.err
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Warning: tests/module_type.mli:3 exceeds the margin
4 changes: 4 additions & 0 deletions test/passing/tests/module_type.mli.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(* Wrapping an empty sig *)
module Foo
(A : FOO)
(B : FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO) : sig end

0 comments on commit 948e87a

Please sign in to comment.