Skip to content

Commit

Permalink
make SpacingBetweenDeclarationsWithCommentsRule work correctly when t…
Browse files Browse the repository at this point in the history
…here are two comments above a declaration
  • Loading branch information
mgroth0 committed Jan 6, 2025
1 parent d6a5985 commit 97975eb
Showing 1 changed file with 2 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 97975eb

Please sign in to comment.