From bcbfe986caa9f938e03649681c59fbb273a0c971 Mon Sep 17 00:00:00 2001 From: Monchi Date: Sun, 20 Oct 2019 23:52:07 +0900 Subject: [PATCH 1/2] Fix indentation with lambda --- .../ktlint/ruleset/experimental/IndentationRule.kt | 5 +++-- .../src/test/resources/spec/indent/lint-string.kt.spec | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) 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 297ab4cbcf..6051cf2680 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 @@ -613,7 +613,7 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { } private fun adjustExpectedIndentInsideQualifiedExpression(n: ASTNode, ctx: IndentContext) { - val p = n.treeParent + val p = n.parent({ it.treeParent.elementType != DOT_QUALIFIED_EXPRESSION }) ?: return val nextSibling = n.treeNext if (!ctx.ignored.contains(p) && nextSibling != null) { expectedIndent++ @@ -628,7 +628,8 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { } else { nextSibling } - ctx.exitAdjBy(e, -1) + ctx.ignored.add(p) + ctx.exitAdjBy(p, -1) } } diff --git a/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-string.kt.spec b/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-string.kt.spec index cd8b198467..ca9be19f98 100644 --- a/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-string.kt.spec +++ b/ktlint-ruleset-experimental/src/test/resources/spec/indent/lint-string.kt.spec @@ -19,4 +19,11 @@ fun f4() = "${ true }" +fun f5() { + Integer + .parseInt("32").let { + println("parsed $it") + } +} + // expect From 39f94483a468218b7eb85867ef6de9a428e35a2a Mon Sep 17 00:00:00 2001 From: Monchi Date: Sun, 20 Oct 2019 23:54:46 +0900 Subject: [PATCH 2/2] Add test for format --- .../src/test/resources/spec/indent/format-expected.kt.spec | 7 +++++++ .../src/test/resources/spec/indent/format.kt.spec | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-expected.kt.spec b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-expected.kt.spec index e7da7128c1..a0adf508b5 100644 --- a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-expected.kt.spec +++ b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-expected.kt.spec @@ -42,6 +42,13 @@ public class ThisIsASampleClass : } } + fun foo3() { + Integer + .parseInt("32").let { + println("parsed $it") + } + } + private val f = { a: Int -> a * 2 } diff --git a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format.kt.spec b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format.kt.spec index 90690aa987..aedc7832ce 100644 --- a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format.kt.spec +++ b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format.kt.spec @@ -42,6 +42,13 @@ return 2 } } +fun foo3() { +Integer +.parseInt("32").let { +println("parsed $it") +} +} + private val f = { a: Int -> a * 2 }