mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
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:
@@ -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"],
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -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
|
||||
@@ -0,0 +1,3 @@
|
||||
sample:
|
||||
TooManyFunctions:
|
||||
active: true
|
||||
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user