Sam Pengilly
10/18/2023, 5:16 AM// This example of a typically formatted long property initialiser
val someProperty: SomeType =
someInitialiser.thatIsQuiteLong()
// Example of how this should look with property delegation if it followed the same pattern
// This is what detekt/ktlint expect with their formatting rules for continuation indent
val someDelegatedProperty: SomeType by
someDelegateInitialiser.thatIsQuiteLong()
// This is what IntelliJ does when you run an auto-format on the file
val someDelegatedProperty: SomeType by
somedelegateInitialiser.thatIsQuiteLong()
// Doesn't matter if you put the "by" on the upper line or the lower line, IntelliJ auto-format removes the continuation indent
// Another option when the initialiser is a function might be
val someDelegatedProperty: SomeType by someDelegateFunc(
someArgument
)
// But this doesn't look great when you want to follow up with a "private set"
val someDelegatedProperty: SomeType by someDelegateFunc(
someArgument
)
private set
// Plus it still forces a potentially long line by keeping the function name up on the starting line
Anton Mefodichev
11/13/2023, 1:35 PM