Skip to content

Commit 363257e

Browse files
authored
Upgrade ocamlformat to 0.26.1 (#6493)
1 parent 2a37c94 commit 363257e

36 files changed

+286
-274
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,23 @@ jobs:
143143
144144
- name: Use OCaml ${{matrix.ocaml_compiler}}
145145
uses: ocaml/setup-ocaml@v2
146+
if: matrix.os != 'windows-latest'
146147
with:
147148
ocaml-compiler: ${{matrix.ocaml_compiler}}
148149
opam-pin: false
149150
opam-depext: false
150151

152+
- name: Use OCaml ${{matrix.ocaml_compiler}} (Win)
153+
uses: ocaml/setup-ocaml@v2
154+
if: matrix.os == 'windows-latest'
155+
with:
156+
ocaml-compiler: ${{matrix.ocaml_compiler}}
157+
opam-pin: false
158+
opam-depext: false
159+
opam-repositories: |
160+
opam-repository-mingw: https://github.com/ocaml-opam/opam-repository-mingw.git#sunset
161+
default: https://github.com/ocaml/opam-repository.git
162+
151163
- name: "Install OPAM dependencies"
152164
run: opam install . --deps-only
153165

.ocamlformat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
profile = default
2-
version = 0.22.4
2+
version = 0.26.1
33

44
field-space = tight-decl
55
break-cases = toplevel

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
(ocaml
2222
(>= 4.10))
2323
(ocamlformat
24-
(= 0.22.4))
24+
(= 0.26.1))
2525
(cppo
2626
(= 1.6.9))
2727
(js_of_ocaml-compiler

jscomp/frontend/ast_attributes.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ let process_method_attributes_rev (attrs : t) =
4141
| None -> true
4242
| Some e -> Ast_payload.assert_bool_lit e),
4343
undefined )
44-
| "undefined" -> (
44+
| "undefined" ->
4545
( null,
4646
match opt_expr with
4747
| None -> true
48-
| Some e -> Ast_payload.assert_bool_lit e ))
48+
| Some e -> Ast_payload.assert_bool_lit e )
4949
| "nullable" -> (
5050
match opt_expr with
5151
| None -> (true, true)

jscomp/frontend/ast_derive_abstract.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ let handleTdcl light (tdcl : Parsetree.type_declaration) :
8484
Ext_list.fold_right label_declarations
8585
( [],
8686
(if has_optional_field then
87-
Ast_compatible.arrow ~loc (Ast_literal.type_unit ()) core_type
88-
else core_type),
87+
Ast_compatible.arrow ~loc (Ast_literal.type_unit ()) core_type
88+
else core_type),
8989
[] )
9090
(fun ({
9191
pld_name = {txt = label_name; loc = label_loc} as pld_name;
@@ -109,15 +109,15 @@ let handleTdcl light (tdcl : Parsetree.type_declaration) :
109109
( Ast_compatible.opt_arrow ~loc:pld_loc label_name pld_type maker,
110110
Val.mk ~loc:pld_loc
111111
(if light then pld_name
112-
else {pld_name with txt = pld_name.txt ^ "Get"})
112+
else {pld_name with txt = pld_name.txt ^ "Get"})
113113
~attrs:get_optional_attrs ~prim
114114
(Ast_compatible.arrow ~loc core_type optional_type)
115115
:: acc )
116116
else
117117
( Ast_compatible.label_arrow ~loc:pld_loc label_name pld_type maker,
118118
Val.mk ~loc:pld_loc
119119
(if light then pld_name
120-
else {pld_name with txt = pld_name.txt ^ "Get"})
120+
else {pld_name with txt = pld_name.txt ^ "Get"})
121121
~attrs:get_attrs
122122
~prim:
123123
((* Not needed actually*)

jscomp/frontend/ast_derive_js_mapper.ml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ let init () =
213213
Ast_comb.single_non_rec_value patFromJs
214214
(Ast_compatible.fun_ (Pat.var pat_param)
215215
(if createType then
216-
Exp.let_ Nonrecursive
217-
[Vb.mk (Pat.var pat_param) (exp_param +: newType)]
218-
(Exp.constraint_ obj_exp core_type)
219-
else Exp.constraint_ obj_exp core_type))
216+
Exp.let_ Nonrecursive
217+
[Vb.mk (Pat.var pat_param) (exp_param +: newType)]
218+
(Exp.constraint_ obj_exp core_type)
219+
else Exp.constraint_ obj_exp core_type))
220220
in
221221
let rest = [toJs; fromJs] in
222222
if createType then eraseTypeStr :: newTypeStr :: rest else rest
@@ -239,16 +239,17 @@ let init () =
239239
));
240240
Ast_comb.single_non_rec_value {loc; txt = revMap}
241241
(if has_bs_as then
242-
Exp.extension
243-
( {txt = "raw"; loc},
244-
PStr
245-
[Str.eval (Exp.constant (Const.string revData))]
246-
)
247-
else expMap);
242+
Exp.extension
243+
( {txt = "raw"; loc},
244+
PStr
245+
[
246+
Str.eval (Exp.constant (Const.string revData));
247+
] )
248+
else expMap);
248249
toJsBody
249250
(if has_bs_as then
250-
app2 unsafeIndexGetExp expMap exp_param
251-
else app1 eraseTypeExp exp_param);
251+
app2 unsafeIndexGetExp expMap exp_param
252+
else app1 eraseTypeExp exp_param);
252253
Ast_comb.single_non_rec_value patFromJs
253254
(Ast_compatible.fun_ (Pat.var pat_param)
254255
(let result =

jscomp/frontend/ast_derive_projector.ml

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,32 +60,33 @@ let init () =
6060
Ast_comb.single_non_rec_value
6161
{loc; txt = little_con_name}
6262
(if arity = 0 then
63-
(*TODO: add a prefix, better inter-op with FFI *)
64-
Exp.constraint_
65-
(Exp.construct
66-
{loc; txt = Longident.Lident con_name}
67-
None)
68-
annotate_type
69-
else
70-
let vars =
71-
Ext_list.init arity (fun x ->
72-
"param_" ^ string_of_int x)
73-
in
74-
let exp =
75-
Exp.constraint_
76-
(Exp.construct
77-
{loc; txt = Longident.Lident con_name}
78-
@@ Some
79-
(if arity = 1 then
80-
Exp.ident {loc; txt = Lident (List.hd vars)}
81-
else
82-
Exp.tuple
83-
(Ext_list.map vars (fun x ->
84-
Exp.ident {loc; txt = Lident x}))))
85-
annotate_type
86-
in
87-
Ext_list.fold_right vars exp (fun var b ->
88-
Ast_compatible.fun_ (Pat.var {loc; txt = var}) b)))
63+
(*TODO: add a prefix, better inter-op with FFI *)
64+
Exp.constraint_
65+
(Exp.construct
66+
{loc; txt = Longident.Lident con_name}
67+
None)
68+
annotate_type
69+
else
70+
let vars =
71+
Ext_list.init arity (fun x ->
72+
"param_" ^ string_of_int x)
73+
in
74+
let exp =
75+
Exp.constraint_
76+
(Exp.construct
77+
{loc; txt = Longident.Lident con_name}
78+
@@ Some
79+
(if arity = 1 then
80+
Exp.ident
81+
{loc; txt = Lident (List.hd vars)}
82+
else
83+
Exp.tuple
84+
(Ext_list.map vars (fun x ->
85+
Exp.ident {loc; txt = Lident x}))))
86+
annotate_type
87+
in
88+
Ext_list.fold_right vars exp (fun var b ->
89+
Ast_compatible.fun_ (Pat.var {loc; txt = var}) b)))
8990
| Ptype_abstract | Ptype_open ->
9091
Ast_derive_util.notApplicable tdcl.ptype_loc derivingName;
9192
[]

