diff --git a/diktat-rules/src/main/kotlin/generated/WarningNames.kt b/diktat-rules/src/main/kotlin/generated/WarningNames.kt index 4e75adb157..e8043f0aee 100644 --- a/diktat-rules/src/main/kotlin/generated/WarningNames.kt +++ b/diktat-rules/src/main/kotlin/generated/WarningNames.kt @@ -121,6 +121,8 @@ public object WarningNames { public const val FILE_WILDCARD_IMPORTS: String = "FILE_WILDCARD_IMPORTS" + public const val UNUSED_IMPORT: String = "UNUSED_IMPORT" + public const val NO_BRACES_IN_CONDITIONALS_AND_LOOPS: String = "NO_BRACES_IN_CONDITIONALS_AND_LOOPS" @@ -203,8 +205,12 @@ public object WarningNames { public const val RUN_BLOCKING_INSIDE_ASYNC: String = "RUN_BLOCKING_INSIDE_ASYNC" + public const val TOO_MANY_LINES_IN_LAMBDA: String = "TOO_MANY_LINES_IN_LAMBDA" + public const val CUSTOM_LABEL: String = "CUSTOM_LABEL" + public const val INVERSE_FUNCTION_PREFERRED: String = "INVERSE_FUNCTION_PREFERRED" + public const val SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY: String = "SINGLE_CONSTRUCTOR_SHOULD_BE_PRIMARY" @@ -236,12 +242,6 @@ public object WarningNames { public const val OBJECT_IS_PREFERRED: String = "OBJECT_IS_PREFERRED" - public const val INVERSE_FUNCTION_PREFERRED: String = "INVERSE_FUNCTION_PREFERRED" - - public const val TOO_MANY_LINES_IN_LAMBDA: String = "TOO_MANY_LINES_IN_LAMBDA" - - public const val UNUSED_IMPORT: String = "UNUSED_IMPORT" - public const val INLINE_CLASS_CAN_BE_USED: String = "INLINE_CLASS_CAN_BE_USED" public const val EXTENSION_FUNCTION_WITH_CLASS: String = "EXTENSION_FUNCTION_WITH_CLASS" diff --git a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt index 74a7b71032..4c627e3166 100644 --- a/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt +++ b/diktat-rules/src/main/kotlin/org/cqfn/diktat/ruleset/rules/chapter6/ExtensionFunctionsInFileRule.kt @@ -4,18 +4,16 @@ import org.cqfn.diktat.common.config.rules.RulesConfig import org.cqfn.diktat.ruleset.constants.EmitType import org.cqfn.diktat.ruleset.constants.Warnings import org.cqfn.diktat.ruleset.utils.findAllNodesWithSpecificType +import org.cqfn.diktat.ruleset.utils.getAllChildrenWithType import org.cqfn.diktat.ruleset.utils.getFirstChildWithType -import org.cqfn.diktat.ruleset.utils.hasChildOfType import com.pinterest.ktlint.core.Rule import com.pinterest.ktlint.core.ast.ElementType import com.pinterest.ktlint.core.ast.ElementType.CLASS -import com.pinterest.ktlint.core.ast.ElementType.DOT import com.pinterest.ktlint.core.ast.ElementType.FUN import com.pinterest.ktlint.core.ast.ElementType.IDENTIFIER import com.pinterest.ktlint.core.ast.ElementType.TYPE_REFERENCE import com.pinterest.ktlint.core.ast.prevSibling -import org.cqfn.diktat.ruleset.utils.getAllChildrenWithType import org.jetbrains.kotlin.com.intellij.lang.ASTNode import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtFunction @@ -53,13 +51,11 @@ class ExtensionFunctionsInFileRule(private val configRules: List) : Warnings.EXTENSION_FUNCTION_WITH_CLASS.warn(configRules, emitWarn, isFixMode, "fun ${(node.psi as KtFunction).name}", node.startOffset, node) } - private fun collectAllExtensionFunctionsWithSameClassName(node: ASTNode, classNames: List): List { - return node.getAllChildrenWithType(FUN).filter { isExtensionFunctionWithClassName(it, classNames) } - } + private fun collectAllExtensionFunctionsWithSameClassName(node: ASTNode, classNames: List): List = + node.getAllChildrenWithType(FUN).filter { isExtensionFunctionWithClassName(it, classNames) } + @Suppress("UnsafeCallOnNullableType") private fun isExtensionFunctionWithClassName(node: ASTNode, classNames: List): Boolean = - node.getFirstChildWithType(IDENTIFIER)!!.prevSibling { it.elementType == TYPE_REFERENCE } != null - && node.getFirstChildWithType(IDENTIFIER)!!.prevSibling { it.elementType == TYPE_REFERENCE }!!.text in classNames - + node.getFirstChildWithType(IDENTIFIER)!!.prevSibling { it.elementType == TYPE_REFERENCE }?.text in classNames }