Repository: detekt/detekt (kotlin)

Issue:
UseDataClass: False positive with expected class
This class

```kotlin
expect class OAuthClientSettings() {
    val environment: Environment
    internal val authFlowFactory: CodeAuthFlowFactory
    internal val store: SettingsStore
}
```

triggers the following warning:

```
OAuthClientSettings.kt:9:14: The class OAuthClientSettings defines no functionality and only holds data. Consider converting it to a data class. [UseDataClass]
```

However, it is prohibited to create "expected" data classes:

```
Modifier 'expect' is incompatible with 'data'
```

## Your Environment
* Version of detekt used: 1.23.7
* Version of Gradle used (if applicable): 8.10.1

Pull request:
Fixes #7832

Patch:
diff --git a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClass.kt b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClass.kt
index 905903ecce84..19ce092de613 100644
--- a/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClass.kt
+++ b/detekt-rules-style/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClass.kt
@@ -7,6 +7,7 @@ import io.gitlab.arturbosch.detekt.api.Entity
 import io.gitlab.arturbosch.detekt.api.RequiresFullAnalysis
 import io.gitlab.arturbosch.detekt.api.Rule
 import io.gitlab.arturbosch.detekt.api.config
+import io.gitlab.arturbosch.detekt.rules.isExpect
 import io.gitlab.arturbosch.detekt.rules.isOpen
 import org.jetbrains.kotlin.psi.KtClass
 import org.jetbrains.kotlin.psi.KtFile
@@ -112,7 +113,8 @@ class UseDataClass(config: Config) : Rule(
             klass.isSealed() ||
             klass.isInline() ||
             klass.isValue() ||
-            klass.isInner()
+            klass.isInner() ||
+            klass.isExpect()
 
     private fun hasOnlyPrivateConstructors(klass: KtClass): Boolean {
         val primaryConstructor = klass.primaryConstructor


Test patch:
diff --git a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClassSpec.kt b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClassSpec.kt
index d70ce2f010e6..79429bb321fd 100644
--- a/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClassSpec.kt
+++ b/detekt-rules-style/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/UseDataClassSpec.kt
@@ -5,6 +5,7 @@ import io.gitlab.arturbosch.detekt.rules.KotlinCoreEnvironmentTest
 import io.gitlab.arturbosch.detekt.test.TestConfig
 import io.gitlab.arturbosch.detekt.test.assertThat
 import io.gitlab.arturbosch.detekt.test.compileAndLintWithContext
+import io.gitlab.arturbosch.detekt.test.lintWithContext
 import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
 import org.junit.jupiter.api.Nested
 import org.junit.jupiter.api.Test
@@ -414,4 +415,14 @@ class UseDataClassSpec(val env: KotlinCoreEnvironment) {
         """.trimIndent()
         assertThat(subject.compileAndLintWithContext(env, code)).isEmpty()
     }
+
+    @Test
+    fun `does not report expected classes`() {
+        val code = """
+            expect class Foo() {
+                val bar: String
+            }
+        """.trimIndent()
+        assertThat(subject.lintWithContext(env, code)).isEmpty()
+    }
 }