Repository: detekt/detekt (kotlin)

Issue:
Show a warning message when ussing comma separate strings instead of lists
If someone has an old configuration can still be using things like this: 

```yaml
    methodNames: 'toString,hashCode,equals,finalize'
```
instead of 
```yaml
    methodNames: ['toString', 'hashCode', 'equals', 'finalize']
```

An example can be found here: https://github.com/mozilla-mobile/android-components/blob/6f60a8a44b9fa24b62c223130d39bc5ea8095ae6/config/detekt.yml#L129

The support for both types was introduced at 1.8.0. The reason to support both was purely retrocompatibility but keeping this retrocompatibility makes more difficult to maintain our code (Example: https://github.com/detekt/detekt/issues/3501#issuecomment-1015324916)

I think that we should add a warning for the users that still use the old comma separated format so in the future we can remove that retrocompatibility.

Pull request description:
With this we will show to our users a warning when they are using a comma-separeted String instead of a yaml array. This way, some release later, we can drop the support to the comma-separated String.

Fix #4498

Patch:
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 331dbaf5bb11..4f6dfe62d528 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<String, Any>
@@ -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,
+    )


Test patch:
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 81b41bb41d1b..a67f6d93e70b 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 222505f1294f..dc814e5a41af 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