Formatting of multiline strings #1372
0x6675636b796f75676974687562
started this conversation in
Ideas
Replies: 1 comment 4 replies
-
I love this one:
May be we will force to move it to a new line ALWAYS? This one is also fine:
But I prefer the first one |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Abstract
In light of the recent fixes (#1364)) for the way we format multiline strings, it makes sense to agree on how exactly we format string literals which are not effective call arguments.
There're two aspects to consider:
"""
.LITERAL_STRING_TEMPLATE_ENTRY
nodes (at least, in the.trimMargin()
case).Ideas
Variants:
"""
as well as each line are aligned using a fractional indent size (not a multiple of 4, we can introduce a separate flag similar toalignedParameters
):"""
is indented, using a single or a continuation indent, w. r. t. the current indentation level, and string fragments which start with|
, use the same indentation level (we'd need a newextendedIndentInMultilineStrings
flag):extendedIndentInMultilineStrings
is on):"""
nor any fragments starting with|
are indented at all:All the above examples may feature
|
-fragments being additionally indented w. r. t. the closing"""
, optionally controlled by a separate flag, e. g.:Whenever a string literal is followed by a
.trimIndent()
call or a.trimXyz()
call or no call at all (we must handle this case, too),LITERAL_STRING_TEMPLATE_ENTRY
nodes should retain their original indentation, only the closing"""
should be indented.Existing style guides
Kotlin style guide says nothing about indentation (nor does IDEA) but provides these examples:
Additionally, the Java-to-Kotlin migration guide provides two extra examples:
(the closing
"""
indented once) and(the closing
"""
indented using 3 spaces which is probably a mistake).@akuleshov7, @Arrgentum, WDYT?
Beta Was this translation helpful? Give feedback.
All reactions