reasonml / reason

Simple, fast & type safe code that leverages the JavaScript & OCaml ecosystems
http://reasonml.github.io
MIT License
10.08k stars 425 forks source link

[refmt] Add env variable to configure --print-width #2687

Closed davesnx closed 1 year ago

davesnx commented 1 year ago

The workaround is to have an env variable to set the wrapping width for printing. It should unblock https://github.com/reasonml/reason/issues/2567 and delay the discussion about the need for a config file.

This unblocks editor integrations to configure it however they want it.

$ echo "let initialState = uiStateFromValidated(~ownership=RemoteData.NotAsked, ~limits=initialLimits, SiteAuditSettings.default);" | REFMT_PRINT_WIDTH=80 esy x refmt
let initialState =
  uiStateFromValidated(
    ~ownership=RemoteData.NotAsked,
    ~limits=initialLimits,
    SiteAuditSettings.default,
  );

$ echo "let initialState = uiStateFromValidated(~ownership=RemoteData.NotAsked, ~limits=initialLimits, SiteAuditSettings.default);" | REFMT_PRINT_WIDTH=120 esy x refmt
let initialState =
  uiStateFromValidated(~ownership=RemoteData.NotAsked, ~limits=initialLimits, SiteAuditSettings.default);

This PR also adds cram tests, which tests refmt end to end, and are a little nicer than our test.sh:

SanderSpies commented 1 year ago

LGTM.