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 caa95a9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
Expand Up @@ -28,7 +28,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 +44,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
Expand Up @@ -59,8 +59,14 @@ 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.joinToString(
","
)
)
}

@Configuration("if labeled return statements should be ignored")
private val excludeLabeled: Boolean by config(false)
Expand Down Expand Up @@ -90,7 +96,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 caa95a9

Please sign in to comment.