Merge pull request #1731 from vector-im/feature/bma/variousCleanup
Konsist: check if sealed class could be sealed interface
This commit is contained in:
commit
fe69db397f
30 changed files with 148 additions and 59 deletions
|
|
@ -16,12 +16,19 @@
|
|||
|
||||
package io.element.android.tests.konsist
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.Immutable
|
||||
import androidx.compose.runtime.Stable
|
||||
import com.lemonappdev.konsist.api.Konsist
|
||||
import com.lemonappdev.konsist.api.ext.list.constructors
|
||||
import com.lemonappdev.konsist.api.ext.list.modifierprovider.withSealedModifier
|
||||
import com.lemonappdev.konsist.api.ext.list.parameters
|
||||
import com.lemonappdev.konsist.api.ext.list.withAnnotationOf
|
||||
import com.lemonappdev.konsist.api.ext.list.withNameEndingWith
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutAnnotationOf
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutConstructors
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutName
|
||||
import com.lemonappdev.konsist.api.ext.list.withoutParents
|
||||
import com.lemonappdev.konsist.api.verify.assertEmpty
|
||||
import com.lemonappdev.konsist.api.verify.assertTrue
|
||||
import org.junit.Test
|
||||
|
|
@ -55,4 +62,33 @@ class KonsistArchitectureTest {
|
|||
.withNameEndingWith("Events")
|
||||
.assertEmpty(additionalMessage = "Events class MUST be sealed interface")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Sealed class without constructor and without parent MUST be sealed interface`() {
|
||||
Konsist.scopeFromProject()
|
||||
.classes()
|
||||
.withSealedModifier()
|
||||
.withoutConstructors()
|
||||
.withoutParents()
|
||||
.assertEmpty(additionalMessage = "Sealed class without constructor MUST be sealed interface")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Sealed interface used in Composable MUST be Immutable or Stable`() {
|
||||
// List all sealed interface without Immutable nor Stable annotation in the project
|
||||
val forbiddenInterfacesForComposableParameter = Konsist.scopeFromProject()
|
||||
.interfaces()
|
||||
.withSealedModifier()
|
||||
.withoutAnnotationOf(Immutable::class, Stable::class)
|
||||
.map { it.fullyQualifiedName }
|
||||
|
||||
Konsist.scopeFromProject()
|
||||
.functions()
|
||||
.withAnnotationOf(Composable::class)
|
||||
.assertTrue(additionalMessage = "Consider adding the @Immutable or @Stable annotation to the sealed interface") {
|
||||
it.parameters.all { param ->
|
||||
param.type.fullyQualifiedName !in forbiddenInterfacesForComposableParameter
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue