Android Snippets
Konsist can be used to guard the consistency of the Android project.
1. Classes Extending ViewModel Should Have ViewModel Suffix
ViewModel Should Have ViewModel Suffix@Test
fun `classes extending 'ViewModel' should have 'ViewModel' suffix`() {
Konsist
.scopeFromProject()
.classes()
.withParentClassOf(ViewModel::class)
.assertTrue { it.name.endsWith("ViewModel") }
}2. Every ViewModel Public Property Has Flow Type
ViewModel Public Property Has Flow Type@Test
fun `Every 'ViewModel' public property has 'Flow' type`() {
Konsist
.scopeFromProject()
.classes()
.withParentClassOf(ViewModel::class)
.properties()
.assertTrue {
it.hasPublicOrDefaultModifier && it.hasType { type -> type.name == "kotlinx.coroutines.flow.Flow" }
}
}3. Repository Classes Should Reside In repository Package
Repository Classes Should Reside In repository Package4. No Class Should Use Android Util Logging
5. All JetPack Compose Previews Contain Preview In Method Name
Preview In Method Name6. Every Class With Serializable Must Have Its Properties Serializable
Last updated