diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index 7eac0d0871..69a04c1db3 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -783,7 +783,7 @@ and fmt_modals ?(pro = fmt "@ ") c ~ats modals = let fmt_ats = match ats with `Zero -> str "" | `One -> str "@ " | `Two -> str "@@ " in - let fmt_modal {txt; loc} = Cmts.fmt c loc (str txt) in + let fmt_modal {txt; loc} = Cmts.fmt c loc (str txt) ~eol:(fmt "@ ") in let fmt_mode {txt= Mode mode; loc} = fmt_modal {txt= mode; loc} in let fmt_modality {txt= Modality modality; loc} = fmt_modal {txt= modality; loc} @@ -5302,7 +5302,7 @@ let fmt_file (type a) ~ctx ~fmt_code ~debug (fragment : a Extended_ast.t) let c = {source; cmts; conf; debug; fmt_code} in match (fragment, itms) with | Signature, {psg_items= []; psg_modalities; _} -> - fmt_modals c ~ats:`Two (Modalities psg_modalities) + fmt_modals ~pro:noop c ~ats:`Two (Modalities psg_modalities) $ Cmts.fmt_after ~pro:noop c Location.none | Structure, [] | Use_file, [] -> Cmts.fmt_after ~pro:noop c Location.none | Structure, l -> Chunk.split_and_fmt Structure c ctx l diff --git a/test/passing/dune.inc b/test/passing/dune.inc index 3fbbe502f8..3b7d925dd4 100644 --- a/test/passing/dune.inc +++ b/test/passing/dune.inc @@ -8563,6 +8563,80 @@ (package ocamlformat) (action (diff tests/mod_type_subst.ml.js-err mod_type_subst.ml.js-stderr))) +(rule + (deps tests/.ocamlformat ) + (package ocamlformat) + (action + (with-stdout-to modality_comments_failure.mli.stdout + (with-stderr-to modality_comments_failure.mli.stderr + (with-accepted-exit-codes 1 + (run %{bin:ocamlformat} --margin-check %{dep:tests/modality_comments_failure.mli})))))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_failure.mli.ref modality_comments_failure.mli.stdout))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_failure.mli.err modality_comments_failure.mli.stderr))) + +(rule + (deps tests/.ocamlformat ) + (package ocamlformat) + (action + (with-stdout-to modality_comments_failure.mli.js-stdout + (with-stderr-to modality_comments_failure.mli.js-stderr + (with-accepted-exit-codes 1 + (run %{bin:ocamlformat} --profile=janestreet --enable-outside-detected-project --disable-conf-files %{dep:tests/modality_comments_failure.mli})))))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_failure.mli.js-ref modality_comments_failure.mli.js-stdout))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_failure.mli.js-err modality_comments_failure.mli.js-stderr))) + +(rule + (deps tests/.ocamlformat ) + (package ocamlformat) + (action + (with-stdout-to modality_comments_regression.mli.stdout + (with-stderr-to modality_comments_regression.mli.stderr + (run %{bin:ocamlformat} --margin-check %{dep:tests/modality_comments_regression.mli}))))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_regression.mli.ref modality_comments_regression.mli.stdout))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_regression.mli.err modality_comments_regression.mli.stderr))) + +(rule + (deps tests/.ocamlformat ) + (package ocamlformat) + (action + (with-stdout-to modality_comments_regression.mli.js-stdout + (with-stderr-to modality_comments_regression.mli.js-stderr + (run %{bin:ocamlformat} --profile=janestreet --enable-outside-detected-project --disable-conf-files %{dep:tests/modality_comments_regression.mli}))))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_regression.mli.js-ref modality_comments_regression.mli.js-stdout))) + +(rule + (alias runtest) + (package ocamlformat) + (action (diff tests/modality_comments_regression.mli.js-err modality_comments_regression.mli.js-stderr))) + (rule (deps tests/.ocamlformat ) (package ocamlformat) diff --git a/test/passing/tests/default_modalities2.mli.js-ref b/test/passing/tests/default_modalities2.mli.js-ref index f4da7957cc..56160f153e 100644 --- a/test/passing/tests/default_modalities2.mli.js-ref +++ b/test/passing/tests/default_modalities2.mli.js-ref @@ -1,7 +1,6 @@ @@ (* a *) - (* b *) - moda1 (* c *) moda2 + (* b *) moda1 (* c *) moda2 (* d *) val x : int diff --git a/test/passing/tests/default_modalities2.mli.ref b/test/passing/tests/default_modalities2.mli.ref index f4da7957cc..56160f153e 100644 --- a/test/passing/tests/default_modalities2.mli.ref +++ b/test/passing/tests/default_modalities2.mli.ref @@ -1,7 +1,6 @@ @@ (* a *) - (* b *) - moda1 (* c *) moda2 + (* b *) moda1 (* c *) moda2 (* d *) val x : int diff --git a/test/passing/tests/layout_abbreviation-erased.ml.js-ref b/test/passing/tests/layout_abbreviation-erased.ml.js-ref index 662ee36e92..f099198d4f 100644 --- a/test/passing/tests/layout_abbreviation-erased.ml.js-ref +++ b/test/passing/tests/layout_abbreviation-erased.ml.js-ref @@ -815,7 +815,11 @@ kind_abbrev_ k = (* 375 *) mod (* 382 *) - m (* 381 *) mmmmmmmmmmmmmmmmmmmmm (* 383 *) mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm + m + (* 381 *) + mmmmmmmmmmmmmmmmmmmmm + (* 383 *) + mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm (* 374 *) kind_abbrev_ k = @@ -1912,8 +1916,8 @@ module type S = sig _ (* 1192 *) (* 1191 *) - mod (* 1194 *) - mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm + mod + (* 1194 *) mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm (* 1190 *) (* 1189 *) with (* 1196 *) tt (* 1188 *)) diff --git a/test/passing/tests/layout_abbreviation.ml.err b/test/passing/tests/layout_abbreviation.ml.err index a32acaee89..72d82581af 100644 --- a/test/passing/tests/layout_abbreviation.ml.err +++ b/test/passing/tests/layout_abbreviation.ml.err @@ -1,12 +1,12 @@ Warning: tests/layout_abbreviation.ml:2044 exceeds the margin Warning: tests/layout_abbreviation.ml:2058 exceeds the margin -Warning: tests/layout_abbreviation.ml:2090 exceeds the margin -Warning: tests/layout_abbreviation.ml:2105 exceeds the margin -Warning: tests/layout_abbreviation.ml:2122 exceeds the margin -Warning: tests/layout_abbreviation.ml:2139 exceeds the margin -Warning: tests/layout_abbreviation.ml:2141 exceeds the margin -Warning: tests/layout_abbreviation.ml:2187 exceeds the margin -Warning: tests/layout_abbreviation.ml:2194 exceeds the margin -Warning: tests/layout_abbreviation.ml:2266 exceeds the margin -Warning: tests/layout_abbreviation.ml:2268 exceeds the margin -Warning: tests/layout_abbreviation.ml:2277 exceeds the margin +Warning: tests/layout_abbreviation.ml:2089 exceeds the margin +Warning: tests/layout_abbreviation.ml:2104 exceeds the margin +Warning: tests/layout_abbreviation.ml:2121 exceeds the margin +Warning: tests/layout_abbreviation.ml:2138 exceeds the margin +Warning: tests/layout_abbreviation.ml:2140 exceeds the margin +Warning: tests/layout_abbreviation.ml:2186 exceeds the margin +Warning: tests/layout_abbreviation.ml:2193 exceeds the margin +Warning: tests/layout_abbreviation.ml:2265 exceeds the margin +Warning: tests/layout_abbreviation.ml:2267 exceeds the margin +Warning: tests/layout_abbreviation.ml:2276 exceeds the margin diff --git a/test/passing/tests/layout_abbreviation.ml.js-ref b/test/passing/tests/layout_abbreviation.ml.js-ref index 662ee36e92..f099198d4f 100644 --- a/test/passing/tests/layout_abbreviation.ml.js-ref +++ b/test/passing/tests/layout_abbreviation.ml.js-ref @@ -815,7 +815,11 @@ kind_abbrev_ k = (* 375 *) mod (* 382 *) - m (* 381 *) mmmmmmmmmmmmmmmmmmmmm (* 383 *) mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm + m + (* 381 *) + mmmmmmmmmmmmmmmmmmmmm + (* 383 *) + mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm (* 374 *) kind_abbrev_ k = @@ -1912,8 +1916,8 @@ module type S = sig _ (* 1192 *) (* 1191 *) - mod (* 1194 *) - mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm + mod + (* 1194 *) mmmmmmmmmmmmm (* 1195 *) mmmmmmmmmmmmm (* 1190 *) (* 1189 *) with (* 1196 *) tt (* 1188 *)) diff --git a/test/passing/tests/layout_abbreviation.ml.ref b/test/passing/tests/layout_abbreviation.ml.ref index c95201d25d..ae279dadd6 100644 --- a/test/passing/tests/layout_abbreviation.ml.ref +++ b/test/passing/tests/layout_abbreviation.ml.ref @@ -2066,8 +2066,7 @@ module type S = sig tttttttttttttttttttt (* 1091 *) (* 1079 *))) - mod (* 1096 *) - mmmmmmmmmmmmmm + mod (* 1096 *) mmmmmmmmmmmmmm (* 1078 *) (* 1077 *) with (* 1097 *) diff --git a/test/passing/tests/layout_annotation_mod.ml.js-ref b/test/passing/tests/layout_annotation_mod.ml.js-ref index 8d70bbfe77..15ebcd0a13 100644 --- a/test/passing/tests/layout_annotation_mod.ml.js-ref +++ b/test/passing/tests/layout_annotation_mod.ml.js-ref @@ -240,8 +240,7 @@ type a = ((* comment 1 *) 'k (* comment 2 *) : (* comment 3 *) - immediate64 (* comment 4 *) mod (* comment 5 *) - mode (* comment 6 *)) + immediate64 (* comment 4 *) mod (* comment 5 *) mode (* comment 6 *)) (* comment 7 *) let f (type a : immediate mod mode) x = x diff --git a/test/passing/tests/layout_annotation_mod.ml.ref b/test/passing/tests/layout_annotation_mod.ml.ref index 836e461b9b..ee669bc9f2 100644 --- a/test/passing/tests/layout_annotation_mod.ml.ref +++ b/test/passing/tests/layout_annotation_mod.ml.ref @@ -310,8 +310,7 @@ type a = (* comment 3 *) immediate64 (* comment 4 *) - mod (* comment 5 *) - mode + mod (* comment 5 *) mode (* comment 6 *)) (* comment 7 *) diff --git a/test/passing/tests/modality_comments_failure.mli b/test/passing/tests/modality_comments_failure.mli new file mode 100644 index 0000000000..e6b7dd02e8 --- /dev/null +++ b/test/passing/tests/modality_comments_failure.mli @@ -0,0 +1,5 @@ +(** a *) + +(** b *) + +@@ a b c diff --git a/test/passing/tests/modality_comments_failure.mli.err b/test/passing/tests/modality_comments_failure.mli.err new file mode 100644 index 0000000000..62640188a9 --- /dev/null +++ b/test/passing/tests/modality_comments_failure.mli.err @@ -0,0 +1,6 @@ +ocamlformat: ignoring "tests/modality_comments_failure.mli" (misplaced documentation comments - warning 50) +File "tests/modality_comments_failure.mli", line 3, characters 0-8: +3 | (** b *) + ^^^^^^^^ +Warning 50 [unexpected-docstring]: unattached documentation comment (ignored) +Hint: (Warning 50) This file contains a documentation comment (** ... *) that the OCaml compiler does not know how to attach to the AST. OCamlformat does not support these cases. You can find more information at: https://github.com/ocaml-ppx/ocamlformat#overview. If you'd like to disable this check and let ocamlformat make a choice (though it might not be consistent with the ocaml compilers and odoc), you can set the --no-comment-check option. diff --git a/test/passing/tests/modality_comments_failure.mli.js-err b/test/passing/tests/modality_comments_failure.mli.js-err new file mode 100644 index 0000000000..62640188a9 --- /dev/null +++ b/test/passing/tests/modality_comments_failure.mli.js-err @@ -0,0 +1,6 @@ +ocamlformat: ignoring "tests/modality_comments_failure.mli" (misplaced documentation comments - warning 50) +File "tests/modality_comments_failure.mli", line 3, characters 0-8: +3 | (** b *) + ^^^^^^^^ +Warning 50 [unexpected-docstring]: unattached documentation comment (ignored) +Hint: (Warning 50) This file contains a documentation comment (** ... *) that the OCaml compiler does not know how to attach to the AST. OCamlformat does not support these cases. You can find more information at: https://github.com/ocaml-ppx/ocamlformat#overview. If you'd like to disable this check and let ocamlformat make a choice (though it might not be consistent with the ocaml compilers and odoc), you can set the --no-comment-check option. diff --git a/test/passing/tests/modality_comments_failure.mli.js-ref b/test/passing/tests/modality_comments_failure.mli.js-ref new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/passing/tests/modality_comments_failure.mli.ref b/test/passing/tests/modality_comments_failure.mli.ref new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/passing/tests/modality_comments_failure.mli.should-fail b/test/passing/tests/modality_comments_failure.mli.should-fail new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/passing/tests/modality_comments_regression.mli b/test/passing/tests/modality_comments_regression.mli new file mode 100644 index 0000000000..314fa8c49f --- /dev/null +++ b/test/passing/tests/modality_comments_regression.mli @@ -0,0 +1,3 @@ +@@ mmmmmmmmm m (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) mmmmmmmmmm mmmmmmmmmm mmmmm mm m + +val command : Command.t @@ mmmmmmmm m mmmmm mmm mmmmmmmm (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) mmmmmmm mmmmm mmmmmm diff --git a/test/passing/tests/modality_comments_regression.mli.js-ref b/test/passing/tests/modality_comments_regression.mli.js-ref new file mode 100644 index 0000000000..b1946c89f3 --- /dev/null +++ b/test/passing/tests/modality_comments_regression.mli.js-ref @@ -0,0 +1,20 @@ +@@ m + m + mm + mmmmm + mmmmmmmmm + (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) + mmmmmmmmmm + mmmmmmmmmm + +val command + : Command.t + @@ m + mmm + mmmmm + mmmmm + mmmmmm + (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) + mmmmmmm + mmmmmmmm + mmmmmmmm diff --git a/test/passing/tests/modality_comments_regression.mli.ref b/test/passing/tests/modality_comments_regression.mli.ref new file mode 100644 index 0000000000..7e999382ae --- /dev/null +++ b/test/passing/tests/modality_comments_regression.mli.ref @@ -0,0 +1,19 @@ +@@ m + m + mm + mmmmm + mmmmmmmmm + (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) + mmmmmmmmmm + mmmmmmmmmm + +val command : Command.t + @@ m + mmm + mmmmm + mmmmm + mmmmmm + (* xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*) + mmmmmmm + mmmmmmmm + mmmmmmmm