io.gitlab.arturbosch.detekt.cli.config.ConfigValidators.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of detekt-cli Show documentation
Show all versions of detekt-cli Show documentation
Static code analysis for Kotlin
package io.gitlab.arturbosch.detekt.cli.config
import io.gitlab.arturbosch.detekt.api.ConfigValidator
import io.gitlab.arturbosch.detekt.api.Notification
import io.gitlab.arturbosch.detekt.cli.console.red
import io.gitlab.arturbosch.detekt.core.ProcessingSettings
import java.util.ServiceLoader
internal fun checkConfiguration(settings: ProcessingSettings) {
val props = settings.config.subConfig("config")
val shouldValidate = props.valueOrDefault("validation", true)
if (shouldValidate) {
val validators = loadValidators(settings) + DefaultPropertiesConfigValidator(settings)
val notifications = validators.flatMap { it.validate(settings.config) }
notifications.map(Notification::message).forEach(settings::info)
val errors = notifications.filter(Notification::isError)
if (errors.isNotEmpty()) {
val propsString = if (errors.size == 1) "property" else "properties"
throw InvalidConfig("Run failed with ${errors.size} invalid config $propsString.".red())
}
}
}
private fun loadValidators(settings: ProcessingSettings): List =
ServiceLoader.load(ConfigValidator::class.java, settings.pluginLoader)
.onEach { it.init(settings.config); it.init(settings) }
.toList()
© 2015 - 2025 Weber Informatics LLC | Privacy Policy