Request for new style rules

I’d like to request that IntelliJ’s Kotlin formatter (and default style guide) weigh in on the following formatting topics. I don’t care much what is chosen, but these are sources of inconsistency in our relatively large Kotlin codebase and it’d be nice if the autoformatter could fix it:

Bracket placement on multi-line function calls:

val foo = Bar(
      1,
      2,
      3)

I like to write it symmetrically, like this, but not everyone does:

val foo = Bar(
      1,
      2,
      3
)

Blank lines at the top of class definitions (but not the bottom):

class Foo {

    fun bar()
}

This one really triggers my code formatting OCD for some reason. I have tried to get to the bottom of why this happens but it seems lots of people just do it that way: there’s nothing obvious in the IDE that causes this.

Getters on the same line or next:

val foo: Bar
    get() = whatever

vs

val foo: Bar get() = whatever

I prefer code to be vertically compact where possible and when it does not reduce the utility of line-based code coverage tools … but not everyone does.

For loops vs forEach - two very similar constructs with very similar syntaxes:

for (foo in foos) { foo.thing() }

vs

foos.forEach { it.thing() }

I prefer the traditional for form, seeing as that’s what forEach becomes anyway and it encourages you to pick a more meaningful iterator name than it, but I’m happy with either. Having a random mix sucks though!

I’m sure other people have similar peeves!

edit: thought of another

Hi Mike,

Please check out https://github.com/yole/kotlin-style-guide and file issues there for those things that aren’t covered by existing recommendations yet.