Skip to content

Commit 28464e8

Browse files
Moves module attributes after the module keyword
1 parent de28240 commit 28464e8

File tree

8 files changed

+53
-61
lines changed

8 files changed

+53
-61
lines changed

lib/Fmt_ast.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,8 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
758758
Cmts.fmt c ptyp_loc
759759
@@ (fun k -> k $ fmt_docstring c ~pro:(fmt "@ ") doc)
760760
@@ ( if List.is_empty atrs then Fn.id
761-
else fun k ->
762-
hvbox 0 (Params.parens c.conf (k $ fmt_attributes c ~pre:Cut atrs))
763-
)
761+
else fun k ->
762+
hvbox 0 (Params.parens c.conf (k $ fmt_attributes c ~pre:Cut atrs)) )
764763
@@
765764
let parens = parenze_typ xtyp in
766765
hvbox_if box 0
@@ -836,10 +835,10 @@ and fmt_core_type c ?(box = true) ?pro ?(pro_space = true) ?constraint_ctx
836835
| _ ->
837836
list rfs
838837
( if
839-
in_type_declaration
840-
&& Poly.(c.conf.fmt_opts.type_decl.v = `Sparse)
841-
then "@;<1000 0>| "
842-
else "@ | " )
838+
in_type_declaration
839+
&& Poly.(c.conf.fmt_opts.type_decl.v = `Sparse)
840+
then "@;<1000 0>| "
841+
else "@ | " )
843842
(fmt_row_field c ctx)
844843
in
845844
let protect_token = Exposed.Right.(list ~elt:row_field) rfs in
@@ -3695,6 +3694,7 @@ and fmt_module c ctx ?ext ?epi ?(can_sparse = false) keyword ?(eqty = "=")
36953694
$ hvbox 4
36963695
( str keyword
36973696
$ fmt_extension_suffix c ext
3697+
$ fmt_attributes c ~pre:(Break (1, 0)) atrs
36983698
$ fmt_if rec_flag " rec" $ str " "
36993699
$ fmt_str_loc_opt c name $ list_pn arg_blks fmt_arg
37003700
)
@@ -3707,9 +3707,7 @@ and fmt_module c ctx ?ext ?epi ?(can_sparse = false) keyword ?(eqty = "=")
37073707
$ blk_b.psp
37083708
$ fmt_if (Option.is_none blk_b.pro && Option.is_some xbody) "@ "
37093709
$ blk_b.bdy )
3710-
$ blk_b.esp $ fmt_opt blk_b.epi
3711-
$ fmt_item_attributes c ~pre:(Break (1, 0)) atrs
3712-
$ doc_after
3710+
$ blk_b.esp $ fmt_opt blk_b.epi $ doc_after
37133711
$ opt epi (fun epi ->
37143712
fmt_or_k compact
37153713
(fmt_or
@@ -4156,7 +4154,7 @@ and fmt_let c ctx ~ext ~rec_flag ~bindings ~parens ~fmt_atrs ~fmt_expr
41564154
(vbox 0
41574155
( hvbox 0 (list_fl bindings fmt_binding)
41584156
$ ( if blank_line_after_in then fmt "\n@,"
4159-
else break 1000 indent_after_in )
4157+
else break 1000 indent_after_in )
41604158
$ hvbox 0 fmt_expr ) )
41614159
$ fmt_atrs
41624160

test/passing/tests/attributes.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module type M = sig
6565

6666
module T : [%ext] [@test7]
6767

68-
module T = T [@@test8]
68+
module [@test8] T = T
6969
end
7070

7171
let f = fun [@inline] [@inline never] x -> x
@@ -177,7 +177,7 @@ type t = {a: int}
177177
[@@deriving xxxxxxxxxxxxxxxxxxxxxxxxxxx]
178178

179179
module type A = sig
180-
module A := A.B [@@attr]
180+
module [@attr] A := A.B
181181
end
182182

183183
module M = struct
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Warning: tests/js_source.ml:156 exceeds the margin
2-
Warning: tests/js_source.ml:3558 exceeds the margin
3-
Warning: tests/js_source.ml:9546 exceeds the margin
4-
Warning: tests/js_source.ml:9649 exceeds the margin
5-
Warning: tests/js_source.ml:9668 exceeds the margin
6-
Warning: tests/js_source.ml:9708 exceeds the margin
7-
Warning: tests/js_source.ml:9790 exceeds the margin
1+
Warning: tests/js_source.ml:154 exceeds the margin
2+
Warning: tests/js_source.ml:3556 exceeds the margin
3+
Warning: tests/js_source.ml:9544 exceeds the margin
4+
Warning: tests/js_source.ml:9647 exceeds the margin
5+
Warning: tests/js_source.ml:9666 exceeds the margin
6+
Warning: tests/js_source.ml:9706 exceeds the margin
7+
Warning: tests/js_source.ml:9788 exceeds the margin

test/passing/tests/js_source.ml.ref

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@ type t = Foo of (t[@foo]) [@foo] [@@foo]
66

77
[@@@foo]
88

9-
module M = struct
9+
module [@foo] M = struct
1010
type t = { l : (t[@foo]) [@foo] } [@@foo] [@@foo]
1111

1212
[@@@foo]
1313
end [@foo]
14-
[@@foo]
1514

16-
module type S = sig
15+
module type [@foo] S = sig
1716
include ((module type of M [@foo]) [@foo] with type t := M.t [@foo]) [@@foo]
1817

1918
[@@@foo]
2019
end [@foo]
21-
[@@foo]
2220

2321
[@@@foo]
2422

@@ -181,12 +179,12 @@ class%foo x = x [@@foo]
181179
class type%foo x = x [@@foo]
182180
external%foo x : _ = "" [@@foo]
183181
exception%foo X [@foo]
184-
module%foo M = M [@@foo]
182+
module%foo [@foo] M = M
185183

186-
module%foo rec M : S = M [@@foo]
187-
and M : S = M [@@foo]
184+
module%foo [@foo] rec M : S = M
185+
and [@foo] M : S = M
188186

189-
module type%foo S = S [@@foo]
187+
module type%foo [@foo] S = S
190188
include%foo M [@@foo]
191189
open%foo M [@@foo]
192190

@@ -200,13 +198,13 @@ module type S = sig
200198

201199
type%foo t += T [@@foo]
202200
exception%foo X [@foo]
203-
module%foo M : S [@@foo]
201+
module%foo [@foo] M : S
204202

205-
module%foo rec M : S [@@foo]
206-
and M : S [@@foo]
203+
module%foo [@foo] rec M : S
204+
and [@foo] M : S
207205

208-
module%foo M = M [@@foo]
209-
module type%foo S = S [@@foo]
206+
module%foo [@foo] M = M
207+
module type%foo [@foo] S = S
210208
include%foo M [@@foo]
211209
open%foo M [@@foo]
212210
class%foo x : t [@@foo]

test/passing/tests/protected_object_types.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,15 @@ module Space_around = struct
2525
(* Ensure that the protection mechanism does not add extra spaces when
2626
[--space-around-*] options are sufficient. *)
2727

28-
module Records = struct
28+
module [@ocamlformat "space-around-records = true"] Records = struct
2929
type t = { foo: < .. > }
3030

3131
type t = A of { foo: < .. > }
3232
end
33-
[@@ocamlformat "space-around-records = true"]
3433

35-
module Variants = struct
34+
module [@ocamlformat "space-around-variants"] Variants = struct
3635
type t = [ `Foo of < .. > ]
3736
end
38-
[@@ocamlformat "space-around-variants"]
3937
end
4038

4139
module Inside_payloads = struct

test/passing/tests/shortcut_ext_attr.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ external%foo x : _ = "" [@@foo]
104104

105105
exception%foo X [@@foo]
106106

107-
module%foo M = M [@@foo]
107+
module%foo [@foo] M = M
108108

109-
module%foo rec M : S = M [@@foo]
109+
module%foo [@foo] rec M : S = M
110110

111-
and M : S = M [@@foo]
111+
and [@foo] M : S = M
112112

113-
module type%foo S = S [@@foo]
113+
module type%foo [@foo] S = S
114114

115115
include%foo M [@@foo]
116116

@@ -130,16 +130,16 @@ module type S = sig
130130

131131
[%%foo: exception X [@@foo]]
132132

133-
[%%foo: module M : S [@@foo]]
133+
[%%foo: module [@foo] M : S]
134134

135135
[%%foo:
136-
module rec M : S [@@foo]
136+
module [@foo] rec M : S
137137

138-
and M : S [@@foo]]
138+
and [@foo] M : S]
139139

140-
[%%foo: module M = M [@@foo]]
140+
[%%foo: module [@foo] M = M]
141141

142-
[%%foo: module type S = S [@@foo]]
142+
[%%foo: module type [@foo] S = S]
143143

144144
[%%foo: include M [@@foo]]
145145

test/passing/tests/source.ml.err

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Warning: tests/source.ml:706 exceeds the margin
2-
Warning: tests/source.ml:2322 exceeds the margin
1+
Warning: tests/source.ml:704 exceeds the margin
2+
Warning: tests/source.ml:2320 exceeds the margin

test/passing/tests/source.ml.ref

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,19 @@ type t = Foo of (t[@foo]) [@foo] [@@foo]
66

77
[@@@foo]
88

9-
module M = struct
9+
module [@foo] M = struct
1010
type t = {l: (t[@foo]) [@foo]} [@@foo] [@@foo]
1111

1212
[@@@foo]
1313
end [@foo]
14-
[@@foo]
1514

16-
module type S = sig
15+
module type [@foo] S = sig
1716
include
1817
((module type of M [@foo]) [@foo] with type t := M.t [@foo])
1918
[@@foo]
2019

2120
[@@@foo]
2221
end [@foo]
23-
[@@foo]
2422

2523
[@@@foo]
2624

@@ -226,13 +224,13 @@ external%foo x : _ = "" [@@foo]
226224

227225
exception%foo X [@foo]
228226

229-
module%foo M = M [@@foo]
227+
module%foo [@foo] M = M
230228

231-
module%foo rec M : S = M [@@foo]
229+
module%foo [@foo] rec M : S = M
232230

233-
and M : S = M [@@foo]
231+
and [@foo] M : S = M
234232

235-
module type%foo S = S [@@foo]
233+
module type%foo [@foo] S = S
236234

237235
include%foo M [@@foo]
238236

@@ -252,15 +250,15 @@ module type S = sig
252250

253251
exception%foo X [@foo]
254252

255-
module%foo M : S [@@foo]
253+
module%foo [@foo] M : S
256254

257-
module%foo rec M : S [@@foo]
255+
module%foo [@foo] rec M : S
258256

259-
and M : S [@@foo]
257+
and [@foo] M : S
260258

261-
module%foo M = M [@@foo]
259+
module%foo [@foo] M = M
262260

263-
module type%foo S = S [@@foo]
261+
module type%foo [@foo] S = S
264262

265263
include%foo M [@@foo]
266264

0 commit comments

Comments
 (0)