diff --git a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfig.kt b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfig.kt index 331dbaf5bb1..4f6dfe62d52 100644 --- a/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfig.kt +++ b/detekt-core/src/main/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfig.kt @@ -99,6 +99,8 @@ internal fun validateConfig( if (!base.contains(prop)) { notifications.add(propertyDoesNotExists(propertyPath)) + } else if (current[prop] is String && base[prop] is List<*>) { + notifications.add(propertyShouldBeAnArray(propertyPath, warningsAsErrors)) } val next = current[prop] as? Map @@ -140,3 +142,12 @@ internal fun propertyIsDeprecated( "Property '$prop' is deprecated. $deprecationDescription.", if (reportAsError) Notification.Level.Error else Notification.Level.Warning, ) + +internal fun propertyShouldBeAnArray( + prop: String, + reportAsError: Boolean, +): Notification = + SimpleNotification( + "Property '$prop' should be a YAML array instead of a comma-separated String.", + if (reportAsError) Notification.Level.Error else Notification.Level.Warning, + ) diff --git a/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfigSpec.kt b/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfigSpec.kt index 81b41bb41d1..a67f6d93e70 100644 --- a/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfigSpec.kt +++ b/detekt-core/src/test/kotlin/io/gitlab/arturbosch/detekt/core/config/ValidateConfigSpec.kt @@ -224,4 +224,27 @@ class ValidateConfigSpec { ) } } + + @ParameterizedTest + @ValueSource(booleans = [true, false]) + fun `reports a string that should be an array as a warning`(warningsAsErrors: Boolean) { + val config = yamlConfigFromContent( + """ + config: + warningsAsErrors: $warningsAsErrors + style: + MagicNumber: + ignoreNumbers: '-1,0,1,2' + """.trimIndent() + ) + + val result = validateConfig(config, baseline) + + assertThat(result).contains( + propertyShouldBeAnArray( + "style>MagicNumber>ignoreNumbers", + reportAsError = warningsAsErrors + ) + ) + } } diff --git a/detekt-core/src/test/resources/config_validation/baseline.yml b/detekt-core/src/test/resources/config_validation/baseline.yml index 222505f1294..dc814e5a41a 100644 --- a/detekt-core/src/test/resources/config_validation/baseline.yml +++ b/detekt-core/src/test/resources/config_validation/baseline.yml @@ -1,3 +1,5 @@ +config: + warningsAsErrors: true complexity: LongMethod: active: true