ReturnCount.excludedFunctions should be a List<String> - #5081
Conversation
Codecov Report
@@ Coverage Diff @@
## main #5081 +/- ##
============================================
+ Coverage 84.87% 84.92% +0.05%
- Complexity 3575 3605 +30
============================================
Files 500 502 +2
Lines 11785 11876 +91
Branches 2197 2227 +30
============================================
+ Hits 10002 10086 +84
+ Misses 692 691 -1
- Partials 1091 1099 +8
Continue to review full report at Codecov.
|
|
|
| @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: List<String> by config(emptyList()) |
There was a problem hiding this comment.
You are introducing a breaking change here. You should keep "equals".
And I don't know why the tests doesn't complain but looking at the code of SplitPattern this code doesn't do the same as before, right?
There was a problem hiding this comment.
You are introducing a breaking change here. You should keep `"equals"
Ok
And I don't know why the tests doesn't complain but looking at the code of
SplitPatternthis code doesn't do the same as before, right?
Yes
There was a problem hiding this comment.
@BraisGabin Should we change the SplitPattern implementation and leave the signature of ReturnCount as before i.e private val excludedFunctions: SplitPattern by config("equals") { SplitPattern(it) }?
There was a problem hiding this comment.
Is this the right way to change?
ReturnCount.kt
private val excludedFunctions: SplitPattern by config(listOf("equals")) { SplitPattern(it.toString()) }SplitPattern.kt
@Suppress("detekt.SpreadOperator")
private val excludes = text
.commaSeparatedPattern(*delimiters.toCharArray().map { it.toString() }.toTypedArray())
.mapIf(removeTrailingAsterisks) { seq ->
seq.map { it.removePrefix("*") }
.map { it.removeSuffix("*") }
.map {it.removePrefix("[")}
.map { it.removeSuffix("]") }
}
.toList()There was a problem hiding this comment.
I would look at what SplitPattern does and reproduce it in this rule. I'm sure that I did this time on other classes some time ago but for some reason I missed this one.
| @@ -1,14 +1,8 @@ | |||
| @file:Suppress("WildcardImport", "NoWildcardImports") | |||
| @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()) } |
There was a problem hiding this comment.
If you want to go this way you can use it.joinString(",") (or something similar, I can't recall the signature). This way you don't need to change SplitPattern. That could have unexpected implications.
| fun matches(value: String): List<String> = | ||
| excludes.filter { value.contains(it, ignoreCase = true) } |
There was a problem hiding this comment.
Reduce the changed lines
| 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) } |
| fun contains(value: String?): Boolean = | ||
| excludes.any { value?.contains(it, ignoreCase = true) == true } |
There was a problem hiding this comment.
Reduce the changed lines
| 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 } |
| SplitPattern( | ||
| it.joinToString( | ||
| "," | ||
| ) | ||
| ) |
There was a problem hiding this comment.
| SplitPattern( | |
| it.joinToString( | |
| "," | |
| ) | |
| ) | |
| SplitPattern(it.joinToString(",")) |
| private fun shouldBeIgnored(function: KtNamedFunction) = | ||
| excludedFunctions.contains(function.name) |
There was a problem hiding this comment.
Reduce the changed lines
| private fun shouldBeIgnored(function: KtNamedFunction) = | |
| excludedFunctions.contains(function.name) | |
| private fun shouldBeIgnored(function: KtNamedFunction) = excludedFunctions.contains(function.name) |
closes: #5063