From 7f8b89ac105f20d8076ec91d0def539a8e0bdafe Mon Sep 17 00:00:00 2001 From: Yuku Kotani Date: Fri, 4 Oct 2019 04:39:22 +0900 Subject: [PATCH] Fix indent with get/set and line-separated variable assignment (#599) --- .../ktlint/ruleset/experimental/IndentationRule.kt | 10 ++++++++++ .../spec/indent/lint-property-accessor.kt.spec | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt index 8e5a0db6e3..34ad58b997 100644 --- a/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt +++ b/ktlint-ruleset-experimental/src/main/kotlin/com/pinterest/ktlint/ruleset/experimental/IndentationRule.kt @@ -968,6 +968,16 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { node.treeParent?.elementType.let { it == TYPE_PARAMETER_LIST || it == TYPE_ARGUMENT_LIST } -> 0 nextLeafElementType in rTokenSet -> -1 + // IDEA quirk: + // var value: DataClass = + // DataClass("too long line") + // private set + // + // instead of expected: + // var value: DataClass = + // DataClass("too long line") + // private set + node.nextCodeSibling()?.elementType == PROPERTY_ACCESSOR && node.treeParent.findChildByType(EQ)?.nextLeaf().isWhiteSpaceWithNewline() -> -1 else -> 0 } // indentation with all \t replaced diff --git a/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-property-accessor.kt.spec b/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-property-accessor.kt.spec index fbde03c0d1..2c334b4c42 100644 --- a/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-property-accessor.kt.spec +++ b/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-property-accessor.kt.spec @@ -28,7 +28,12 @@ class A { var setterWithAnnotation: Any? = null @Inject set + + var multilineInitialValue: String = + "tooooooooooooo loooooooooooooooong" + private set } // expect // 3:1:Unexpected indentation (4) (should be 8) +// 34:1:Unexpected indentation (12) (should be 8)