Skip to content

Commit

Permalink
interleave whitespace between recursive let and module bindings (#1990)
Browse files Browse the repository at this point in the history
* interleave whitespace between recursive let and module bindings

* Inline braces surrounding a Pexp_match as jsx child.

* Consistent with Prettier
* Wastes less whitespace

Before:
```reason
<div>
  {
    switch (color) {
    | Black => ReasonReact.string("black")
    | Red => ReasonReact.string("red")
    }
  }
</div>;
```

```reason
<div>
  {switch (color) {
   | Black => ReasonReact.string("black")
   | Red => ReasonReact.string("red")
   }}
</div>;
```

* Cleanup unused code

* fix esy build
  • Loading branch information
IwanKaramazow authored and chenglou committed Nov 14, 2018
1 parent 7f2c5a3 commit 3591742
Show file tree
Hide file tree
Showing 5 changed files with 335 additions and 51 deletions.
108 changes: 108 additions & 0 deletions formatTest/unit_tests/expected_output/whitespace.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,35 @@ module Test = {
let y = 34;
};

/** recursive let bindings */

/* see below */

let foo = "abc"
and bar = "def"
and baz = "ghi";

/* with whitespace */

let foo = "abc"

and bar = "def"

and baz = "ghi";

/** with whitespace and attrs */

/* -> */

[@foo]
let foo = "abc"

[@bar]
and bar = "def"

[@baz]
and baz = "ghi";

module Comments = {
let z = 1;
/* comment *without* whitespace interleaved*/
Expand Down Expand Up @@ -172,6 +201,85 @@ module PatternMatching = {
};
};

/** recursive modules without whitespace */
module rec A: {
type t;
let a_fn: t => B.t;
let of_float: float => t;
} = {
type t = int;
let a_fn = x => B.of_int(x);
let of_float = x => int_of_float(x);
}
/* no whitespace */
and B: {
type t;
let another_fn: t => A.t;
let of_int: int => t;
} = {
type t = float;
let another_fn = x => A.of_float(x);
let of_int = x => float_of_int(x);
};

/** recursive modules with whitespace */

/* -> below */

module rec A: {
type t;
let a_fn: t => B.t;
let of_float: float => t;
} = {
type t = int;
let a_fn = x => B.of_int(x);
let of_float = x => int_of_float(x);
}

/** okok */

/* lala */

and B: {
type t;
let another_fn: t => A.t;
let of_int: int => t;
} = {
type t = float;
let another_fn = x => A.of_float(x);
let of_int = x => float_of_int(x);
};

/** recursive modules with attrs */

/* -> below */

[@foo1]
module rec A: {
type t;
let a_fn: t => B.t;
let of_float: float => t;
} = {
type t = int;
let a_fn = x => B.of_int(x);
let of_float = x => int_of_float(x);
}

/** okok */

/* lala */

[@foo2]
and B: {
type t;
let another_fn: t => A.t;
let of_int: int => t;
} = {
type t = float;
let another_fn = x => A.of_float(x);
let of_int = x => float_of_int(x);
};

module EdgeCase = {
let x = 1; /* a */

Expand Down
22 changes: 22 additions & 0 deletions formatTest/unit_tests/expected_output/whitespace.rei
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,28 @@ and X2: Y2;
module rec X1: Y1
and X2: Y2;

/** rec modules with whitespace */

/* -> */

module rec X1: Y1

and X2: Y2;

/** rec modules with whitespace and attrs */

/* -> */

[@foo]
module rec X1: Y1

/** another one below */

/* random comment */

[@bar]
and X2: Y2;

/* notice the whitespace after the last signature item */

/* this one has whitespace interleaved */
Expand Down
84 changes: 84 additions & 0 deletions formatTest/unit_tests/input/whitespace.re
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ module Test = {

};

/** recursive let bindings */

/* see below */

let foo = "abc"
and bar = "def"
and baz = "ghi";

/* with whitespace */

let foo = "abc"

and bar = "def"

and baz = "ghi";

/** with whitespace and attrs */

/* -> */

[@foo]
let foo = "abc"

[@bar]
and bar = "def"

[@baz]
and baz = "ghi";

module Comments = {

let z = 1;
Expand Down Expand Up @@ -177,6 +206,61 @@ module PatternMatching = {
};
};

/** recursive modules without whitespace */
module rec A: {type t; let a_fn: t => B.t; let of_float: float => t;} = {
type t = int;
let a_fn = x => B.of_int(x);
let of_float = x => int_of_float(x);
}
/* no whitespace */
and B: {type t; let another_fn: t => A.t; let of_int: int => t;} = {
type t = float;
let another_fn = x => A.of_float(x);
let of_int = x => float_of_int(x);
};

/** recursive modules with whitespace */

/* -> below */

module rec A: {type t; let a_fn: t => B.t; let of_float: float => t;} = {
type t = int;
let a_fn = x => B.of_int(x);
let of_float = x => int_of_float(x);
}

/** okok */

/* lala */

and B: {type t; let another_fn: t => A.t; let of_int: int => t;} = {
type t = float;
let another_fn = x => A.of_float(x);
let of_int = x => float_of_int(x);
};

/** recursive modules with attrs */

/* -> below */

[@foo1]
module rec A: {type t; let a_fn: t => B.t; let of_float: float => t;} = {
type t = int;
let a_fn = x => B.of_int(x);
let of_float = x => int_of_float(x);
}

/** okok */

/* lala */

[@foo2]
and B: {type t; let another_fn: t => A.t; let of_int: int => t;} = {
type t = float;
let another_fn = x => A.of_float(x);
let of_int = x => float_of_int(x);
};

module EdgeCase = {
let x = 1; /* a */

Expand Down
23 changes: 23 additions & 0 deletions formatTest/unit_tests/input/whitespace.rei
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,29 @@ and X2: Y2;
module rec X1: Y1
and X2: Y2;


/** rec modules with whitespace */

/* -> */

module rec X1: Y1

and X2: Y2;

/** rec modules with whitespace and attrs */

/* -> */

[@foo]
module rec X1: Y1

/** another one below */

/* random comment */

[@bar]
and X2: Y2;

/* notice the whitespace after the last signature item */

/* this one has whitespace interleaved */
Expand Down
Loading

0 comments on commit 3591742

Please sign in to comment.