ktfmt: Wrong indentation in a lambda
Introduced in 0.20
class SomeClass {
fun aLongMethodWhereLambdaIsNotInTheSameLine(foo: String, bar: String, baz: String) =
someLambda {
someClass.someMethod(foo = foo, bar = bar, baz = baz)
}
}
should be
class SomeClass {
fun aLongMethodWhereLambdaIsNotInTheSameLine(foo: String, bar: String, baz: String) =
someLambda {
someClass.someMethod(foo = foo, bar = bar, baz = baz)
}
}
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 20 (19 by maintainers)
We (I) actually prefer reverting this - it was a feature request by Google, actually đ (it complicates the code and I agree it produces inconsistencies) @nreid260 - let me know.
On the Google side, weâre considering that it might be better to revert. Weâd prefer a formatting that is consistently adequate vs one that is usually good but fails a few percent of the time. Weâre also not sure whether presenting scoping function names on the same line is more readable, or just more terse.
I did some digging into how to fix this bug, and while itâs possible, itâs pretty hacky. The underlying problem is that google_java_format strongly adheres to the rectangle rule, which https://github.com/facebookincubator/ktfmt/commit/6c7dd8dd6aaf1daa7d6633efb78b924c2e534fe1 violates. In order to express https://github.com/facebookincubator/ktfmt/commit/6c7dd8dd6aaf1daa7d6633efb78b924c2e534fe1 formatting correctly, we need to futz around with conditional indents across many syntactic levels.
This issue is common to all âblock-like expressionsâ, which Kotlin has several of (e.g.
if,when). If we could add support for such constructs directly into google_java_format, it might make sense, but it currently isnât obvious how to do that. Until then, consistency across all block-like expressions is also desirable.@JavierSegoviaCordoba weâll try đ in the meanwhile, donât wait for us - clone the repo and build at head and see if itâs of use for you at all.