Skip to content

Commit

Permalink
remove the debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldickson committed Oct 12, 2024
1 parent ef58f0e commit 3f3e35e
Showing 1 changed file with 10 additions and 34 deletions.
44 changes: 10 additions & 34 deletions src/main/kotlin/io/agodadev/kraftdetekt/IgnoredReturnValueRule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,49 +18,28 @@ class IgnoredReturnValueRule(config: Config) : Rule(config) {
override fun visitCallExpression(expression: KtCallExpression) {
super.visitCallExpression(expression)

println("Visiting call expression: ${expression.text}")

// Ignore constructor calls and calls within throw expressions
if (expression.calleeExpression is KtConstructorCalleeExpression || isWithinThrowExpression(expression)) {
println(" Ignoring constructor call or throw expression")
return
}

val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall == null) {
println(" Resolved call is null")
return
}

val returnType = resolvedCall.resultingDescriptor.returnType
if (returnType == null) {
println(" Return type is null")
return
}

println(" Return type: $returnType")
println(" Is Unit: ${returnType.isUnit()}")
println(" Is Nothing: ${returnType.isNothing()}")
val resolvedCall = expression.getResolvedCall(bindingContext) ?: return
val returnType = resolvedCall.resultingDescriptor.returnType ?: return

if (!returnType.isUnit() && !returnType.isNothing()) {
val parent = expression.parent
println(" Parent: ${parent?.javaClass?.simpleName}")

when {
parent is KtValueArgument -> println(" Parent is KtValueArgument")
parent is KtProperty -> println(" Parent is KtProperty")
parent is KtReturnExpression -> println(" Parent is KtReturnExpression")
parent is KtBinaryExpression && parent.operationToken.toString() == "EQ" -> println(" Parent is assignment")
parent is KtIfExpression && expression == parent.condition -> println(" Parent is if condition")
parent is KtWhenConditionWithExpression -> println(" Parent is when condition")
parent is KtBinaryExpression && parent.operationToken.toString() in setOf("GT", "LT", "GTEQ", "LTEQ", "EQEQ", "EXCLEQ") -> println(" Parent is comparison")
parent is KtDotQualifiedExpression -> println(" Parent is dot qualified expression")
parent is KtValueArgument -> return
parent is KtProperty -> return
parent is KtReturnExpression -> return
parent is KtBinaryExpression && parent.operationToken.toString() == "EQ" -> return
parent is KtIfExpression && expression == parent.condition -> return
parent is KtWhenConditionWithExpression -> return
parent is KtBinaryExpression && parent.operationToken.toString() in setOf("GT", "LT", "GTEQ", "LTEQ", "EQEQ", "EXCLEQ") -> return
parent is KtDotQualifiedExpression -> return
parent is KtBlockExpression -> {
println(" Parent is block expression")
val isLastStatement = parent.statements.lastOrNull() == expression
val isOnlyStatement = parent.statements.size == 1
if (!isLastStatement && !isOnlyStatement) {
println(" Reporting issue: ignored return value in block")
report(CodeSmell(
issue,
Entity.from(expression),
Expand All @@ -69,16 +48,13 @@ class IgnoredReturnValueRule(config: Config) : Rule(config) {
}
}
else -> {
println(" Reporting issue: general case")
report(CodeSmell(
issue,
Entity.from(expression),
"The return value of this function call is ignored."
))
}
}
} else {
println(" Not reporting: return type is Unit or Nothing")
}
}

Expand Down

0 comments on commit 3f3e35e

Please sign in to comment.