-
Notifications
You must be signed in to change notification settings - Fork 504
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
ktlint default settings disagree with IntelliJ IDEA Ultimate Edition on continuation indentation level (8 vs 12) #805
Comments
As per Kotlin styleguide itself, this should be indented with 4 spaces (nothing about continuation though). Imho if it's not implemented on IDEA side, it doesn't necessarily mean it's correct, it might just mean "not yet". |
Oh, disagreement within JetBrains - unexpected. |
Android style says about continuation that it should be 4: https://developer.android.com/kotlin/style-guide#block_tags As a kind-of-workaround you could add following to project [*.kt,*.kts]
continuation_indent_size=4 This should be picked up by IDEA kotlin style. |
Filed an issue in Kotlin to get some clarity from JB https://youtrack.jetbrains.com/issue/KT-41072 |
There are multiple other comments re. the completely unrelated issue, so I've decided to track it here since it's solely focusing on the original topic + I've already posted here the reference to JB's tracker |
This sort of folds into #816 as well really. I think it's worth consolidating to there |
I have a similar issue when a method is called within an "if" with multi-line parameters. It's definitely looks like a bug in ktlint. This code looks fine to me (and to Android Studio).
P.S. I started seeing multiple issues after upgrading ktlint from 0.31.0 to 0.38.1. I have manually verified that the settings of IntelliJ (Android studio) match the ktlint Readme. Deleting my .editorconfig file, and running "ktlint --android applyToIDEAProject" does not solve this issue. |
I'm getting an issue with this:
The errors I'm getting are I understand that there is an open ticket with Jetbrains to make it more explicit what the behaviour should be, but according to the code style:
I read that as being continuation indent should be a singular indent (4 spaces) and if there are any characters (e.g. |
The latest version of IntelliJ IDEA (2020.3) has an explicit setting on the page Editor ⇒ Code Style ⇒ Kotlin to Set from… where one can select Kotlin style guide. Interestingly, while this changes lots of stuff, the setting for Tabs and Indents, Continuation indent seems unaffected by this. It still defaults to 8, and when choosing Kotlin style guide, it remains at 8. When setting it to 4, and choosing Kotlin style guide again, it remains at 4. |
This issue has been relevant to me for a long while. I recommend ktlint to all Kotlin dev teams I advice at my company and at clients, and this crops up when using IntelliJ. The example I point to most:
vs
That JetBrains has not changed this for the life of their Kotlin plugin, nor is an option provided in IntelliJ, leads me to believe that--documented or not--8 spaces is the correct continuation indent. As remarked in Indent size for 'Method formatting' in plugin differs from official style guide:
And there seems to be some JB activity to correct an issue with Could ktlint be updated to use 8 spaces for continuation indents? |
8 space continuation indent is excessive, please don't. |
@ZacSweers I agree aesthetically with you on 8 spaces. However, my interest is in being "standard". I'd like ktllint to default out-of-the-box to whatever is standard Kotlin formatting. To address our own tastes, a configuration to adjust to 4 spaces would be a nice addition. |
Would that mean adding back support for continuation indent size which was removed here? #171 |
Apparently the Google Kotlin Style Guide for continuation indent has changed. Thus it is a migration strategy. We need to keep the old 8 space(2*4 space tab) continuation intent for a base line and merge slowly to 4 space continuation. Ktlint should have a settable continuation_indent configuration property that can be set in .editorconfig. |
This confuses me. JetBrains has provided a definition for standard Kotlin
style. Perhaps this kind of indentation is not covered? Without other
reasons, I follow that.
Brian Oxley
Principal Consultant
Email boxley@thoughtworks.com
Telephone +6 <+1+713+231+3265>5 8028 2709
[image: ThoughtWorks]
<http://www.thoughtworks.com/?utm_campaign=brian-oxley-signature&utm_medium=email&utm_source=thoughtworks-email-signature-generator>
…On Fri, Mar 5, 2021 at 4:59 AM qlihdunn ***@***.***> wrote:
Apparently the Google Kotlin Style Guide
<https://developer.android.com/kotlin/style-guide#indentation> for
continuation indent has changed. Thus it is a migration strategy. We need
to keep the old 8 space(2*4 space tab) continuation intent for a base line
and merge slowly to 4 space continuation. Ktlint should have a settable
continuation_indent configuration property that can be set in .editorconfig.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#805 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AIOR2SXCJ2QIGUCAOAECS6LTB7YD3ANCNFSM4OK746IQ>
.
|
It looks like there's an open IDEA issue regarding the use of continuation indent size. Kotlin official style guide recomments using *single* indent for continuations, however, IDEA wants to use double indent for some reason. So far ij_kotlin_continuation_indent_size = 4 workaround seems to be sufficient to make IDEA and ktlint format in the same way. https://youtrack.jetbrains.com/issue/KTIJ-17907 pinterest/ktlint#805
It looks like there's an open IDEA issue regarding the use of continuation indent size. Kotlin official style guide recomments using *single* indent for continuations, however, IDEA wants to use double indent for some reason. So far ij_kotlin_continuation_indent_size = 4 workaround seems to be sufficient to make IDEA and ktlint format in the same way. https://youtrack.jetbrains.com/issue/KTIJ-17907 pinterest/ktlint#805
Let's track the general continuation indent support in #816. As for the original report, I see there's some movement in https://youtrack.jetbrains.com/issue/KTIJ-17907, hopefully, the official styleguide will become a default one for editorconfig and bring less confusion |
The bug you're experiencing might have already be reported!
Please search in the issues before creating one.
⇒ Maybe duplicate of #558
Expected Behavior
Without any further configuration, ktlint expects the same formatting as applied by IntelliJ IDEA Ultimate Edition, because the latter is from JetBrains, the creators of Kotlin.
This includes the behavior about indentation.
IntelliJ IDEA uses 4 spaces for block indentation and 8 spaces for continuation indentation.
The following code snippet was formatted by IntelliJ IDEA Ultimate Edition 2020.1.2 without any modification of the code style settings.
The expected behavior is that ktlint accepts this code snipped as correctly formatted.
Observed Behavior
ktlint misbehaves regarding continuation indentation.
Although continuation indentation should be 8 spaces, ktlint expects continuation with 4 spaces instead.
Above example snippet triggers ktlint to report
Unexpected indentation (12) (should be 8)
.Steps to Reproduce
https://github.com/nelkinda/gameoflife-kotlin/tree/ktlint-805
Run
./gradlew build
Your Environment
The text was updated successfully, but these errors were encountered: