question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong indentation in a lambda

See original GitHub issue

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)
        }
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:20 (19 by maintainers)

github_iconTop GitHub Comments

1reaction
cgrushkocommented, Feb 10, 2022

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.

1reaction
nreid260commented, Feb 7, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found