Bsrefmt or refmt? with vscode + reason-vscode 1.5.2


#1

I am noticing some differences with reason-vscode’s formatting, and the older refmt command which I had installed by via https://github.com/reasonml/reason-cli

$ yarn global list
yarn global v1.13.0
info "bs-platform@4.0.18" has binaries:
   - bsb
   - bsc
   - bsrefmt

reason-vscode formats identically as bsrefmt, I believe, for example

let sqr = x => {
  x * x;
};

The older refmt cli tool, however, formatted the same function as:

let sqr = x => x * x;

The question: Is bsrefmt the current standard for reason-ml formatting? Is reason-cli just deprecated?

PS, reason-vscode is awesome. Truly enjoyable developer experience!


#2

I’m wondering about this, too. Am I understanding correctly that there are currently two formatters?

I’m using emacs (which I understand isn’t fully supported at the moment), which uses refmt, whereas the rest of my team uses vscode, which formats things a bit differently. When I save a file that they’ve worked on, I can choose to either:

  1. not format it at all
  2. format it using refmt, which creates a lot of commit noise and isn’t compatible with what my team’s formatting considers “correct”
  3. jump into vscode and format it there

edit: It’s also possible that my settings for refmt (such ad line width) simply don’t match my team’s yet. Maybe refmt and bsrefmt are at parity after all?


#3

If I remember correctly, bsrefmt is refmt, just the version can be different.


#4

Each BuckleScript version comes with a precompiled refmt version. They called it bsrefmt to prevent PATH naming collisions. Other than that, you could theoretically use any refmt version as long as you build up a PATH variable which makes the reason-vscode extension pick it up correctly.

BuckleScript occasionally copies over newer refmt version whenever there were important updates. For consistency reasons, it’s usually recommended to go with the bsrefmt over any other globally installed refmt version (makes it easier to have reproducible results on CI and your coworkers machine).

reason-cli itself is quite obsolete afaik


#5

To answer your question about the braces, what happened is refmt started keeping braces rather than optimising them away for a single expression.

Now if only they’d stop optimising open X;expression; to X.(expression);


#6

I have to say I also got the feeling that refmt tends to make code more verbose by adding or at least not removing braces, by adding extra lines in certain constructs, or as spyder mentioned, by using local opens. But I guess that’s also a matter of personal taste.