-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong indentation in a lambda #177
Comments
Mmm, looks like it's a result of 6c7dd8d I assume you're using dropbox style? it's lacking the extra indent we added for google-style. See the example at the very bottom of the commit. I think the way forward is to get rid of dropbox style, since it's not really maintained, and switch to 4/4 google style (and call it kotlinlang-style, maybe). |
Yeah, I am using dropbox-style. But currently, there is no way to use Google Style with any Gradle plugin no? I reproduced it in a test:
Result:
|
I am checking the commit:
This is strange because the lambda content is not indented based on the lambda, it is indented based on the function
shouldn't be this?
or with 2 indent:
|
IMO moving to kotlinlang-style is perfect, indeed I created a post in discussions. I am currently introducing ktfmt in the company I work, should be great if you could expose this style this week so I can test it in the PR I am already creating. Do you think it is possible or it is very soon? |
@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. |
This weirdness is a limitation of the underlying engine: google/google-java-format#556. |
I think some time ago it was not happening 🤔 If it is caused by this 6c7dd8d cannot be improved/reverted? |
Indeed, 6c7dd8d is the root cause. |
I agree and I can live with it trying to changing some large names to avoid this problem, don't worry :) |
Chiming in to say this issue has been reported internally within Google as well. Would be nice to find a fix, though I can respect the fact that it's complicated! |
@bethcutler do you know if it is fixed there? I have checked that this issue happens a lot when you are using ktor client |
Not a good new... google/google-java-format#19 (comment), not sure if it is the same. |
I wonder if this is also the cause of this issue with compose code which relies heavily on trailing lambdas: #249 |
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 6c7dd8d violates. In order to express 6c7dd8d 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. |
For tracking, this is how it looks like in 0.31 using kotlinlang style:
cc @strulovich |
What do you think about reverting @cgrushko. Personally don't see a lot of them
|
We (I) actually prefer reverting this - it was a feature request by Google, actually :) |
I've sent #280 to fix this issue, at least for the majority of cases. I'm still not sure the special case is worth it overall, but the fix isn't notably more complex than the current implementation. It might be easier to debate philosophy when there's no clear bug. |
I think this is already fixed, @cgrushko feels free to reopen if not. |
Introduced in
0.20
should be
The text was updated successfully, but these errors were encountered: