2

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!

liminal
  • 1,144
  • 2
  • 13
  • 24

1 Answers1

2

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
Mauin
  • 483
  • 3
  • 12
  • Thanks, Mauin! I will give it a try soon. What is the preferred way? I thought active = true means the check is enabled but apparently it’s the opposite? – liminal Oct 10 '18 at 11:12
  • The choice is really yours if you want to use the ktlint or detekt rule. Internally they should behave the same. Feel free to open an issue in the detekt repository mentioning this case. It seems like even if you set a ktlint (formatting) rule to active but don't include the formatting dependency detekt will not mention the issue to you and just ignore it. That could be improved. – Mauin Oct 11 '18 at 12:04