prettier-ruby icon indicating copy to clipboard operation
prettier-ruby copied to clipboard

Discussion: Keeping previous whitespace for logically grouped code

Open AlanFoster opened this issue 7 years ago • 2 comments

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

AlanFoster avatar Jun 03 '18 01:06 AlanFoster

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.

AlanFoster avatar Jun 03 '18 10:06 AlanFoster

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

iamsolankiamit avatar Jun 03 '18 12:06 iamsolankiamit