Search code examples
detekt

detekt NoUnusedImports not reported


In my Android gradle project, I added detekt v1.0.0.RC8.

I generated default .yml file by executing: ./gradlew detektGenerateConfig

and ran the check: ./gradlew detektCheck

The plugin found a couple of issues of type TooGenericExceptionCaught, MaxLineLength but not unused imports that I added in the code to see if detekt catches them.

These lines are in my default-detekt-config.yml

NoUnusedImports:
    active: true
    autoCorrect: true

Thanks for any pointers!


Solution

  • The NoUnusedImports is a rule that is wrapped from ktlint. Did you add the ktlint wrapping jar as a dependency with:

    dependencies {
        detekt "io.gitlab.arturbosch.detekt:detekt-formatting:[version]"
    }
    

    Alternatively you can also use the detekt rule that detects UnusedImports by enabling the rule in your config.yml:

    UnusedImports:
        active: false