From 532f03c1bd5c029d1a0d2ecd42a04455947b13f2 Mon Sep 17 00:00:00 2001 From: Sha Sha Chu Date: Wed, 3 Jul 2019 00:08:00 -0700 Subject: [PATCH] Fixing bug with extra indentation after lambda arrow Fixes https://github.com/pinterest/ktlint/issues/479 --- .../ktlint/ruleset/experimental/IndentationRule.kt | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 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 055609684a..c33a229e0c 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 @@ -707,11 +707,14 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { } private fun adjustExpectedIndentAfterArrow(n: ASTNode, ctx: IndentContext) { - val prevBlockLine = ctx.blockOpeningLineStack.peek() ?: -1 - if (prevBlockLine != line) { - expectedIndent++ - debug { "++after(ARROW) -> $expectedIndent" } - ctx.exitAdjBy(n.treeParent, -1) + // Only adjust indents for arrows inside of when statements. Lambda arrows should not increase indent. + if (n.treeParent?.elementType == WHEN_ENTRY) { + val prevBlockLine = ctx.blockOpeningLineStack.peek() ?: -1 + if (prevBlockLine != line) { + expectedIndent++ + debug { "++after(ARROW) -> $expectedIndent" } + ctx.exitAdjBy(n.treeParent, -1) + } } }