All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.gitlab.arturbosch.detekt.cli.config.ConfigValidators.kt Maven / Gradle / Ivy

There is a newer version: 1.23.7
Show newest version
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