Back to Detekt

Howto: build upon the default yaml config file

website/blog/2019-03-03-build-upon-the-default-config.md

1.23.81.1 KB
Original Source

A common use case of detekt users was to build upon the default config file and use a second config file to override some defaults.

<!-- truncate -->

Speaking in Gradle terms, this could look like following:

gradle
detekt {
    ...
    config = files(
            project.rootDir.resolve("config/default-detekt-config.yml"),
            project.rootDir.resolve("config/our.yml")
    )
    baseline = project.rootDir.resolve("config/baseline.xml")
    ...
}

Starting from RC13, two new commandline flags got introduced:

  • --fail-fast
  • and --build-upon-default-config
  • (buildUponDefaultConfig and failFast properties for gradle setup)

Both options allow us to use the distributed default-detekt-config.yml as the backup configuration when no rule configuration is found in the specified configuration (--config or config = ...).
This allows us to simplify our detekt setup without copy-pasting a huge config file:

gradle
detekt {
    ...
    buildUponDefaultConfig = true
    config = files(project.rootDir.resolve("config/our.yml"))
    baseline = project.rootDir.resolve("config/baseline.xml")
    ...
}