diff --git a/src/reason-parser/reason_pprint_ast.ml b/src/reason-parser/reason_pprint_ast.ml index 14639c306..b59b9c800 100644 --- a/src/reason-parser/reason_pprint_ast.ml +++ b/src/reason-parser/reason_pprint_ast.ml @@ -2873,7 +2873,7 @@ let printer = object(self:'self) source_map ~loc:pld.pld_loc recordRow in let rows = List.map recordRow lbls in - (* if a record has more than 1 row, always break *) + (* if a record type has more than 1 row, always break *) let break = match rows with | [] | [ _ ] -> Layout.IfNeed @@ -6226,7 +6226,7 @@ let printer = object(self:'self) | (Pexp_record (recordRows, optionalGadt), _, _) -> forceBreak := true; let keyWithColon = makeList (maybeQuoteFirstElem li [atom ":"]) in - let value = self#unparseRecord ~forceBreak: true recordRows optionalGadt in + let value = self#unparseRecord ~forceBreak:true recordRows optionalGadt in label ~space:true keyWithColon value | (Pexp_extension (s, p), _, _) when s.txt = "mel.obj" -> forceBreak := true; @@ -6283,9 +6283,15 @@ let printer = object(self:'self) in firstRow::(getRows l) in + let break = + (* if a record has more than 1 row, always break *) + match !forceBreak, allRows with + | false, ([] | [ _ ]) -> Layout.IfNeed + | _ -> Layout.Always_rec + in makeList ~wrap:(lwrap ^ "{" ,"}" ^ rwrap) - ~break:(if !forceBreak then Layout.Always else Layout.IfNeed) + ~break ~sep:commaTrail ~postSpace:true (groupAndPrint ~xf:fst ~getLoc:snd ~comments:self#comments allRows) diff --git a/test/4.06/type-trailing.t/run.t b/test/4.06/type-trailing.t/run.t index ed25ea505..fea1934ce 100644 --- a/test/4.06/type-trailing.t/run.t +++ b/test/4.06/type-trailing.t/run.t @@ -38,8 +38,14 @@ Print the formatted file xx }; let p = {contents: 0}; let {contents: c} = p; - let point = {x: 0, y: 0}; - let point2 = {...point, y: 200}; + let point = { + x: 0, + y: 0, + }; + let point2 = { + ...point, + y: 200, + }; let myTuple = (0, 0); let (i, j) = myTuple; diff --git a/test/4.10/reasonComments-re.t/run.t b/test/4.10/reasonComments-re.t/run.t index 46319a97e..b55cb1201 100644 --- a/test/4.10/reasonComments-re.t/run.t +++ b/test/4.10/reasonComments-re.t/run.t @@ -758,7 +758,10 @@ Print the formatted file }; /** doc let */ - let letter: q = {a: 42, b: "answer"}; + let letter: q = { + a: 42, + b: "answer", + }; Type-check basics $ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re diff --git a/test/4.12/reasonComments-re.t/run.t b/test/4.12/reasonComments-re.t/run.t index 248fa9a5d..ec0051f22 100644 --- a/test/4.12/reasonComments-re.t/run.t +++ b/test/4.12/reasonComments-re.t/run.t @@ -758,7 +758,10 @@ Print the formatted file }; /** doc let */ - let letter: q = {a: 42, b: "answer"}; + let letter: q = { + a: 42, + b: "answer", + }; Type-check basics $ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re diff --git a/test/basicStructures.t/run.t b/test/basicStructures.t/run.t index 4a68d2f2b..4d9be7660 100644 --- a/test/basicStructures.t/run.t +++ b/test/basicStructures.t/run.t @@ -754,12 +754,24 @@ Format basicStructures /* no punning available for a single field. Can't tell the difference with a scope + expression */ let componentA = {props: props}; /* pun for real */ - let componentB = {props, state: ()}; + let componentB = { + props, + state: (), + }; /* pun fields with module prefix too */ let foo = {Foo.foo: foo}; - let bar = {Foo.foo, bar: 1}; - let bar = {bar: 1, Foo.foo}; - let bar = {Foo.foo, Bar.bar}; + let bar = { + Foo.foo, + bar: 1, + }; + let bar = { + bar: 1, + Foo.foo, + }; + let bar = { + Foo.foo, + Bar.bar, + }; ({M.x, y}) => 1; diff --git a/test/general-syntax-re.t/run.t b/test/general-syntax-re.t/run.t index 2cf97ba88..483b6f38a 100644 --- a/test/general-syntax-re.t/run.t +++ b/test/general-syntax-re.t/run.t @@ -262,7 +262,10 @@ Format general implementation syntax y: int, z: int, }; - let point2D = {x: 20, y: 30}; + let point2D = { + x: 20, + y: 30, + }; let point3D: point3D = { x: 10, @@ -282,7 +285,10 @@ Format general implementation syntax let res1 = printPoint(point2D); let res2 = - printPoint({x: point3D.x, y: point3D.y}); + printPoint({ + x: point3D.x, + y: point3D.y, + }); /* When () were used to indicate sequences, the parser used seq_expr not only @@ -310,7 +316,10 @@ Format general implementation syntax printPoint( addPoints( point2D, - {x: point3D.x, y: point3D.y}, + { + x: point3D.x, + y: point3D.y, + }, ), ); @@ -324,10 +333,16 @@ Format general implementation syntax dateHired: int, }; - let o: person = {name: "bob", age: 10}; + let o: person = { + name: "bob", + age: 10, + }; /* Parens needed? Nope! */ - let o: person = {name: "bob", age: 10}; + let o: person = { + name: "bob", + age: 10, + }; let printPerson = (p: person) => { let q: person = p; @@ -1400,9 +1415,30 @@ Format general implementation syntax foo(~a=Foo.a); /* https://github.com/facebook/reason/issues/2155#issuecomment-422077648 */ - true ? (Update({...a, b: 1}), None) : x; - true ? {...a, b: 1} : a; - true ? (a, {...a, b: 1}) : a; + true + ? ( + Update({ + ...a, + b: 1, + }), + None, + ) + : x; + true + ? { + ...a, + b: 1, + } + : a; + true + ? ( + a, + { + ...a, + b: 1, + }, + ) + : a; true ? ([x, ...xs]) => f(x, xs) : a; diff --git a/test/modules.t/run.t b/test/modules.t/run.t index 7c2d5cc62..badd4f15d 100644 --- a/test/modules.t/run.t +++ b/test/modules.t/run.t @@ -555,7 +555,10 @@ Format modules M.[foo, bar]; }; let z = { - M.{x: 10, y: 20}; + M.{ + x: 10, + y: 20, + }; }; let z = { M.(M2.(value)); @@ -590,7 +593,10 @@ Format modules }; let z = { open! M; - {x: 10, y: 20}; + { + x: 10, + y: 20, + }; }; let z = { open! M; diff --git a/test/modules_no_semi.t/run.t b/test/modules_no_semi.t/run.t index 91dc96c67..a0667dfa1 100644 --- a/test/modules_no_semi.t/run.t +++ b/test/modules_no_semi.t/run.t @@ -555,7 +555,10 @@ Format modules no semi M.[foo, bar]; }; let z = { - M.{x: 10, y: 20}; + M.{ + x: 10, + y: 20, + }; }; let z = { M.(M2.(value)); @@ -590,7 +593,10 @@ Format modules no semi }; let z = { open! M; - {x: 10, y: 20}; + { + x: 10, + y: 20, + }; }; let z = { open! M; diff --git a/test/patternMatching.t/run.t b/test/patternMatching.t/run.t index 195ff82f7..5199c9684 100644 --- a/test/patternMatching.t/run.t +++ b/test/patternMatching.t/run.t @@ -314,7 +314,11 @@ Print the formatted file | ({from: None, to_: None}: intRange) => ( None: optIntRange ) - | {from, to_} => Some({from, to_}); + | {from, to_} => + Some({ + from, + to_, + }); Type-check basics $ ocamlc -c -pp 'refmt --print binary' -intf-suffix .rei -impl formatted.re diff --git a/test/pexpFun.t/run.t b/test/pexpFun.t/run.t index df2e22130..1d2d21d46 100644 --- a/test/pexpFun.t/run.t +++ b/test/pexpFun.t/run.t @@ -4,7 +4,10 @@ Format function expressipns (pexpFun) switch (x) { | Bar => ReasonReact.UpdateWithSideEffects( - {...state, click: click + 1}, + { + ...state, + click: click + 1, + }, self => { let _ = 1; apply(bar); diff --git a/test/sequences.t/run.t b/test/sequences.t/run.t index acc0eae22..a8e5cf34c 100644 --- a/test/sequences.t/run.t +++ b/test/sequences.t/run.t @@ -83,9 +83,21 @@ Print the formatted file let b = 0; let c = 0; /* All of these will be printed as punned because they have more than one field. */ - let firstFieldPunned = {a, b, c}; - let sndFieldPunned = {a, b, c}; - let thirdFieldPunned = {a, b, c}; + let firstFieldPunned = { + a, + b, + c, + }; + let sndFieldPunned = { + a, + b, + c, + }; + let thirdFieldPunned = { + a, + b, + c, + }; let singlePunAcceptedIfExtended = { ...firstFieldPunned, a, diff --git a/test/trailing.t/run.t b/test/trailing.t/run.t index f28bd1786..1ab4a94d6 100644 --- a/test/trailing.t/run.t +++ b/test/trailing.t/run.t @@ -2,11 +2,21 @@ Format trailing $ refmt ./input.re let x = {"obj": obj}; - let x = {"key": key, "keyTwo": keyTwo}; - - let x = {...x, "key": key}; - - let x = {...x, "key": key, "keyTwo": keyTwo}; + let x = { + "key": key, + "keyTwo": keyTwo, + }; + + let x = { + ...x, + "key": key, + }; + + let x = { + ...x, + "key": key, + "keyTwo": keyTwo, + }; type t = {. "x": int}; @@ -18,11 +28,21 @@ Format trailing let x = {"obj": 0}; - let x = {"key": 0, "keyTwo": 1}; - - let x = {...x, "key": 0}; - - let x = {...x, "key": 0, "keyTwo": 1}; + let x = { + "key": 0, + "keyTwo": 1, + }; + + let x = { + ...x, + "key": 0, + }; + + let x = { + ...x, + "key": 0, + "keyTwo": 1, + }; type t = {. "x": int}; diff --git a/test/type-pipeFirst.t/run.t b/test/type-pipeFirst.t/run.t index 816c64911..2c9a4237e 100644 --- a/test/type-pipeFirst.t/run.t +++ b/test/type-pipeFirst.t/run.t @@ -16,7 +16,10 @@ Print the formatted file x: int, y: int, }; - let coord = {x: 1, y: 1}; + let coord = { + x: 1, + y: 1, + }; /* parses as (coord.x)->a->b->c */ let t2: int = coord.x->a->b->c; diff --git a/test/variants.t/run.t b/test/variants.t/run.t index e0e57e394..f5365b423 100644 --- a/test/variants.t/run.t +++ b/test/variants.t/run.t @@ -270,7 +270,14 @@ Format variants let result = switch ( - AlsoHasARecord(10, 10, {x: 10, y: 20}) + AlsoHasARecord( + 10, + 10, + { + x: 10, + y: 20, + }, + ) ) { | Blah => 1000 | AlsoHasARecord(a, b, {x, y}) => diff --git a/test/wrapping-re.t/run.t b/test/wrapping-re.t/run.t index 29ce4349f..06959ba55 100644 --- a/test/wrapping-re.t/run.t +++ b/test/wrapping-re.t/run.t @@ -542,7 +542,10 @@ Format wrapping in .re files */ let result = acceptsTwoThings( - {age: 20, name: "a"}, + { + age: 20, + name: "a", + }, { fieldOne: 10, fieldtwo: [10, 20],