Should we build a code formatter as a community?

I’m liking a lot rescript. It’s a wonderful effort to make reasonml simpler, and I’m really satisfied with the ecosystem and the seamless introduction of the language into a js / ts codebase.

However, the thing that makes my code really hard to read is the current formatting situation that we have. I find this really hard to read and edit:

  ->thenResolve(category => {
    category["path_from_root"]->Array.get(0)-> => category["name"])
  ->catch(_ => resolve(None))

Compared to this:

  ->thenResolve(category => {
      -> => category["name"])

Note that I’m a vim user, so moving and editing parts of the pipelines is easier when they are split in lines. There are more examples with jsx that the same applies.

It’s been months since there’s no improvements in this area, and I get it, the current team is busy with other things. Therefore, is it worth it to build a rescript formatting tool, or is the rescript format api coming with more customizations?


There is an open issue for this: Smart linebreak printer for pipe chains · Issue #257 · rescript-lang/syntax · GitHub
I think it is more productive to submit a PR, instead of creating a separate formatter.


Hum, I just read about how to do a pretty printer. Apparently is far more difficult than I thought :smiley:

Really interesting reads for anyone interested:


However, the thing that makes my code really hard to read is the current formatting situation that we have.

I agree, I’ve been trying to use the default formatter this last week but these long lines are making my code pretty difficult to read, I’m ready to disable it

It happens with JSX elements too, which I almost never want on the same line

  <div className={Css.pageModal}>
    <NavBar> <NavBar.Back /> <NavBar.Title> {React.string("Create Game")} </NavBar.Title> </NavBar>
    <div className={contentClass}>


  <div className={Css.pageModal}>
      <NavBar.Back /> 
        {React.string("Create Game")} 
    <div className={contentClass}>

I wish at a minimum there were config options, similar to eslintrc, to where we can disable certain parts of the formatter.

This is an example where someone from the community could first gauge interest and do some experimentation. See if there are gotchas, ux/dx or implementation issues. Prepare enough examples and present them to the community for feedback.
An area with no scarcity of opinions normally.


At least there should be a code standard - a must for any enterprise or bigger project.

Variable, module and function naming is sadly not possible to inspect statically, but there should be a standard for that too. OCaml has conventions for this, like string_of_int C-style, UPPERCASE for module signatures, CamelCase for modules, using t for the base type in a module, etc.