From 33f8421f5ed37c567445e38a542626f75f19a2d0 Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Mon, 31 Oct 2022 20:07:12 +0100 Subject: [PATCH] Fix indent of annotation array entry --- .../ktlint/ruleset/standard/AnnotationRule.kt | 6 +++++- .../ktlint/ruleset/standard/AnnotationRuleTest.kt | 10 ++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt index b2ebb72eec..4e7d8eef9e 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt @@ -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 @@ -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) } } diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt index 31c6166d85..3ebcaf478f 100644 --- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt +++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/AnnotationRuleTest.kt @@ -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() + } }