ktlint icon indicating copy to clipboard operation
ktlint copied to clipboard

Could we get back the support for continuation indent?

Open yongce opened this issue 3 years ago • 18 comments

It seems that ktlint v0.37.0 removed the support for continuation indent. Now all indents are 4 spaces. It would be great if there is a config option for it, so that we can make the decision for the projects.

yongce avatar Jul 19 '20 10:07 yongce

probably we could use ij_continuation_indent_size .editorconfig property

Unfortunately there is no standard .editorconfig property for this, see https://github.com/editorconfig/editorconfig/issues/412

Tapchicoma avatar Jul 20 '20 14:07 Tapchicoma

Also, the indentation rule does not really support it in the current state I think

romtsn avatar Jul 21 '20 08:07 romtsn

This removal basically prevents us from updating ktlint, as eating this kind of line cost in our codebase for a change that disagrees with the IDE style's built-in rules is too much image

ZacSweers avatar Jul 30 '20 06:07 ZacSweers

@ZacSweers the problem is that the old indentation rule was pretty dumb and also did not support auto-formatting, it was just reporting some issues, so I guess these changes are not solely caused by the absence of the continuation indent support.

I think we'd be happy to bring it back after the split of the indentation rule, but there are also some misalignments on JetBrains' side (e.g. #805) that have to be clarified first.

romtsn avatar Aug 04 '20 16:08 romtsn

I did a cursory glance around the changed files and ~99% of the couple dozen I checked were related to the continuation indent change.

ZacSweers avatar Aug 04 '20 16:08 ZacSweers

Interesting, could you drop a few examples?

romtsn avatar Aug 04 '20 16:08 romtsn

We could definitely consider this. Like @romtsn said, at the time the now-standard Indent rule was written, it greatly simplified the implementation to not support continuation indent. But if we're trying to converge on IDEA and ktlint formatting things the same, it does seem like something we need to support.

shashachu avatar Aug 04 '20 16:08 shashachu

Is there any progress on this issue? This seems to become a blocker for Kotlin 1.4.0. Our Square code style has a specific continuation indent that we don't like to drop. It would be sad if we'd need to disable the indent rule only to get access to the newer version that's compiles with Kotlin 1.4.0.

vRallev avatar Aug 15 '20 22:08 vRallev

No progress so far, we were planning to split the rule itself first so it gets easier to disable and also change it. But it seems we need to prioritize it now. I am just curious, do you use continuation indent on some custom code blocks that are different from the official styleguide? By that I mean this: image

If the answer is yes, then we'd also need to bring support for this via editorconfig

romtsn avatar Aug 16 '20 12:08 romtsn

We use the continuation indent there. Screen Shot 2020-08-16 at 9 46 14 PM

vRallev avatar Aug 17 '20 04:08 vRallev

you can set a config rule to disable this check indent_size = unset

Denchick1 avatar Aug 19 '20 09:08 Denchick1

Unable to update Detekt because of this, which in turn is preventing us from updating to Kotlin 1.4.

eygraber avatar Aug 21 '20 03:08 eygraber

I guess this feature didn't make it into the 0.39.0 release, did it?

vRallev avatar Sep 14 '20 23:09 vRallev

No, planned for next release.

Tapchicoma avatar Sep 15 '20 11:09 Tapchicoma

Unable to update Detekt because of this, which in turn is preventing us from updating to Kotlin 1.4.

@eygraber I have ktlint set up separately with kotlinter and I'm not leveraging the Detekt formatting plugin. When updating Detekt, a higher version of ktlint was brought in as a transitive dependency and broke the build. If you're in the same boat, then this temporary work-around could be helpful. If you're using the formatting plugin, you can try a similar strategy of forcing the versions of the transitive dependencies (and cross your fingers that it works.) These docs and the buildEnvironment gradle task are helpful in verification.

buildscript {
  dependencies {
    classpath("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:$VERSION") {
      exclude group: "com.pinterest.ktlint"
    }
  }
}

Sorry for the off-topic, but I figured this might help what I suspect will be a growing amount of people arriving at these threads after completing some routine version bumps. I'm anxiously awaiting these changes :)

patrickpilch avatar Sep 16 '20 19:09 patrickpilch

@patrickpilch thanks for that. Unfortunately it wasn't able to help us. Wish this issue didn't keep getting bounced to future releases :disappointed:

eygraber avatar Mar 01 '21 07:03 eygraber

I think this may have been fixed? I updated to latest, removed the indent_size = unset rule and ktlint doesn't fail? I'm still somewhat ignorant to the issue (I encountered it once and blindly copy pasted the unset rule above), but just pointing out that it seems to be all good on my end.

EDIT: Actually nevermind. Somehow it's passing locally but not on CI. I'm running ktlintCheck on both. Really unsure what's going on.

Edit 2: Added back in the indent_size rule and CI now passes. No idea what's going on.

ColtonIdle avatar Mar 10 '21 19:03 ColtonIdle

Hey - 0.41.0 was released but doesn't mention this. We're seeing new issues when trying it out as well, where it fails due to expecting a larger continuation indent when we define 2.

@ColtonIdle this issue is about continuation indent, indent_size is irrelevant to this

ZacSweers avatar Mar 30 '21 01:03 ZacSweers

As described here the continuation indent has been dropped in the default IntellI IDEA formatter.

paul-dingemans avatar Aug 16 '22 19:08 paul-dingemans