jscomp/frontend/ast_external_process.ml

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -896,22 +896,22 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type)
896896
let arg_label = param_type.label in
897897
let ty = param_type.ty in
898898
(if i = 0 && splice then
899-
match arg_label with
900-
| Optional _ ->
901-
Location.raise_errorf ~loc
902-
"%@variadic expect the last type to be a non optional"
903-
| Labelled _ | Nolabel -> (
904-
if ty.ptyp_desc = Ptyp_any then
899+
match arg_label with
900+
| Optional _ ->
905901
Location.raise_errorf ~loc
906-
"%@variadic expect the last type to be an array";
907-
if spec_of_ptyp true ty <> Nothing then
908-
Location.raise_errorf ~loc
909-
"%@variadic expect the last type to be an array";
910-
match ty.ptyp_desc with
911-
| Ptyp_constr ({txt = Lident "array"; _}, [_]) -> ()
912-
| _ ->
913-
Location.raise_errorf ~loc
914-
"%@variadic expect the last type to be an array"));
902+
"%@variadic expect the last type to be a non optional"
903+
| Labelled _ | Nolabel -> (
904+
if ty.ptyp_desc = Ptyp_any then
905+
Location.raise_errorf ~loc
906+
"%@variadic expect the last type to be an array";
907+
if spec_of_ptyp true ty <> Nothing then
908+
Location.raise_errorf ~loc
909+
"%@variadic expect the last type to be an array";
910+
match ty.ptyp_desc with
911+
| Ptyp_constr ({txt = Lident "array"; _}, [_]) -> ()
912+
| _ ->
913+
Location.raise_errorf ~loc
914+
"%@variadic expect the last type to be an array"));
915915
let ( (arg_label : External_arg_spec.label_noname),
916916
arg_type,
917917
new_arg_types ) =
@@ -988,8 +988,7 @@ let pval_prim_of_option_labels (labels : (bool * string Asttypes.loc) list)
988988
(ends_with_unit : bool) =
989989
let arg_kinds =
990990
Ext_list.fold_right labels
991-
(if ends_with_unit then [External_arg_spec.empty_kind Extern_unit]
992-
else [])
991+
(if ends_with_unit then [External_arg_spec.empty_kind Extern_unit] else [])
993992
(fun (is_option, p) arg_kinds ->
994993
let label_name = p.txt in
995994
let obj_arg_label =

jscomp/frontend/bs_builtin_ppx.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
549549
(* Dynamic import of module transformation: module M = @res.await Belt.List *)
550550
| Pstr_module
551551
({pmb_expr = {pmod_desc = Pmod_ident {txt; loc}; pmod_attributes} as me}
552-
as mb)
552+
as mb)
553553
when Res_parsetree_viewer.hasAwaitAttribute pmod_attributes ->
554554
let item = self.structure_item self item in
555555
let safe_module_type_name = local_module_type_name txt in

