From d06f10f0205956cd70eca96a34296327fb07cb3d Mon Sep 17 00:00:00 2001 From: Stanley Shyiko Date: Thu, 29 Mar 2018 11:34:17 -0700 Subject: [PATCH] Disabled intent check inside `where ` (#180) --- .../ktlint/ruleset/standard/IndentationRule.kt | 5 +++-- .../ruleset/standard/IndentationRuleTest.kt | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt index 7a0c91fe0b..3f694ec168 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRule.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.psi.KtSafeQualifiedExpression import org.jetbrains.kotlin.psi.KtSecondaryConstructor import org.jetbrains.kotlin.psi.KtSuperTypeList import org.jetbrains.kotlin.psi.KtSuperTypeListEntry +import org.jetbrains.kotlin.psi.KtTypeConstraintList import org.jetbrains.kotlin.psi.KtTypeProjection import org.jetbrains.kotlin.psi.KtValueArgumentList import org.jetbrains.kotlin.psi.psiUtil.getPrevSiblingIgnoringWhitespaceAndComments @@ -39,9 +40,9 @@ class IndentationRule : Rule("indent") { if (indentSize <= 0 || continuationIndentSize <= 0) { return } - if (node is PsiWhiteSpace && !node.isPartOf(PsiComment::class)) { + if (node is PsiWhiteSpace) { val lines = node.getText().split("\n") - if (lines.size > 1) { + if (lines.size > 1 && !node.isPartOf(PsiComment::class) && !node.isPartOf(KtTypeConstraintList::class)) { var offset = node.startOffset + lines.first().length + 1 val previousIndentSize = node.previousIndentSize() val expectedIndentSize = if (continuationIndentSize == indentSize || shouldUseContinuationIndent(node)) diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt index c797a48d07..0329e9a9c5 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/github/shyiko/ktlint/ruleset/standard/IndentationRuleTest.kt @@ -386,4 +386,19 @@ class IndentationRuleTest { LintError(7, 1, "indent", "Unexpected indentation (1) (it should be 8)") )) } + + @Test(description = "https://github.com/shyiko/ktlint/issues/180") + fun testLintWhereClause() { + assertThat(IndentationRule().lint( + """ + class BiAdapter( + val adapter1: A1, + val adapter2: A2 + ) : RecyclerView.Adapter() + where A1 : RecyclerView.Adapter, A1 : ComposableAdapter.ViewTypeProvider, + A2 : RecyclerView.Adapter, A2 : ComposableAdapter.ViewTypeProvider { + } + """.trimIndent() + )).isEmpty() + } }