ktfmt
ktfmt copied to clipboard
Annotations get collapsed to the same line as code it affects
We are using ktfmt with the following gradle config
ktfmt {
kotlinLangStyle()
}
The issue that annotations get formatted on the same line, e.g. we get lines like
@Serializable @SerialName("native:live") object NativeLive : SpecificSettings()
@Serializable @SerialName("native:self-paced") object NativeSelfPaced : SpecificSettings()
The Kotlinx documentation all have the annotations on different lines and I noticed that in ktfmt you also have annotations on different lines.
We would very much like ktfmt to format this like
@Serializable
@SerialName("native:live")
object NativeLive : SpecificSettings()
@Serializable
@SerialName("native:self-paced")
object NativeSelfPaced : SpecificSettings()
Using ktfmt version 0.43.0
Many thanks.
@strulovich , I remember you have thoughts on this?
If I recall correctly, the main reason we are at this state is since similar multiline formatting for annotated parameters look really bad.
- We went back and forth whether to handle annotations with params differently (as the Kotlin guidelines suggests). In the end I think we do not, since it created many awkward instances.
- Breaking annotations can make a list of annotated items look very awkward if the items are short. (It take a nicely formatted 5 lines turning them to 20 ones).
- We can consider treating formatting differently according to the annotated target (i.e. treat properties differently than top level objects), but I think that will be a time sink with very little value.
Overall, this is basically working as intended right now. Without really strong support and argument to do it the opposite way I think we should keep it as is.
Ok thanks for your comments
Is there any progress?
There's no progress here. Also see https://github.com/facebook/ktfmt/issues/226
See this comment here https://github.com/facebook/ktfmt/pull/435#issuecomment-2000099557
Also this would violate this principle here that we try to follow for ktfmt