Skip to content

Commit

Permalink
Fixed warning FUNCTION_BOOLEAN_PREFIX on operator fun
Browse files Browse the repository at this point in the history
### What's done:
- fixed warning `FUNCTION_BOOLEAN_PREFIX` on `operator fun`.
- added warning test.

Closes #1723
  • Loading branch information
diphtongue committed Oct 27, 2023
1 parent c7c539a commit 9d30b64
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,9 @@ class IdentifierNaming(configRules: List<RulesConfig>) : 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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Boolean>()
""".trimIndent()
)
}

@Test
@Tag(WarningNames.IDENTIFIER_LENGTH)
fun `regression - function argument type`() {
Expand Down

0 comments on commit 9d30b64

Please sign in to comment.