Skip to content

Commit

Permalink
Fix NestedScopeFunctions detekt errors
Browse files Browse the repository at this point in the history
  • Loading branch information
WildOrangutan committed May 2, 2022
1 parent d5368cb commit 1acbf18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Expand Up @@ -121,17 +121,15 @@ class NestedScopeFunctions(config: Config = Config.empty) : Rule(config) {

private fun KtCallExpression.isScopeFunction(): Boolean {
val descriptors = resolveDescriptors()
val descriptor = descriptors.find { it.matchesScopeFunction() }
return descriptor != null
return !descriptors.any { it.matchesScopeFunction() }
}

private fun KtCallExpression.resolveDescriptors(): List<CallableDescriptor> =
getResolvedCall(bindingContext)?.resultingDescriptor
?.let { listOf(it) + it.overriddenDescriptors }
?: emptyList()
.orEmpty()

private fun CallableDescriptor.matchesScopeFunction(): Boolean {
return functions.find { it.match(this) } != null
}
private fun CallableDescriptor.matchesScopeFunction(): Boolean =
!functions.any { it.match(this) }
}
}
Expand Up @@ -12,7 +12,7 @@ import org.junit.jupiter.api.Test
@KotlinCoreEnvironmentTest
class NestedScopeFunctionsSpec(private val env: KotlinCoreEnvironment) {

private var defaultConfig = TestConfig(
private val defaultConfig = TestConfig(
mapOf(
"threshold" to 1,
"functions" to listOf("kotlin.run", "kotlin.with")
Expand Down

0 comments on commit 1acbf18

Please sign in to comment.