jscomp/frontend/external_ffi_types.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ let inline_float_primitive (i : string) : string list =
296296
let rec ffi_bs_aux acc (params : External_arg_spec.params) =
297297
match params with
298298
| {arg_type = Nothing; arg_label = Arg_empty}
299-
(* same as External_arg_spec.dummy*)
299+
(* same as External_arg_spec.dummy*)
300300
:: rest ->
301301
ffi_bs_aux (acc + 1) rest
302302
| _ :: _ -> -1

jscomp/gentype/EmitJs.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
156156
match type_ with
157157
| Function
158158
({argTypes = [{aType = Object (closedFlag, fields); aName}]; retType}
159-
as function_)
159+
as function_)
160160
when retType |> EmitType.isTypeFunctionComponent ~fields ->
161161
(* JSX V3 *)
162162
let fields =
@@ -178,7 +178,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
178178
Function function_
179179
| Function
180180
({argTypes = [{aType = Ident {name} as propsType; aName}]; retType} as
181-
function_)
181+
function_)
182182
when Filename.check_suffix name "props"
183183
&& retType |> EmitType.isTypeFunctionComponent ~fields:[] -> (
184184
match inlineOneLevel propsType with
@@ -305,7 +305,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
305305
Some {HookType.propsType; resolvedTypeName; typeVars} )
306306
| Function
307307
({argTypes = [{aType = Ident {name} as propsType}]; retType} as
308-
function_)
308+
function_)
309309
when Filename.check_suffix name "props"
310310
&& retType |> EmitType.isTypeFunctionComponent ~fields:[] ->
311311
let compType =

jscomp/gentype/EmitType.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,10 @@ let emitExportType ~(config : Config.t) ~emitters ~nameAs ~opaque ~type_
360360
|> Emitters.export ~emitters
361361
else
362362
(if isInterface && config.exportInterfaces then
363-
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString ^ " "
364-
else
365-
docString ^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
363+
docString ^ "export interface " ^ resolvedTypeName ^ typeParamsString
364+
^ " "
365+
else
366+
docString ^ "export type " ^ resolvedTypeName ^ typeParamsString ^ " = ")
366367
^ (match type_ with
367368
| _ -> type_ |> typeToString ~config ~typeNameIsInterface)
368369
^ ";" ^ exportNameAs

jscomp/gentype/GenTypeMain.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,4 @@ let processCmtFile cmt =
167167
else (
168168
outputFile |> GeneratedFiles.logFileAction NoMatch;
169169
if Sys.file_exists outputFile then Sys.remove outputFile)
170-
[@@live]
170+
[@@live]

