I can’t seem to get autocorrect to work. This is w...
# detekt
v
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
Did you run
./gradlew detekt --auto-correct
?
v
When I run
./gradlew detekt --auto-correct
I get Unknown command-line option ‘--auto-correct’
Is that the same thing?
c
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
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
Does that mean that detekt.gradle was not applied in the build.gradle before 🤔
v
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
Ah yes
v
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
By default those have autoCorrect = true
v
Thanks @chao
344 Views