Does the detekt plugin for Android Studio work wit...
# detekt
m
Does the detekt plugin for Android Studio work with custom rules, and specifically for rules using type resolution? My rule works when I do
./gradlew detektMain
but I don't see any live errors while coding.
c
You can add your custom rule in the
plugin jars
👌 1
m
With the
Plugin jars
path set up, I can now see highlighting from my custom rule that doesn't require type resolution, but not the one which does require it 🤔
In my
detekt.yml
Copy code
# By default detekt does not know about your new properties. Therefore we need to mention them in the configuration
#  under config>excludes. (<https://detekt.github.io/detekt/extensions.html>)
config:
  validation: true
  excludes: "custom-proj-rules.*,custom-proj-rules>.*>.*"

custom-proj-rules:
  active: true
  InvalidExpressionFunction:
    active: true
    includes: [ '**/main/**' ]
  KotlinObjectJavaSerialization:
    active: true
    includes: ['**/main/**']
In my
detekt.xml
config file
Copy code
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="DetektProjectConfiguration">
    <enableDetekt>true</enableDetekt>
    <enableFormatting>true</enableFormatting>
    <treatAsError>true</treatAsError>
    <configPaths>$PROJECT_DIR$/config/detekt/detekt.yml</configPaths>
    <pluginPaths>$PROJECT_DIR$/detekt-rules/build/libs/detekt-rules.jar</pluginPaths>
  </component>
</project>
g
On a separate note, 
active: false
 on a specific custom rule doesn’t seem to be respected. e.g. when I set my config to
That could be a bug. Are you able to reproduce it also with Detekt gradle plugin or is it just happening inside IntelliJ?
As for the type resolution: yes I’m afraid they don’t work in IntelliJ https://github.com/detekt/detekt-intellij-plugin/issues/126
👍 1
m
I found when I changed my config, I needed to restart Android Studio to see the plugin use it. That was several versions ago though.
🤔 1
g
@mkrussel Is this related? If not can you open another thread/issue?
m
I was just commented on why the
active:false
might not have worked.
👍 3
m
If I run
./gradlew detek
I can reproduce it that way. The IDE plugin seems to be very erratic as to whether it shows the detekt errors. I'm not sure if I need to rebuild or clear cache after each change to
detekt.yml
?
g
I'm unsure about the IntelliJ plugin. But if you're able to reproduce from the Gradle tasks, then it's definitely a bug in detekt.
😮 1
m
Also I read in an issue that
includes: [ '**/main/**' ]
is required, but it doesn't appear to be from my testing. I'm assuming that was changed?
g
Also I read in an issue that 
includes: [ '**/main/**' ]
 is required,
Which issue?
m
222 Views