detekt-intellij-plugin icon indicating copy to clipboard operation
detekt-intellij-plugin copied to clipboard

Detekt custom rules that uses Type resolution doesn't work with IntelliJ plugin

Open skymansandy opened this issue 3 years ago • 7 comments

Hi team,

I've created some custom rules. Few that use type resolution and few that don't. In the IntelliJ Plugin, rules that don't need type resolution works fine when I add the plugin jar. But the type resolution ones don't. Is this expected?

Thanks.

skymansandy avatar Apr 08 '21 13:04 skymansandy

Is this expected?

Are they working fine if you invoke Detekt from CLI or from Gradle?

cortinico avatar Apr 10 '21 15:04 cortinico

Hey @cortinico, Yes, while running the Gradle task it's working fine.

skymansandy avatar Apr 12 '21 05:04 skymansandy

This is actually reported by users. ConfiguredService does not invoke Detetkt with BindingContext, therefore, type resolution rules do not work and mixed type resolving/plain rules may result in weird behavior.

It is reported that UnusedPrivateMember is such a rule with mixed behavior: https://kotlinlang.slack.com/archives/C88E12QH4/p1624326624052100

chao2zhang avatar Jun 22 '21 03:06 chao2zhang

Hey, I would love to help, but might need a hint. I assume that if we set the classpath via compiler options, rules with type resolutions are executed.

Do you know how to get the classpath in the plugin?

I googled a bit, read some javadocs and tried with:

        ModuleManager.getInstance(project).modules
            .map { OrderEnumerator.orderEntries(it).recursively().getPathsList().getPathsString() }
            .filterNot { it.isNullOrEmpty() }
            .joinToString { ":" }

which gives me an empty string.

sesigl avatar Jul 25 '22 06:07 sesigl

Rules like ForbiddenMethodCall, ForbiddenImport are not working with the plugin.

pinguinjkeke avatar Jul 26 '22 10:07 pinguinjkeke

Yea, also just noticed that built-in rules that require type resolution are not working.

kuhnroyal avatar May 26 '23 13:05 kuhnroyal

It's not just custom rules, btw, as per https://github.com/detekt/detekt-intellij-plugin/issues/499.

sindrenm avatar Jan 24 '24 18:01 sindrenm