Skip to content

Commit

Permalink
Handle the globbing inside AnnotationExcluder
Browse files Browse the repository at this point in the history
  • Loading branch information
BraisGabin committed Dec 10, 2021
1 parent f117e87 commit 84a8b9a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 31 deletions.
Expand Up @@ -10,8 +10,11 @@ import org.jetbrains.kotlin.psi.KtFile
*/
class AnnotationExcluder(
root: KtFile,
private val excludes: List<String>
excludes: List<String>,
) {
private val excludes = excludes.map {
it.removePrefix("*").removeSuffix("*")
}

private val resolvedAnnotations = root.importList?.run {
imports
Expand Down
Expand Up @@ -52,21 +52,21 @@ class AnnotationExcluderSpec : Spek({
Case("Factory", "@Factory") to true,
Case("Factory", "@Component.Factory") to true,
Case("Factory", "@dagger.Component.Factory") to true,
Case("dagger.", "@Component") to true,
Case("dagger.", "@dagger.Component") to true,
Case("dagger.", "@Factory") to true,
Case("dagger.", "@Component.Factory") to false, // false positive
Case("dagger.", "@dagger.Component.Factory") to true,
Case(".Component.Factory", "@Component") to false,
Case(".Component.Factory", "@dagger.Component") to false,
Case(".Component.Factory", "@Factory") to true,
Case(".Component.Factory", "@Component.Factory") to false, // false negative
Case(".Component.Factory", "@dagger.Component.Factory") to true,
Case(".Component.", "@Component") to false,
Case(".Component.", "@dagger.Component") to false,
Case(".Component.", "@Factory") to true,
Case(".Component.", "@Component.Factory") to false, // false negative
Case(".Component.", "@dagger.Component.Factory") to true,
Case("dagger.*", "@Component") to true,
Case("dagger.*", "@dagger.Component") to true,
Case("dagger.*", "@Factory") to true,
Case("dagger.*", "@Component.Factory") to false, // false positive
Case("dagger.*", "@dagger.Component.Factory") to true,
Case("*.Component.Factory", "@Component") to false,
Case("*.Component.Factory", "@dagger.Component") to false,
Case("*.Component.Factory", "@Factory") to true,
Case("*.Component.Factory", "@Component.Factory") to false, // false positive
Case("*.Component.Factory", "@dagger.Component.Factory") to true,
Case("*.Component.*", "@Component") to false,
Case("*.Component.*", "@dagger.Component") to false,
Case("*.Component.*", "@Factory") to true,
Case("*.Component.*", "@Component.Factory") to false, // false positive
Case("*.Component.*", "@dagger.Component.Factory") to true,
Case("foo.Component", "@Component") to false,
Case("foo.Component", "@dagger.Component") to false,
Case("foo.Component", "@Factory") to false,
Expand Down
Expand Up @@ -62,9 +62,7 @@ class LongParameterList(config: Config = Config.empty) : Rule(config) {
@Configuration(
"ignore the annotated parameters for the count (e.g. `fun foo(@Value bar: Int)` would not be counted"
)
private val ignoreAnnotatedParameter: List<String> by config(emptyList<String>()) { list ->
list.map { it.removePrefix("*").removeSuffix("*") }
}
private val ignoreAnnotatedParameter: List<String> by config(emptyList())

private lateinit var annotationExcluder: AnnotationExcluder

Expand Down
Expand Up @@ -40,9 +40,7 @@ class LateinitUsage(config: Config = Config.empty) : Rule(config) {

@Configuration("Allows you to provide a list of annotations that disable this check.")
@Deprecated("Use `ignoreAnnotated` instead")
private val excludeAnnotatedProperties: List<String> by config(emptyList<String>()) { list ->
list.map { it.removePrefix("*").removeSuffix("*") }
}
private val excludeAnnotatedProperties: List<String> by config(emptyList())

@Configuration("Allows you to disable the rule for a list of classes")
private val ignoreOnClassesPattern: Regex by config("", String::toRegex)
Expand Down
Expand Up @@ -57,9 +57,7 @@ class FunctionOnlyReturningConstant(config: Config = Config.empty) : Rule(config

@Configuration("allows to provide a list of annotations that disable this check")
@Deprecated("Use `ignoreAnnotated` instead")
private val excludeAnnotatedFunction: List<String> by config(emptyList<String>()) { functions ->
functions.map { it.removePrefix("*").removeSuffix("*") }
}
private val excludeAnnotatedFunction: List<String> by config(emptyList())

private lateinit var annotationExcluder: AnnotationExcluder

Expand Down
Expand Up @@ -60,9 +60,7 @@ class UnnecessaryAbstractClass(config: Config = Config.empty) : Rule(config) {

@Configuration("Allows you to provide a list of annotations that disable this check.")
@Deprecated("Use `ignoreAnnotated` instead")
private val excludeAnnotatedClasses: List<String> by config(emptyList<String>()) { classes ->
classes.map { it.removePrefix("*").removeSuffix("*") }
}
private val excludeAnnotatedClasses: List<String> by config(emptyList())

private lateinit var annotationExcluder: AnnotationExcluder

Expand Down
Expand Up @@ -56,9 +56,7 @@ class UseDataClass(config: Config = Config.empty) : Rule(config) {

@Configuration("allows to provide a list of annotations that disable this check")
@Deprecated("Use `ignoreAnnotated` instead")
private val excludeAnnotatedClasses: List<String> by config(emptyList<String>()) { classes ->
classes.map { it.removePrefix("*").removeSuffix("*") }
}
private val excludeAnnotatedClasses: List<String> by config(emptyList())

@Configuration("allows to relax this rule in order to exclude classes that contains one (or more) vars")
private val allowVars: Boolean by config(false)
Expand Down

0 comments on commit 84a8b9a

Please sign in to comment.