Is there a way to allow auto-fixing when using loc...
# detekt
e
Is there a way to allow auto-fixing when using locally, like from the command line or pre-commit hook, but disable for use in CI pipeline? I want the build to fail for style and formatting issues. detekt.yml:
Copy code
build:
  maxIssues: 0
  excludeCorrectable: true
# ...
formatting:
  autoCorrect: true
build.gradle.kts:
Copy code
detekt {
    buildUponDefaultConfig = true
    allRules = false
    config.setFrom(files("$projectDir/config/detekt.yml"))
    autoCorrect = true
}
./gradlew detektMain -Ddetekt.build.excludeCorrectable=false -Ddetekt.formatting.autoCorrent=false
?
I think this should work
Copy code
detekt {
    buildUponDefaultConfig = true
    allRules = false
    config.setFrom(files("$projectDir/config/detekt.yml"))
    autoCorrect = System.getenv("CI").isNullOrBlank()
}
s
Copy your config yaml file and edit the copy to disable
autoCorrect
.
Copy code
formatting:
  active: true
  autoCorrect: false
e
that's the point, i do NOT want autoCorrect in CI/CD
s
Then you could inject one or the other yaml config depending on your environment.
e
this is working
Copy code
detekt {
    buildUponDefaultConfig = true
    allRules = false
    config.setFrom(files("$projectDir/config/detekt.yml"))
    autoCorrect = System.getenv("CI").isNullOrBlank()
}
👍 1
nearly all CI systems set the
CI
env var
s
Yes, either with the detekt closure variable or with two config files only differing in the
autoCorrect
setting.