From 33f8421f5ed37c567445e38a542626f75f19a2d0 Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Mon, 31 Oct 2022 20:07:12 +0100 Subject: [PATCH 1/3] 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() + } } From bc5d5dafdedde6d922a5be4290fe07032929892d Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Mon, 31 Oct 2022 20:08:31 +0100 Subject: [PATCH 2/3] update changelog Closes #1687 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26df1c6793..ee81c3251f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ if (node.isRoot()) { * Update Kotlin development version to `1.7.20` and Kotlin version to `1.7.20`. * CLI options `--debug`, `--trace`, `--verbose` and `-v` are replaced with `--log-level=` or the short version `-l=, see [CLI log-level](https://pinterest.github.io/ktlint/install/cli/#logging). ([#1632](https://github.com/pinterest/ktlint/issue/1632)) * In CLI, disable logging entirely by setting `--log-level=none` or `-l=none` ([#1652](https://github.com/pinterest/ktlint/issue/1652)) -* Rewrite `indent` rule. Solving problems in the old algorithm was very difficult. With the new algorithm this becomes a lot easier. Although the new implementation of the rule has been compared against several open source projects containing over 400,000 lines of code, it is still likely that new issues will be discovered. Please report your indentation issues so that these can be fixed as well. ([#1682](https://github.com/pinterest/ktlint/pull/1682), [#1321](https://github.com/pinterest/ktlint/issues/1321), [#1200](https://github.com/pinterest/ktlint/issues/1200), [#1562](https://github.com/pinterest/ktlint/issues/1562), [#1563](https://github.com/pinterest/ktlint/issues/1563), [#1639](https://github.com/pinterest/ktlint/issues/1639)) +* Rewrite `indent` rule. Solving problems in the old algorithm was very difficult. With the new algorithm this becomes a lot easier. Although the new implementation of the rule has been compared against several open source projects containing over 400,000 lines of code, it is still likely that new issues will be discovered. Please report your indentation issues so that these can be fixed as well. ([#1682](https://github.com/pinterest/ktlint/pull/1682), [#1321](https://github.com/pinterest/ktlint/issues/1321), [#1200](https://github.com/pinterest/ktlint/issues/1200), [#1562](https://github.com/pinterest/ktlint/issues/1562), [#1563](https://github.com/pinterest/ktlint/issues/1563), [#1639](https://github.com/pinterest/ktlint/issues/1639), [#1687](https://github.com/pinterest/ktlint/issues/1687)) ## [0.47.1] - 2022-09-07 From 22ea60fa7e19c8bef2adda9a1432bb72eb49fc7f Mon Sep 17 00:00:00 2001 From: paul-dingemans Date: Mon, 31 Oct 2022 20:09:59 +0100 Subject: [PATCH 3/3] update changelog Closes #1688 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ee81c3251f..4440958d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ if (node.isRoot()) { * Update Kotlin development version to `1.7.20` and Kotlin version to `1.7.20`. * CLI options `--debug`, `--trace`, `--verbose` and `-v` are replaced with `--log-level=` or the short version `-l=, see [CLI log-level](https://pinterest.github.io/ktlint/install/cli/#logging). ([#1632](https://github.com/pinterest/ktlint/issue/1632)) * In CLI, disable logging entirely by setting `--log-level=none` or `-l=none` ([#1652](https://github.com/pinterest/ktlint/issue/1652)) -* Rewrite `indent` rule. Solving problems in the old algorithm was very difficult. With the new algorithm this becomes a lot easier. Although the new implementation of the rule has been compared against several open source projects containing over 400,000 lines of code, it is still likely that new issues will be discovered. Please report your indentation issues so that these can be fixed as well. ([#1682](https://github.com/pinterest/ktlint/pull/1682), [#1321](https://github.com/pinterest/ktlint/issues/1321), [#1200](https://github.com/pinterest/ktlint/issues/1200), [#1562](https://github.com/pinterest/ktlint/issues/1562), [#1563](https://github.com/pinterest/ktlint/issues/1563), [#1639](https://github.com/pinterest/ktlint/issues/1639), [#1687](https://github.com/pinterest/ktlint/issues/1687)) +* Rewrite `indent` rule. Solving problems in the old algorithm was very difficult. With the new algorithm this becomes a lot easier. Although the new implementation of the rule has been compared against several open source projects containing over 400,000 lines of code, it is still likely that new issues will be discovered. Please report your indentation issues so that these can be fixed as well. ([#1682](https://github.com/pinterest/ktlint/pull/1682), [#1321](https://github.com/pinterest/ktlint/issues/1321), [#1200](https://github.com/pinterest/ktlint/issues/1200), [#1562](https://github.com/pinterest/ktlint/issues/1562), [#1563](https://github.com/pinterest/ktlint/issues/1563), [#1639](https://github.com/pinterest/ktlint/issues/1639), [#1688](https://github.com/pinterest/ktlint/issues/1688)) ## [0.47.1] - 2022-09-07