From 9d30b64864c7791ee85206feda64761d87ccb478 Mon Sep 17 00:00:00 2001 From: Pleshkova Daria Date: Fri, 27 Oct 2023 16:12:42 +0300 Subject: [PATCH] Fixed warning `FUNCTION_BOOLEAN_PREFIX` on `operator fun` ### What's done: - fixed warning `FUNCTION_BOOLEAN_PREFIX` on `operator fun`. - added warning test. Closes #1723 --- .../diktat/ruleset/rules/chapter1/IdentifierNaming.kt | 4 +++- .../ruleset/chapter1/IdentifierNamingWarnTest.kt | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/IdentifierNaming.kt b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/IdentifierNaming.kt index fd2f55ea0f..dbcb474e32 100644 --- a/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/IdentifierNaming.kt +++ b/diktat-rules/src/main/kotlin/com/saveourtool/diktat/ruleset/rules/chapter1/IdentifierNaming.kt @@ -412,7 +412,9 @@ class IdentifierNaming(configRules: List) : DiktatRule( @Suppress("COLLAPSE_IF_STATEMENTS") if (functionReturnType != null && functionReturnType == PrimitiveType.BOOLEAN.typeName.asString()) { @Suppress("COLLAPSE_IF_STATEMENTS") - if (allMethodPrefixes.none { functionName.text.startsWith(it) }) { + val isOperatorFun = node.firstChildNode?.findChildrenMatching { it.elementType == KtNodeTypes.OPERATION_REFERENCE } + + if (isOperatorFun == null && allMethodPrefixes.none { functionName.text.startsWith(it) }) { // FixMe: add agressive autofix for this FUNCTION_BOOLEAN_PREFIX.warn(configRules, emitWarn, functionName.text, functionName.startOffset, functionName) } diff --git a/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt b/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt index d32fb24cc7..af6eb1a3e3 100644 --- a/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt +++ b/diktat-rules/src/test/kotlin/com/saveourtool/diktat/ruleset/chapter1/IdentifierNamingWarnTest.kt @@ -447,6 +447,16 @@ class IdentifierNamingWarnTest : LintTestBase(::IdentifierNaming) { ) } + @Test + @Tag(WarningNames.FUNCTION_BOOLEAN_PREFIX) + fun `fixed false positive result on operator functions`() { + lintMethod( + """ + inline operator fun component3(): Boolean = asDynamic()[2].unsafeCast() + """.trimIndent() + ) + } + @Test @Tag(WarningNames.IDENTIFIER_LENGTH) fun `regression - function argument type`() {