Skip to content

Commit

Permalink
ReturnCount.excludedFunctions should be a List<String>
Browse files Browse the repository at this point in the history
  • Loading branch information
gouri-panda committed Jul 18, 2022
1 parent 6bce28f commit c3fef48
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
Expand Up @@ -17,6 +17,8 @@ open class SplitPattern(
.mapIf(removeTrailingAsterisks) { seq ->
seq.map { it.removePrefix("*") }
.map { it.removeSuffix("*") }
.map { it.removePrefix("[") }
.map { it.removeSuffix("]") }
}
.toList()

Expand All @@ -28,7 +30,8 @@ open class SplitPattern(
/**
* Does any part contain given [value]?
*/
fun contains(value: String?): Boolean = excludes.any { value?.contains(it, ignoreCase = true) == true }
fun contains(value: String?): Boolean =
excludes.any { value?.contains(it, ignoreCase = true) == true }

/**
* Is there any element which matches the given [value]?
Expand All @@ -43,7 +46,8 @@ open class SplitPattern(
/**
* Finds all parts which match the given [value].
*/
fun matches(value: String): List<String> = excludes.filter { value.contains(it, ignoreCase = true) }
fun matches(value: String): List<String> =
excludes.filter { value.contains(it, ignoreCase = true) }

/**
* Tests if any part starts with the given [value]
Expand Down
3 changes: 2 additions & 1 deletion detekt-core/src/main/resources/default-detekt-config.yml
Expand Up @@ -626,7 +626,8 @@ style:
ReturnCount:
active: true
max: 2
excludedFunctions: 'equals'
excludedFunctions:
- 'equals'
excludeLabeled: false
excludeReturnFromLambda: true
excludeGuardClauses: false
Expand Down
@@ -1,14 +1,8 @@
@file:Suppress("WildcardImport", "NoWildcardImports")

package io.gitlab.arturbosch.detekt.rules.style

import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import io.gitlab.arturbosch.detekt.api.SplitPattern
import io.gitlab.arturbosch.detekt.api.config
import io.gitlab.arturbosch.detekt.api.*
import io.gitlab.arturbosch.detekt.api.internal.ActiveByDefault
import io.gitlab.arturbosch.detekt.api.internal.Configuration
import io.gitlab.arturbosch.detekt.rules.parentsOfTypeUntil
Expand Down Expand Up @@ -59,8 +53,8 @@ class ReturnCount(config: Config = Config.empty) : Rule(config) {
@Configuration("define the maximum number of return statements allowed per function")
private val max: Int by config(2)

@Configuration("define a free-form comma separated list of function names to be ignored by this check")
private val excludedFunctions: SplitPattern by config("equals") { SplitPattern(it) }
@Configuration("define a list of function names to be ignored by this check")
private val excludedFunctions: SplitPattern by config(listOf("equals")) { SplitPattern(it.toString()) }

@Configuration("if labeled return statements should be ignored")
private val excludeLabeled: Boolean by config(false)
Expand Down Expand Up @@ -90,7 +84,8 @@ class ReturnCount(config: Config = Config.empty) : Rule(config) {
}
}

private fun shouldBeIgnored(function: KtNamedFunction) = excludedFunctions.contains(function.name)
private fun shouldBeIgnored(function: KtNamedFunction) =
excludedFunctions.contains(function.name)

private fun countReturnStatements(function: KtNamedFunction): Int {
fun KtReturnExpression.isExcluded(): Boolean = when {
Expand Down
Expand Up @@ -347,7 +347,7 @@ class ReturnCountSpec {
TestConfig(
mapOf(
MAX to "2",
EXCLUDED_FUNCTIONS to "test1,test2"
EXCLUDED_FUNCTIONS to listOf("test1", "test2")
)
)
).compileAndLint(code)
Expand Down

0 comments on commit c3fef48

Please sign in to comment.