jscomp/gentype/TranslateCoreType.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ and translateCoreType_ ~config ~typeVarsGen
119119
| Ttyp_object (tObj, closedFlag) ->
120120
let getFieldType objectField =
121121
match objectField with
122-
| Typedtree.OTtag ({txt = name}, _, t) -> (
122+
| Typedtree.OTtag ({txt = name}, _, t) ->
123123
( name,
124124
match name |> Runtime.isMutableObjectField with
125125
| true -> {dependencies = []; type_ = ident ""}
126-
| false -> t |> translateCoreType_ ~config ~typeVarsGen ~typeEnv ))
126+
| false -> t |> translateCoreType_ ~config ~typeVarsGen ~typeEnv )
127127
| OTinherit t ->
128128
("Inherit", t |> translateCoreType_ ~config ~typeVarsGen ~typeEnv)
129129
in
@@ -209,7 +209,7 @@ and translateCoreType_ ~config ~typeVarsGen
209209
{
210210
labelJS =
211211
(if isNumber label then IntLabel label
212-
else StringLabel label);
212+
else StringLabel label);
213213
};
214214
t = translation.type_;
215215
})

jscomp/gentype/TranslateStructure.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ and addAnnotationsToFields ~config (expr : Typedtree.expression)
5555
in
5656
({field with nameJS = name} :: nextFields1, types1)
5757
| _ -> (fields, argTypes)
58-
[@@live]
58+
[@@live]
5959

6060
(** Recover from expr the renaming annotations on named arguments. *)
6161
let addAnnotationsToFunctionType ~config (expr : Typedtree.expression)

jscomp/gentype/TranslateTypeDeclarations.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ let traslateDeclarationKind ~config ~loc ~outputFileRelative ~resolver
119119
let fields =
120120
fieldTranslations
121121
|> List.map
122-
(fun (name, mutable_, {TranslateTypeExprFromTypes.type_}, docString)
123-
->
122+
(fun
123+
(name, mutable_, {TranslateTypeExprFromTypes.type_}, docString) ->
124124
let optional, type1 =
125125
match type_ with
126126
| Option type1 when isOptional name -> (Optional, type1)

jscomp/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,7 @@ and translateTypeExprFromTypes_ ~config ~typeVarsGen ~typeEnv
383383
|> List.map (fun label ->
384384
{
385385
labelJS =
386-
(if isNumber label then IntLabel label
387-
else StringLabel label);
386+
(if isNumber label then IntLabel label else StringLabel label);
388387
})
389388
in
390389
let type_ =

jscomp/syntax/cli/res_cli.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module Color = struct
9090
| Format.String_tag "dim" -> [Dim]
9191
| Format.String_tag "filename" -> [FG Cyan]
9292
| _ -> raise Not_found
93-
[@@raises Not_found]
93+
[@@raises Not_found]
9494

9595
let color_enabled = ref true
9696

@@ -305,7 +305,7 @@ module CliArgProcessor = struct
305305
in
306306
printEngine.printImplementation ~width ~filename
307307
~comments:parseResult.comments parsetree
308-
[@@raises exit]
308+
[@@raises exit]
309309
end
310310

311311
let () =
@@ -317,4 +317,4 @@ let () =
317317
~jsxVersion:!ResClflags.jsxVersion ~jsxModule:!ResClflags.jsxModule
318318
~jsxMode:!ResClflags.jsxMode ~typechecker:!ResClflags.typechecker
319319
!ResClflags.file)
320-
[@@raises exit]
320+
[@@raises exit]

jscomp/syntax/src/reactjs_jsx_v3.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ let jsxMapper ~config =
592592
pstr_desc =
593593
Pstr_primitive
594594
({pval_name = {txt = fnName}; pval_attributes; pval_type} as
595-
value_description);
595+
value_description);
596596
} as pstr -> (
597597
match List.filter React_jsx_common.hasAttr pval_attributes with
598598
| [] -> [item]
@@ -1035,7 +1035,7 @@ let jsxMapper ~config =
10351035
psig_desc =
10361036
Psig_value
10371037
({pval_name = {txt = fnName}; pval_attributes; pval_type} as
1038-
psig_desc);
1038+
psig_desc);
10391039
} as psig -> (
10401040
match List.filter React_jsx_common.hasAttr pval_attributes with
10411041
| [] -> [item]

0 commit comments

Comments
 (0)