Reason: [refmt] Add newline before each type alternative

Created on 27 May 2016  路  9Comments  路  Source: reasonml/reason

I think the formatter should add newlines before the | in type definitions.

/* input and desired(?) output */
type binTree 'x =
  | Node of (binTree 'x) (binTree 'x)
  | Leaf of 'x;

/* current refmt output */
type binTree 'x = | Node of (binTree 'x) (binTree 'x) | Leaf of 'x;
GOOD FIRST TASK

All 9 comments

It will add the newlines once it sees that the variant exceeds the width limit.

Jan, do you think it should always break lines? This would be super easy to do (see reason_pprint_ast.ml). Feel free to take a stab at it (tagging as good first task).

Btw I'm totally fine with it being on a single line; But if we keep that, removing the first | would be nice

I think for multiple alternatives(?) it seems like they're more readable on multiple lines, see the example on top. For really simple types you could make a case to put them on one line, like:

type decision = Yes | No | Maybe;

I might be more on the side of using more lines even if they technically fit on one line.

We cannot easily include a leading bar only if it breaks into multiple lines. You could send a pull request so that it always breaks when there is more than one variant leaf and only if needed when there is exactly one variant leaf.

I think it is ok to always break lines like:

type decision = 
   | Yes 
   | No
   | Maybe;

I'll give it a shot.

Another position on this: if the type definition is short enough to fit on one line and not self-evident enough, add comments, then it won't fit on one line anymore. :-)

Is there a difference between

type x = A;

and

type X = | A;
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gustavopinto picture gustavopinto  路  3Comments

jberdine picture jberdine  路  3Comments

braibant picture braibant  路  4Comments

rickyvetter picture rickyvetter  路  3Comments

chenglou picture chenglou  路  3Comments