From 6a71b770d96700b972f8436d371074e6b3e9ede5 Mon Sep 17 00:00:00 2001 From: Sha Sha Chu Date: Wed, 3 Jul 2019 00:36:04 -0700 Subject: [PATCH] Fix AnnotationRule exception * Return if there's no annotations found instead of throwing an exception * Fies https://github.com/pinterest/ktlint/issues/490 --- .../com/pinterest/ktlint/ruleset/standard/AnnotationRule.kt | 4 +++- 1 file changed, 3 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 e5f2d11ef7..cdc892f1dc 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 @@ -31,7 +31,9 @@ class AnnotationRule : Rule("annotation") { root.children() .mapNotNull { it.psi as? KtAnnotationEntry } .toList() - check(!annotations.isEmpty()) { "Annotations list should not be empty" } + if (annotations.isEmpty()) { + return + } // Join the nodes that immediately follow the annotations (whitespace), then add the final whitespace // if it's not a child of root. This happens when a new line separates the annotations from the annotated