reasonml / reason

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

Remaining whitespace interleaving #1991

Open IwanKaramazow opened 6 years ago

IwanKaramazow commented 6 years ago

When https://github.com/facebook/reason/pull/1990 is merged, most cases where userland preservation of whitespace is absolutely a must-have, will be covered. There are other cases left, where whitespace preservation might make sense to group pieces of code together:

let make = (~greeting, _children) => { / spread the other default fields of component here and override a few / ...component,

initialState: () => {count: 0, show: true},

/ State transitions / reducer: (action, state) => switch (action) { | Click => ReasonReact.Update({...state, count: state.count + 1}) | Toggle => ReasonReact.Update({...state, show: ! state.show}) },

render: self => { let message = "You've clicked this " ++ string_of_int(self.state.count) ++ " times(s)";

( self.state.show ? ReasonReact.string(greeting) : ReasonReact.null )
; }, }; ``` - objects/classes Aside from jsx most things are trivial to implement now that the intelligent whitespace interleaving algorithm™ is in place. The question is, should we? Prettier/Gofmt implements all of these cases. Are there cases that are absolutely a must? In some cases (variants, record types?), it might hinder and introduce an extra burden on the developer.
bordoley commented 6 years ago

The record and module type formatting cases particularly impact fields which are documented in rei files and refmt removes whitespace before the document blocks.