Open scott-avery opened 12 months ago
+1000 on improving the formatting of text blocks, for me I find I use .formatted()
at the end of them often and that also drops to the next line which looks ugly, kinda lie:
var text =
"""
update master_data_manager
set version = version + 1, update_time = now(), update_by = #{userId}
where site_id = %s and table_name = #{tableName}
"""
.formatted("site");
Ideally, the opening """
would also be hanging, and the code following on the same line, something like:
var text = """
update master_data_manager
set version = version + 1, update_time = now(), update_by = #{userId}
where site_id = %s and table_name = #{tableName}
""".formatted("site");
would be ideal.
Example from a wiremock test case. A beauty in its own... don't you think? 😉
If memory serves, we don’t currently format text blocks, only the code around them. This is due to their structure being both a string a block which is indention-sensitive. Definitely room for improvement on this :-)
@carterkozak From memory, javac automatically strips away the incidental/grey white space (the initial indentation on the first line of the text block), so changing that initial base indentation shouldn't cause any issues - as long as any additional indentation is respected.
+1 to get something more common/standard and less unlikely by default, formatting should stay well readable after all ;)
javac automatically strips away the incidental/grey white space (the initial indentation on the first line of the text block), so changing that initial base indentation shouldn't cause any issues - as long as any additional indentation is respected.
+1, there is a nice overview here: https://docs.oracle.com/en/java/javase/21/text-blocks/index.html#incidental-white-space
For what it's worth, the approach google-java-format is currently taking for text blocks is to re-indent them to the current continuation indent (see here).
@CRogers any chance we can get an update here?
Another example case:
What happened?
this tool formats text block in not ideal format.
see original verion.
output
What did you want to happen?
keep the same as original.