Wrong indentation in a lambda
See original GitHub issueIntroduced 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)
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:20 (19 by maintainers)
Top Results From Across the Web
Wrong indentation in a lambda · Issue #177 · facebook/ktfmt
Yeah, I am using dropbox-style. But currently, there is no way to use Google Style with any Gradle plugin no? I reproduced it...
Read more >Incorrect indentation for a lambda function - Stack Overflow
I am doing a direct combination of 2 functions using a lambda function. Because indentation is a problem I am doing direct copy/paste...
Read more >C# Multiline Lambda Indentation in Fluent API Incorrect
In Visual Studio for Mac multi-line lambdas written inside a "fluent" API method don't indent correctly. They have a tendency to auto-indent to...
Read more >Wrong indentation in lambda after type <enter> : CPP-16144
STR. Set indent in lambda to 10 in Preferences | Editor | Code Style | C/C++; press enter in the next code. int...
Read more >Formatting - Makes incorrect indentation in lambda expressions
When using autoformat to format source code in a C# file with CodeRush, the indentation of closing braces is incorrect after a method...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.