Skip to content

Commit

Permalink
Fix indent of annotation array entry
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-dingemans committed Oct 31, 2022
1 parent 750f214 commit 33f8421
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -2,6 +2,7 @@ package com.pinterest.ktlint.ruleset.standard

import com.pinterest.ktlint.core.Rule
import com.pinterest.ktlint.core.ast.ElementType.ANNOTATED_EXPRESSION
import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION
import com.pinterest.ktlint.core.ast.ElementType.ANNOTATION_ENTRY
import com.pinterest.ktlint.core.ast.ElementType.FILE_ANNOTATION_LIST
import com.pinterest.ktlint.core.ast.ElementType.TYPE_ARGUMENT_LIST
Expand Down Expand Up @@ -80,7 +81,10 @@ public class AnnotationRule : Rule("annotation") {
checkForAnnotationToBePlacedOnSeparateLine(node, emit, autoCorrect)
}

if (node.isPrecededByOtherAnnotationEntry() && node.isOnSameLineAsAnnotatedConstruct()) {
if (node.treeParent.elementType != ANNOTATION &&
node.isPrecededByOtherAnnotationEntry() &&
node.isOnSameLineAsAnnotatedConstruct()
) {
checkForMultipleAnnotationsOnSameLineAsAnnotatedConstruct(node, emit, autoCorrect)
}
}
Expand Down
Expand Up @@ -538,4 +538,14 @@ class AnnotationRuleTest {
annotationRuleAssertThat(code)
.hasLintViolationWithoutAutoCorrect(1, 13, "Annotation with parameter(s) should be placed on a separate line prior to the annotated construct")
}

@Test
fun `Given an annotation with multiple annotation entries then do not force wrapping of the entries`() {
val code =
"""
@[JvmStatic Provides]
fun foo() = 42
""".trimIndent()
annotationRuleAssertThat(code).hasNoLintViolations()
}
}

0 comments on commit 33f8421

Please sign in to comment.