From e5b04d989773ccc0a1c7af768b264c14f389a97e Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 23 Mar 2023 15:43:51 +0100 Subject: [PATCH 1/3] Don't indent attributes after let/val/external --- lib/Conf.ml | 4 ++-- test/passing/tests/attributes.ml | 14 +++++++------- test/passing/tests/attributes.mli.ref | 4 ++-- test/passing/tests/cases_exp_grouping.ml.ref | 10 +++++----- test/passing/tests/expect_test.ml | 8 ++++---- test/passing/tests/extensions-indent.ml.ref | 8 ++++---- test/passing/tests/extensions.ml.ref | 8 ++++---- test/passing/tests/option.ml.ref | 10 +++++----- 8 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/Conf.ml b/lib/Conf.ml index 9d1ef4cdbd..127943086e 100644 --- a/lib/Conf.ml +++ b/lib/Conf.ml @@ -106,7 +106,7 @@ let conventional_profile from = ; space_around_records= elt true ; space_around_variants= elt true ; stritem_extension_indent= elt 0 - ; stritem_attributes_indent= elt true + ; stritem_attributes_indent= elt false ; type_decl= elt `Compact ; type_decl_indent= elt 2 ; wrap_comments= elt false @@ -174,7 +174,7 @@ let ocamlformat_profile from = ; space_around_records= elt false ; space_around_variants= elt false ; stritem_extension_indent= elt 0 - ; stritem_attributes_indent= elt true + ; stritem_attributes_indent= elt false ; type_decl= elt `Compact ; type_decl_indent= elt 2 ; wrap_comments= elt false diff --git a/test/passing/tests/attributes.ml b/test/passing/tests/attributes.ml index 39d4bacc6e..d37d0b8be8 100644 --- a/test/passing/tests/attributes.ml +++ b/test/passing/tests/attributes.ml @@ -26,13 +26,13 @@ type t = (** docstring that is long enough to break *) } val foo : int - [@@deprecated "it is good the salad"] [@@warning "-32"] [@@warning "-99"] +[@@deprecated "it is good the salad"] [@@warning "-32"] [@@warning "-99"] val foo : int - [@@deprecated "it is good the salad"] - [@@warning "-32"] - [@@warning "-99"] - [@@some long comment] +[@@deprecated "it is good the salad"] +[@@warning "-32"] +[@@warning "-99"] +[@@some long comment] type t = A of int [@attr] | B of (float[@attr]) | C [@attr] @@ -423,8 +423,8 @@ let[@a let raise_length_mismatch name n1 n2 = invalid_argf "length mismatch in %s: %d <> %d" name n1 n2 () - [@@cold] [@@inline never] [@@local never] [@@specialise never] +[@@cold] [@@inline never] [@@local never] [@@specialise never] external unsafe_memset : t -> pos:int -> len:int -> char -> unit = "bigstring_memset_stub" - [@@noalloc] +[@@noalloc] diff --git a/test/passing/tests/attributes.mli.ref b/test/passing/tests/attributes.mli.ref index 471261174f..c7bece0879 100644 --- a/test/passing/tests/attributes.mli.ref +++ b/test/passing/tests/attributes.mli.ref @@ -1,8 +1,8 @@ [@@@ocaml.doc "_"] val f : int -> int -> int - [@@cold] [@@inline never] [@@local never] [@@specialise never] +[@@cold] [@@inline never] [@@local never] [@@specialise never] external unsafe_memset : t -> pos:int -> len:int -> char -> unit = "bigstring_memset_stub" - [@@noalloc] +[@@noalloc] diff --git a/test/passing/tests/cases_exp_grouping.ml.ref b/test/passing/tests/cases_exp_grouping.ml.ref index b5404f3bfa..0f81deb22b 100644 --- a/test/passing/tests/cases_exp_grouping.ml.ref +++ b/test/passing/tests/cases_exp_grouping.ml.ref @@ -9,7 +9,7 @@ let _ = | C -> fooooooooooooo | D -> fooooooooooooo end - [@@ocamlformat "break-cases=fit"] +[@@ocamlformat "break-cases=fit"] let _ = match x with @@ -30,7 +30,7 @@ let _ = | D -> fooooooooooooo end - [@@ocamlformat "break-cases=nested"] +[@@ocamlformat "break-cases=nested"] let _ = match x with @@ -50,7 +50,7 @@ let _ = | C -> fooooooooooooo | D -> fooooooooooooo end - [@@ocamlformat "break-cases=toplevel"] +[@@ocamlformat "break-cases=toplevel"] let _ = match x with @@ -70,7 +70,7 @@ let _ = | C -> fooooooooooooo | D -> fooooooooooooo end - [@@ocamlformat "break-cases=fit-or-vertical"] +[@@ocamlformat "break-cases=fit-or-vertical"] let _ = match x with @@ -90,4 +90,4 @@ let _ = | C -> fooooooooooooo | D -> fooooooooooooo end - [@@ocamlformat "break-cases=all"] +[@@ocamlformat "break-cases=all"] diff --git a/test/passing/tests/expect_test.ml b/test/passing/tests/expect_test.ml index 09e6c0aac3..990375572f 100644 --- a/test/passing/tests/expect_test.ml +++ b/test/passing/tests/expect_test.ml @@ -5,8 +5,8 @@ let%bench "test" = fun () -> () let%expect_test _ = assert false ; [%expect.unreachable] - [@@expect.uncaught_exn - {| +[@@expect.uncaught_exn + {| (* CR expect_test_collector: This test expectation appears to contain a backtrace. This is strongly discouraged as backtraces are fragile. Please change this test to not include a backtrace. *) @@ -18,8 +18,8 @@ let%expect_test _ = let _ = assert false ; [%expect.unreachable] - [@@expect.uncaught_exn - {| +[@@expect.uncaught_exn + {| "Assert_failure test.ml:5:6" Raised at file "test.ml", line 4, characters 6-18 Called from file "collector/expect_test_collector.ml", line 225, characters 12-19 |}] diff --git a/test/passing/tests/extensions-indent.ml.ref b/test/passing/tests/extensions-indent.ml.ref index 1ffe48de07..7b730b8c8a 100644 --- a/test/passing/tests/extensions-indent.ml.ref +++ b/test/passing/tests/extensions-indent.ml.ref @@ -157,10 +157,10 @@ let foo = fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooo foooooooooooooooooooooooooooo] - [@@foooooooooo - fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo - foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooo - foooooooooooooooooooooooooooo] +[@@foooooooooo + fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooo + foooooooooooooooooooooooooooo] [%%foooooooooo: fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo diff --git a/test/passing/tests/extensions.ml.ref b/test/passing/tests/extensions.ml.ref index a4dd654bf0..3dbe10d019 100644 --- a/test/passing/tests/extensions.ml.ref +++ b/test/passing/tests/extensions.ml.ref @@ -157,10 +157,10 @@ let foo = fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooo foooooooooooooooooooooooooooo] - [@@foooooooooo - fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo - foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooo - foooooooooooooooooooooooooooo] +[@@foooooooooo + fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo + foooooooooooooooooooooooooooooooooo foooooooooooooooooooooooooooo + foooooooooooooooooooooooooooo] [%%foooooooooo: fooooooooooooooooooooooooooo foooooooooooooooooooooooooooooooooo diff --git a/test/passing/tests/option.ml.ref b/test/passing/tests/option.ml.ref index 9ceb3d39cc..2a13b6d091 100644 --- a/test/passing/tests/option.ml.ref +++ b/test/passing/tests/option.ml.ref @@ -4,28 +4,28 @@ let _ = else ( something loooooooooooooooooooooooooooooooong enough to_trigger a break ; this is more ) - [@@ocamlformat "if-then-else=keyword-first"] +[@@ocamlformat "if-then-else=keyword-first"] let _ = if b then e else ( something loooooooooooooooooooooooooooooooong enough to_trigger a break ; this is more ) - [@@ocamlformat.typo "if-then-else=keyword-first"] +[@@ocamlformat.typo "if-then-else=keyword-first"] let _ = if b then e else ( something loooooooooooooooooooooooooooooooong enough to_trigger a break ; this is more ) - [@@ocamlformat 1, "if-then-else=keyword-first"] +[@@ocamlformat 1, "if-then-else=keyword-first"] let _ = if b then e else ( something loooooooooooooooooooooooooooooooong enough to_trigger a break ; this is more ) - [@@ocamlformat "if-then-else=bad"] +[@@ocamlformat "if-then-else=bad"] module M = struct [@@@ocamlformat "if-then-else=keyword-first"] @@ -36,7 +36,7 @@ module M = struct else ( something loooooooooooooooooooooooooooooooong enough to_trigger a break ; this is more ) - [@@ocamlformat "if-then-else=bad"] + [@@ocamlformat "if-then-else=bad"] let _ = if b From 38b3dc4cf42a61ae74b2ec468464d9231900a168 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 23 Mar 2023 15:46:40 +0100 Subject: [PATCH 2/3] Remove the internal option --- lib/Conf.ml | 3 --- lib/Conf_t.ml | 1 - lib/Conf_t.mli | 1 - lib/Fmt_ast.ml | 11 ++--------- 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/lib/Conf.ml b/lib/Conf.ml index 127943086e..94b05244ea 100644 --- a/lib/Conf.ml +++ b/lib/Conf.ml @@ -106,7 +106,6 @@ let conventional_profile from = ; space_around_records= elt true ; space_around_variants= elt true ; stritem_extension_indent= elt 0 - ; stritem_attributes_indent= elt false ; type_decl= elt `Compact ; type_decl_indent= elt 2 ; wrap_comments= elt false @@ -174,7 +173,6 @@ let ocamlformat_profile from = ; space_around_records= elt false ; space_around_variants= elt false ; stritem_extension_indent= elt 0 - ; stritem_attributes_indent= elt false ; type_decl= elt `Compact ; type_decl_indent= elt 2 ; wrap_comments= elt false @@ -241,7 +239,6 @@ let janestreet_profile from = ; space_around_records= elt true ; space_around_variants= elt true ; stritem_extension_indent= elt 2 - ; stritem_attributes_indent= elt false ; type_decl= elt `Sparse ; type_decl_indent= elt 2 ; wrap_comments= elt false diff --git a/lib/Conf_t.ml b/lib/Conf_t.ml index 08107f8af3..ca1bf047e5 100644 --- a/lib/Conf_t.ml +++ b/lib/Conf_t.ml @@ -114,7 +114,6 @@ type fmt_opts = ; space_around_records: bool elt ; space_around_variants: bool elt ; stritem_extension_indent: int elt - ; stritem_attributes_indent: bool elt ; type_decl: [`Compact | `Sparse] elt ; type_decl_indent: int elt ; wrap_comments: bool elt diff --git a/lib/Conf_t.mli b/lib/Conf_t.mli index 5e8ea10f29..72d955e3f6 100644 --- a/lib/Conf_t.mli +++ b/lib/Conf_t.mli @@ -112,7 +112,6 @@ type fmt_opts = ; space_around_records: bool elt ; space_around_variants: bool elt ; stritem_extension_indent: int elt - ; stritem_attributes_indent: bool elt ; type_decl: [`Compact | `Sparse] elt ; type_decl_indent: int elt ; wrap_comments: bool elt (** Wrap comments at margin. *) diff --git a/lib/Fmt_ast.ml b/lib/Fmt_ast.ml index e99777b723..85835f0270 100644 --- a/lib/Fmt_ast.ml +++ b/lib/Fmt_ast.ml @@ -3069,9 +3069,6 @@ and fmt_value_description ?ext c ctx vd = wrap "{|" "|}" (str s) else wrap "\"" "\"" (str (String.escaped s)) in - let attrs_indent = - if c.conf.fmt_opts.stritem_attributes_indent.v then 2 else 0 - in hvbox 0 ( doc_before $ box_fun_sig_args c 2 @@ -3091,7 +3088,7 @@ and fmt_value_description ?ext c ctx vd = $ fmt_if (not (List.is_empty pval_prim)) "@ = " $ hvbox_if (List.length pval_prim > 1) 0 @@ list pval_prim "@;" fmt_val_prim ) - $ fmt_item_attributes c ~pre:(Break (1, attrs_indent)) atrs + $ fmt_item_attributes c ~pre:(Break (1, 0)) atrs $ doc_after ) and fmt_tydcl_params c ctx params = @@ -4271,11 +4268,7 @@ and fmt_value_binding c ~rec_flag ?ext ?in_ ?epi ctx , Cmts.fmt_after c lb_loc ) | None -> let epi = - let indent = - if c.conf.fmt_opts.stritem_attributes_indent.v then indent else 0 - in - fmt_item_attributes c ~pre:(Break (1, indent)) at_at_attrs - $ fmt_opt epi + fmt_item_attributes c ~pre:(Break (1, 0)) at_at_attrs $ fmt_opt epi in ( true , noop From aaeec6cc31b63ab2957a4382bb579a751ec8a9a9 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Thu, 23 Mar 2023 15:47:26 +0100 Subject: [PATCH 3/3] Update changes --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index d77d674511..e729b7a2f7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ - Restore short form formatting of record field aliases (#2282, @gpetiot) - Tweaks the JaneStreet profile to be more consistent with ocp-indent (#2281, #2284, #2289, #2299, #2302, #2309, #2310, #2311, #2313, @gpetiot, @Julow) - Improve formatting of class signatures (#2301, @gpetiot, @Julow) +- Don't indent attributes after a let/val/external (#2317, @Julow) ### New features