How can I setup Detekt with ktlint correctly that ...
# detekt
m
How can I setup Detekt with ktlint correctly that when I use the reformat shortcut in Intelij it formats to the Detekt configuration? Both Detekt and ktlint plugins are installed in my IDE. Current gradle configuration
Copy code
tasks {
    withType<io.gitlab.arturbosch.detekt.Detekt> {
        parallel = true
        config.setFrom(files("/config/detekt/detekt.yml"))
        buildUponDefaultConfig = true
        jvmTarget = "$projectJvmTarget"
        autoCorrect = true

        setSource(files("src/main/kotlin", "src/test/kotlin"))
        setOf(
            "**/*.kt",
            "**/*.kts",
            ".*/resources/.*",
            ".*/build/.*",
            "/versions.gradle.kts",
        ).forEach {
            include(it)
        }

        reports {
            html.required.set(true)
            html.outputLocation.set(file("reports/detekt/detekt.html"))

            sarif.required.set(true)
            sarif.outputLocation.set(file("reports/detekt/detekt.sarif"))
        }

        outputs.dir("reports/detekt/")
    }
}

dependencies {
...
 detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8")
}
For the detekt config I just ran the generate config task. Have not changed anything in it
s
Make sure the ktlint plugin is not trying to format the code instead. There's an option to disable in its settings about this. I don't recall offhand the name, but it should be obvious
👍 1
d
found any useful articles on doing this? I need to do that for my project soon