Reason: Refmt preserving spaces in modules.

Created on 22 Mar 2017  路  8Comments  路  Source: reasonml/reason

I'm not sure if the style that the reason team landed on was to not preserve spaces within module and module type, if so then disregard this issue.

An example is:
my code:

module type Example = {
  let example0: someArg0::string => string;

  let example1: someArg1::string => string;

  let example2: someArg2::string => string;
}

gets turned into:

module type Example = {
  let example0: someArg0::string => string;
  let example1: someArg1::string => string;
  let example2: someArg2::string => string;
};

Same thing happens with module:
my code:

module Example = {
  let example0 someArg0 => "0";

  let example1 someArg1 => "1";

  let example2 someArg2 => "2";
};

gets turned into:

module Example = {
  let example0 someArg0 => "0";
  let example1 someArg1 => "1";
  let example2 someArg2 => "2";
};

Now imagine if the functions weren't one liners and mixed with other values aside from functions. This gets very hard to read and sometimes you skip a line reading code or it's hard to tell where something may have ended. Not to take a shot at the regl codebase or anything but when reading it I confused often when a functions was indeed over. These spaces are helpful in showing what may be one unit or feature. Also makes me as a programmer psychologically more at ease when I see spaces. But maybe I'm just being stupid over these spaces.

  • this may not be exclusive to modules but this is where i've noticed spaces not being preserved.

Most helpful comment

Yes the core is ready, need to fix some issues with comments.

It'll group things of the same type & breaks if it's spreaded over multiple lines.

module Something = {
    type a = int;
    type b = string;

    let x = 1;
    let y = "test";

    let render {props, state} => {
        /* same type, e.g. a `let`, but has newline above for readability */
        let () = Lwt_main.run (something ());
        <div> props.x state.y </div>
    }
}

Whitespace will still be killed in the above example, because it's too short of a unit.
If let example3 consists of multiple lines, it'll get a newline above

module Example = {
  let example0 someArg0 => "0";
  let example1 someArg1 => "1";
  let example2 someArg2 => "2";

  let example3 () => {
      let a = 1;
      let b = 2;
      a + b
  };
};

All 8 comments

IIRC @IwanKaramazow was working on some automatic grouping/spacing changes for refmt which should address this.

Yes the core is ready, need to fix some issues with comments.

It'll group things of the same type & breaks if it's spreaded over multiple lines.

module Something = {
    type a = int;
    type b = string;

    let x = 1;
    let y = "test";

    let render {props, state} => {
        /* same type, e.g. a `let`, but has newline above for readability */
        let () = Lwt_main.run (something ());
        <div> props.x state.y </div>
    }
}

Whitespace will still be killed in the above example, because it's too short of a unit.
If let example3 consists of multiple lines, it'll get a newline above

module Example = {
  let example0 someArg0 => "0";
  let example1 someArg1 => "1";
  let example2 someArg2 => "2";

  let example3 () => {
      let a = 1;
      let b = 2;
      a + b
  };
};

That definitely looks like an improvement. That ending part where items that break get extra lines above them. Did someone specify that in a task, or did you intentionally/accidentally add it? It's interesting. I think it would work.

Someone else also suggested preserving additional newlines (any time you have n >= 1 blank lines, preserve and collapse to one line).

I just recently discovered Reason and have been browsing some public Reason projects. I'm having a hard time getting over the lack of newlines that are usually used to separate ideas or blocks of code. It makes understanding the code (and a new language) slightly more overwhelming than it needs to be.

Here's a sample before and after using refmt (Reason 2.0.0 @ 84e87c4): https://gist.github.com/rostero1/efa9dca43254380af28d9ab7eb4152b2

I'm also having a hard time dealing with being given no choice over structuring and grouping my code. For example, having a lot of big functions in a let rec ... and ... and ... block becomes almost unreadable. This is especially bad when mixing one-liners with large functions in the same let rec block. Not to mention not being able to separate statements in a { ... } block (where the assumption that every statement is short and can be compressed with the previous and the next statements often fails)

Someone else also suggested preserving additional newlines (any time you have n >= 1 blank lines, preserve and collapse to one line).

this would be perfect, imo. Agree with others that refmt removing newlines makes it a bit harder to navigate and read code

Someone else also suggested preserving additional newlines (any time you have n >= 1 blank lines, preserve and collapse to one line).

馃挴

This is prettier behavior and it works great imo.

Fixed =)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chenglou picture chenglou  路  3Comments

modlfo picture modlfo  路  4Comments

jberdine picture jberdine  路  3Comments

rickyvetter picture rickyvetter  路  3Comments

gustavopinto picture gustavopinto  路  3Comments