-
-
Notifications
You must be signed in to change notification settings - Fork 794
ReturnCount.excludedFunctions should be a List<String> #5081
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
SplitPattern
this code doesn't do the same as before, right?
Yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/ReturnCount.kt
Fixed
Show fixed
Hide fixed
@@ -1,14 +1,8 @@ | |||
@file:Suppress("WildcardImport", "NoWildcardImports") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use wildcard imports.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SplitPattern( | |
it.joinToString( | |
"," | |
) | |
) | |
SplitPattern(it.joinToString(",")) |
private fun shouldBeIgnored(function: KtNamedFunction) = | ||
excludedFunctions.contains(function.name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce the changed lines
private fun shouldBeIgnored(function: KtNamedFunction) = | |
excludedFunctions.contains(function.name) | |
private fun shouldBeIgnored(function: KtNamedFunction) = excludedFunctions.contains(function.name) |
closes: #5063