android/kotlin-guides

Is there a rule for line break on chains?

Closed this issue · 3 comments

I feel very dumb asking this, which is supposedly simple, but I searched all over the documentation and couldn't find anything.

There are a few operations that take a lot of space. For instance, a Firebase call might be:

FirebaseFirestore
            .getInstance()
            .collection("meetings")
            .document(currentId)
            .collection("all")
            ...
            .whereEqualTo("kind", kind)
            .get()
            .addOnCompleteListener { ... }

Is there supposed to be any rule regarding this kind of thing? For example, always break the line when there are more than two operations/"." going on..
I'm not sure if it is non-existent because "common sense" is enough, someone forgot, or it is there, but I couldn't see.

Thanks!

There's no rule on how you break, only where you break: https://android.github.io/kotlin-guides/style.html#where-to-break, which you already have correct.

In general we'll likely defer to the Kotlin formatter from JetBrains in the Kotlin plugin on how it determines to break. And if you take issue with how it breaks (it's far from perfect since it's so new), issues should be filed on https://youtrack.jetbrains.com/issues/KT.

And most importantly, don't feel dumb! As evidenced by the fact that this was only just added to the Kotlin plugin in 1.2.20 we're all still figuring this out as we go.

Thanks Jake!!