From efd32be7bbd3f32eb999c5328b1fa34acf4f7c6f Mon Sep 17 00:00:00 2001 From: mgroth0 Date: Tue, 10 Dec 2024 04:21:41 -0500 Subject: [PATCH] remove psi from BlankLineBeforeDeclarationRule --- .../standard/rules/BlankLineBeforeDeclarationRule.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt index 8b02750821..3d41d479a6 100644 --- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt +++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/rules/BlankLineBeforeDeclarationRule.kt @@ -1,6 +1,7 @@ package com.pinterest.ktlint.ruleset.standard.rules import com.pinterest.ktlint.rule.engine.core.api.AutocorrectDecision +import com.pinterest.ktlint.rule.engine.core.api.ElementType import com.pinterest.ktlint.rule.engine.core.api.ElementType.BLOCK import com.pinterest.ktlint.rule.engine.core.api.ElementType.CLASS import com.pinterest.ktlint.rule.engine.core.api.ElementType.CLASS_BODY @@ -30,10 +31,8 @@ import com.pinterest.ktlint.rule.engine.core.api.nextCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevCodeSibling import com.pinterest.ktlint.rule.engine.core.api.prevLeaf import com.pinterest.ktlint.rule.engine.core.api.upsertWhitespaceBeforeMe -import com.pinterest.ktlint.rule.engine.core.util.safeAs import com.pinterest.ktlint.ruleset.standard.StandardRule import org.jetbrains.kotlin.com.intellij.lang.ASTNode -import org.jetbrains.kotlin.psi.KtFunctionLiteral import org.jetbrains.kotlin.psi.stubs.elements.KtTokenSets /** @@ -181,10 +180,8 @@ public class BlankLineBeforeDeclarationRule : treeParent .takeIf { it.elementType == BLOCK && it.treeParent.elementType == FUNCTION_LITERAL } ?.treeParent - ?.psi - ?.safeAs() - ?.bodyExpression - ?.node + ?.takeIf { it.elementType == ElementType.FUNCTION_LITERAL } + ?.findChildByType(ElementType.BLOCK) ?.children() ?.firstOrNull { !it.isWhiteSpace() && !it.isPartOfComment() }