AdvancedExpressionFolding icon indicating copy to clipboard operation
AdvancedExpressionFolding copied to clipboard

Do not fold concatenation with new-line breaks that improve readability

Open myhau opened this issue 7 years ago • 6 comments

Example (ignore nonsense where clauses):

String query = 
"SELECT * FROM table" +
"WHERE some_id > 1" +
"AND some_id > 2" +
"AND some_id > 3" +
"AND some_id > 4" +
"AND some_id > 5" +
"AND some_id > 6;"

should stay this way, and not be turned into:

String query = "SELECT * FROM table WHERE some_id > 1 AND some_id > 2 AND some_id > 3 AND some_id > 4 AND some_id > 5 AND some_id > 6";

myhau avatar Apr 28 '17 16:04 myhau

How do you decide what "improves readability" and what doesn't?

Maybe add a list of keywords to settings which if detected on either side will prevent folding. That would cover the first part of issue #73 by adding \n to the list, and for the example here, one could add AND.

petteyg avatar Jul 10 '17 17:07 petteyg

@petteyg that solution doesn't scale at all.

Who decides what is readible? The coder does. They have decided to make a multi line string because they decided it was more readible that way. Why would you change it to some other format?

Therefore, a more sensible method would be to leave the format as close to possible. Split on Java's AST syntax for multi line strings; not on the content inside the strings.

ciscorucinski avatar Jul 10 '17 19:07 ciscorucinski

@ciscorucinski The first sentence of what I typed is pretty clear as a rhetorical question; you just repeated it.

Maybe there is no case where you would actually want line breaks folded up, but I am not assuming there is no such case just because I can't think of one, so I suggested a solution that works both ways.

petteyg avatar Jul 10 '17 19:07 petteyg

I agree this matter should be fixed, or at least create some sort of configuration for it. It partially duplicates https://github.com/cheptsov/AdvancedExpressionFolding/issues/29 though 😕

jfcabral avatar Nov 11 '17 02:11 jfcabral

Here is another example when folding a line break makes readability worse:

Original: image

Folded: image

sabi0 avatar Feb 12 '18 11:02 sabi0

I am also having this issue. I would like there to be configuration options such as "do not fold concatenated string literals on separate lines" and "do not fold concatenated string literals that end with newlines". Hopefully this gets fixed soon.

Tisawesomeness avatar May 06 '21 19:05 Tisawesomeness