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

Eric

11/14/2023, 1:21 PM
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

schalkms

11/16/2023, 8:29 PM
Copy your config yaml file and edit the copy to disable
autoCorrect
.
Copy code
formatting:
  active: true
  autoCorrect: false
e

Eric

11/16/2023, 8:30 PM
that's the point, i do NOT want autoCorrect in CI/CD
s

schalkms

11/16/2023, 8:30 PM
Then you could inject one or the other yaml config depending on your environment.
e

Eric

11/16/2023, 8:31 PM
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

schalkms

11/16/2023, 8:32 PM
Yes, either with the detekt closure variable or with two config files only differing in the
autoCorrect
setting.
2 Views