ceedee
09/21/2023, 9:59 AM@Test
fun `companion object is last declaration in the class`() {
Konsist
.scopeFromProject()
.classes()
.assert {
val companionObject = it.objects().lastOrNull { obj ->
obj.hasModifiers(KoModifier.COMPANION)
}
companionObject != null && it.declarations().last() == companionObject
}
}
It catches variables in the Companion object in it.declarations().last()
. Will that be reworked?Natalia Peterwas
09/21/2023, 10:51 AMincludeNested
and includeLocal
parameters.
However, I found another error, so the correct test is below:
@Test
fun `companion object is last declaration in the class`() {
Konsist
.scopeFromProject()
.classes()
.assert {
val companionObject = it.objects(includeNested = false).lastOrNull { obj ->
obj.hasModifier(KoModifier.COMPANION)
}
if (companionObject != null) {
it.declarations(includeNested = false, includeLocal = false).last() == companionObject
} else {
true
}
}
}
ceedee
09/21/2023, 12:38 PM