https://kotlinlang.org logo
#detekt
Title
v

voben

05/29/2020, 4:49 PM
I can’t seem to get autocorrect to work. This is what my detekt.gradle file looks like. Any ideas?
Copy code
apply plugin: 'io.gitlab.arturbosch.detekt'

detekt {
    parallel = true
    config = files("$rootDir/codeQuality/detekt.yml")
    autoCorrect = true
    reports {
        xml {
            enabled = false
        }
        txt {
            enabled = false
        }
    }
}
c

chao

05/29/2020, 4:49 PM
Did you run
./gradlew detekt --auto-correct
?
v

voben

05/29/2020, 4:53 PM
When I run
./gradlew detekt --auto-correct
I get Unknown command-line option ‘--auto-correct’
Is that the same thing?
c

chao

05/29/2020, 4:59 PM
https://detekt.github.io/detekt/extensions.html#autocorrect-property According to the doc, it should work at least with both options on
Note that only the ktlint rules actually support autocorrect
v

voben

05/29/2020, 5:00 PM
But why doesnt the auto correction option work when I run it with gradle? I just get the error above
Got it working by moving detekt configuration from detekt.gradle to a build.gradle file with detekt closure. Thanks
c

chao

05/29/2020, 5:17 PM
Does that mean that detekt.gradle was not applied in the build.gradle before 🤔
v

voben

05/29/2020, 5:55 PM
So did some more digging, it looks like every rule I want formatted, I have to add the `autoCorrect: true`node. Autocorrect doesnt seem to work when placed only the build.gradle file
c

chao

05/29/2020, 5:55 PM
Ah yes
v

voben

05/29/2020, 5:58 PM
But if I want all rules autoCorrected, it doesnt look like I can have this just once like this. I still need to add autoCorrect to each individual formatting rule. That right?
Copy code
formatting:
  autoCorrect: true
c

chao

05/29/2020, 6:00 PM
By default those have autoCorrect = true
v

voben

05/29/2020, 6:01 PM
Thanks @chao
64 Views