AdvancedExpressionFolding
AdvancedExpressionFolding copied to clipboard
Do not fold concatenation with new-line breaks that improve readability
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";
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 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 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.
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 😕
Here is another example when folding a line break makes readability worse:
Original:
Folded:
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.