Discussion: Keeping previous whitespace for logically grouped code
Consider the following JavaScript which has been input into Prettier. Note that the developer has logically grouped together certain variables with deliberate use of whitespace:
logicalGrouping1 = 10
logicalGrouping2 = 20
secondLogicalGrouping1 = 10
secondLogicalGrouping2 = 20
doSomething()
The current version of Prettier for JavaScript will still keep the logical grouping of statements when creating the updated
logicalGrouping1 = 10;
logicalGrouping2 = 20;
secondLogicalGrouping1 = 10;
secondLogicalGrouping2 = 20;
doSomething();
However, the current prettier-ruby output will currently throw away this whitespace:
logicalGrouping1 = 10
logicalGrouping2 = 20
secondLogicalGrouping1 = 10
secondLogicalGrouping2 = 20
doSomething
Discussion:
Should prettier-ruby align with a similar result to the JavaScript prettier output, and keep some whitespace intact for readability? And if so, are there any thoughts on implementation details
I noticed that Ripper also drops comments from its sexpressions.
However, all of this information is in the original lexed token stream it seems:
[[3, 0], :on_ignored_nl, "\n"], # Blank new line
[[4, 0], :on_comment, "# comment\n"], # Comment
[[5, 0], :on_ident, "secondLogicalGrouping1"], # Logical grouping identifier
So maybe this is just another variation of the work to correlate sexpressions to tokens.
Yes, It does that. Also, I agree with the logical grouping part. It is in the plan, we can take it after covering most of the rubys ast