From 97975eb080e0ed45d3760d045cb5655cdf18e204 Mon Sep 17 00:00:00 2001 From: mgroth0 Date: Mon, 6 Jan 2025 13:24:00 -0500 Subject: [PATCH] make SpacingBetweenDeclarationsWithCommentsRule work correctly when there are two comments above a declaration --- .../rules/SpacingBetweenDeclarationsWithCommentsRule.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt index 406d41ce5d..e221c163a7 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/SpacingBetweenDeclarationsWithCommentsRule.kt @@ -8,6 +8,7 @@ import com.pinterest.ktlint.rule.engine.core.api.SinceKtlint.Status.STABLE import com.pinterest.ktlint.rule.engine.core.api.TokenSets import com.pinterest.ktlint.rule.engine.core.api.ifAutocorrectAllowed import com.pinterest.ktlint.rule.engine.core.api.isDeclaration +import com.pinterest.ktlint.rule.engine.core.api.isPartOfComment import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpace import com.pinterest.ktlint.rule.engine.core.api.isWhiteSpaceWithNewline import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling @@ -42,7 +43,7 @@ public class SpacingBetweenDeclarationsWithCommentsRule : StandardRule("spacing- ) { node .treeParent - .prevSibling() + .prevSibling { !it.isPartOfComment() } .takeIf { it.isWhiteSpace() && it.text.count { it == '\n' } < 2 } ?.let { whiteSpace -> emit(