reasonml / reasonml/reason

refmt indent bug and undesired wrapping with inline first-class modules

Open
#1,605 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

KIND: FEATURE REQUEST Printer
Dominant language
OCaml
Stars
10.3k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

Given a simple module type:

module type MyModule = {
  let f1: int => bool;
  let f2: bool => int;
};

Here is a rough idea of how I'd like an inline first-class module to be formatted, similar to records:

let anonymousModule: (module MyModule) = (module {
  let f1 = (a) => true;
  let f2 = (b) => 1;
});

However this is what I get:

let anonymousModule: (module MyModule) =
  (module
   {
     let f1 = (a) => true;
     let f2 = (b) => 1;
   });

There are two problems here:

  • the line wrapping after (module adds a single space indent, so every line inside is now an odd number instead of an even number
  • there are too many lines and indents. It could perhaps be argued that (module { deserves it's own line, but it doesn't get one when formatting records. I'm on the verge of switching from modules to records for this reason.

Here's the hacky way I'm working around this at the moment, partly to avoid the indent bug but also because of a vscode syntax issue with the above style (which I'm about to log separately):

let anonymousModule: (module MyModule) = {
  module R = {
    let f1 = (a) => true;
    let f2 = (b) => 1;
  };
  (module R)
};

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the input, current output, and desired output in the issue, then locate the formatter logic for inline first-class modules and compare it with record formatting. Done means the output avoids the unwanted wrapping and uses even, consistent indentation while preserving valid Reason syntax.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.