Skip to content

Commit

Permalink
Add some debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
joeldickson committed Oct 12, 2024
1 parent ac3b5ab commit e6144d2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class IgnoredReturnValueRule(config: Config) : Rule(config) {

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

// Ignore constructor calls
if (expression.calleeExpression is KtConstructorCalleeExpression) {
println(" Ignoring constructor call")
return
}

val resolvedCall = expression.getResolvedCall(bindingContext)
if (resolvedCall == null) {
println(" Resolved call is null")
Expand Down Expand Up @@ -72,6 +78,4 @@ class IgnoredReturnValueRule(config: Config) : Rule(config) {
println(" Not reporting: return type is Unit or Nothing")
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,25 @@ class IgnoredReturnValueRuleTest {
@Test
fun `does not report Unit and Nothing return types`() {
val code = """
fun returnsNothing(): Nothing = throw Exception("Nothing")
fun returnsUnit(): Unit {}
fun test() {
returnsNothing()
returnsUnit()
}
""".trimIndent()
fun returnsNothing(): Nothing = throw Exception("Nothing")
fun returnsUnit(): Unit {}
fun test() {
returnsNothing()
returnsUnit()
}
""".trimIndent()

val findings = IgnoredReturnValueRule(Config.empty).compileAndLintWithContext(wrapper.env, code)

println("Number of findings: ${findings.size}")
findings.forEachIndexed { index, finding ->
println("Finding $index:")
println(" Message: ${finding.message}")
println(" Location: ${finding.entity.location}")
println(" Signature: ${finding.entity.signature}")
}

assertThat(findings).isEmpty()
}
}

0 comments on commit e6144d2

Please sign in to comment.