Add tests showing how to exclude custom config properties in plugins (#2192)

* Add tests showing how to exclude custom plugin properties in configuration files - #2169

* Mention config validation excludes in the website under extensions
This commit is contained in:
Artur Bosch
2019-12-26 22:45:29 +01:00
committed by GitHub
parent ceb64e63c9
commit 10f97d2f59
6 changed files with 69 additions and 6 deletions

View File

@@ -16,7 +16,7 @@ class CliArgs : Args {
description = "Input paths to analyze. Multiple paths are separated by comma. If not specified the " +
"current working directory is used."
)
private var input: String? = null
var input: String? = null
@Parameter(
names = ["--includes", "-in"],

View File

@@ -3,13 +3,15 @@ val junitPlatformVersion: String by project
val spekVersion: String by project
dependencies {
// When creating a sample extension, change this dependency to the detekt-api version you build against, e.g.
// io.gitlab.arturbosch.detekt:detekt-api:1.0.0-RC15
// When creating a sample extension, change this dependency to the detekt-api version you build against
// e.g. io.gitlab.arturbosch.detekt:detekt-api:1.x.x
implementation(project(":detekt-api"))
// When creating a sample extension, change this dependency to the detekt-test version you build against, e.g.
// io.gitlab.arturbosch.detekt:detekt-test:1.0.0-RC15
// When creating a sample extension, change this dependency to the detekt-test version you build against
// e.g. io.gitlab.arturbosch.detekt:detekt-test:1.x.x
testImplementation(project(":detekt-test"))
// Do you want to write integration or system tests? Add the cli dependency.
testImplementation(project(":detekt-cli"))
testImplementation("org.assertj:assertj-core:$assertjVersion")
testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")

View File

@@ -0,0 +1,38 @@
package io.gitlab.arturbosch.detekt.sample.extensions
import io.gitlab.arturbosch.detekt.cli.CliArgs
import io.gitlab.arturbosch.detekt.cli.InvalidConfig
import io.gitlab.arturbosch.detekt.cli.runners.Runner
import org.assertj.core.api.Assertions.assertThatCode
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import java.nio.file.Files
class SupportConfigValidationSpec : Spek({
describe("support config validation") {
val testDir = Files.createTempDirectory("detekt-sample")
it("fails when new rule set is not excluded") {
val args = CliArgs {
input = testDir.toString()
configResource = "included-config.yml"
}
assertThatCode { Runner(args).execute() }
.isInstanceOf(InvalidConfig::class.java)
.hasMessage("Run failed with 1 invalid config property.")
}
it("passes with excluded new rule set") {
val args = CliArgs {
input = testDir.toString()
configResource = "excluded-config.yml"
}
assertThatCode { Runner(args).execute() }
.doesNotThrowAnyException()
}
}
})

View File

@@ -0,0 +1,9 @@
config:
validation: true
# 1. exclude rule set 'sample' and all its nested members
# 2. exclude every property in every rule under the rule set 'sample'
excludes: "sample.*,sample>.*>.*"
sample:
TooManyFunctions:
active: true

View File

@@ -0,0 +1,3 @@
sample:
TooManyFunctions:
active: true

View File

@@ -97,6 +97,17 @@ By specifying the rule set and rule ids, _detekt_ will use the sub configuration
```val threshold = valueOrDefault("threshold", THRESHOLD)```
Note: As of version 1.2.0 detekt now verifies if all configured properties actually exist in a configuration created by `--generate-config`.
This means that by default detekt does not know about your new properties.
Therefore we need to mention them in the configuration under `config>excludes`:
```yaml
config:
validation: true
# 1. exclude rule set 'sample' and all its nested members
# 2. exclude every property in every rule under the rule set 'sample'
excludes: "sample.*,sample>.*>.*"
```
##### <a name="testing">Testing your rules</a>