1

Trying to create some playground over Detekt custom rules and it just doesn't work. Doesn't even try to find the rule-set file.

The gradle goes

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id("io.gitlab.arturbosch.detekt").version("1.17.1")
}
...
detekt {
    toolVersion = "$detekt_version" // 1.17.1
    input = files("src/main/java")
    config = files("../detekt/detekt-config.yml")
    autoCorrect = true
    reports { ... } 
}

dependencies {
    detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detekt_version"
    compileOnly "io.gitlab.arturbosch.detekt:detekt-api:$detekt_version"
    detekt "io.gitlab.arturbosch.detekt:detekt-cli:$detekt_version"
    ...
}

The rule goes

class SomeCustomRule(config: Config) : Rule(config) {
    override val issue: Issue
        get() = Issue("Import thingy", Severity.Minor, "I don't like this string", Debt(10))

    override fun visitImportDirective(importDirective: KtImportDirective) {
        val import: String = importDirective.importPath?.pathStr ?: ""
        if ("appcompat" in import) {
            report(CodeSmell(
                issue,
                Entity.from(importDirective),
                "Importing $import which is an internal import"))
        }
    }
}

The provider is

class CustomRuleSetProvider : RuleSetProvider {
    override val ruleSetId: String = "detekt-custom-rules"

    override fun instance(config: Config) = RuleSet(ruleSetId, listOf(SomeCustomRule(config)))
}

And last but not least

At

src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.RuleSetProvider

is

com.playgrounds.detekt.customrule.CustomRuleSetProvider

Still - nothing. I tried to add gibberish at the provider - nothing, no error. I even tried to spoil the declaration at META-INF. Nothing.

Of course I tried to add the provider into my config file, or add a project line in the gradle. Error, not recognised.

What have I missed?

Thanks

user14387887
  • 111
  • 1

0 Answers0