From 260a977c034c321a3bdefe471cd5b76a98e44ae2 Mon Sep 17 00:00:00 2001 From: Sha Sha Chu Date: Fri, 19 Apr 2019 16:57:04 -0700 Subject: [PATCH] Include annotations in parameter indentation checks. Fixes https://github.com/pinterest/ktlint/issues/374 --- .../ktlint/ruleset/experimental/IndentationRule.kt | 3 ++- .../spec/indent/format-parameter-list-expected.kt.spec | 7 +++++++ .../resources/spec/indent/format-parameter-list.kt.spec | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) 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 9e58df4a59..f1526d00ab 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 @@ -3,6 +3,7 @@ package com.pinterest.ktlint.ruleset.experimental import com.pinterest.ktlint.core.EditorConfig import com.pinterest.ktlint.core.KtLint import com.pinterest.ktlint.core.Rule +import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION import com.pinterest.ktlint.core.ast.ElementType.ARROW import com.pinterest.ktlint.core.ast.ElementType.BINARY_EXPRESSION import com.pinterest.ktlint.core.ast.ElementType.BINARY_WITH_TYPE @@ -280,7 +281,7 @@ class IndentationRule : Rule("indent"), Rule.Modifier.RestrictToRootLast { ) { for (c in node.children()) { if ( - (c.elementType == VALUE_PARAMETER || c.elementType == VALUE_ARGUMENT) && + (c.elementType == VALUE_PARAMETER || c.elementType == VALUE_ARGUMENT || c.elementType == ANNOTATION) && c.textContains('\n') ) { // rearrange diff --git a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list-expected.kt.spec b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list-expected.kt.spec index e599705637..7eb9d53dad 100644 --- a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list-expected.kt.spec +++ b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list-expected.kt.spec @@ -17,3 +17,10 @@ class C ( } } +class TestClass( + @Id @NotNull + @Column( + nullable = false + ) + val id: String +) diff --git a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list.kt.spec b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list.kt.spec index d394993673..cb0c6c9752 100644 --- a/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list.kt.spec +++ b/ktlint-ruleset-experimental/src/test/resources/spec/indent/format-parameter-list.kt.spec @@ -9,3 +9,10 @@ class C (val a: Int, val b: Int, val e: ( } } +class TestClass( + @Id @NotNull + @Column( + nullable = false + ) + val id: String +)