I just copied the properties must be declared for ...
# konsist
p
I just copied the properties must be declared for function snippet to my project:
Copy code
@Test
    fun `properties are declared before functions`() {
        Konsist
            .scopeFromProject()
            .classes()
            .assert {
                val lastKoPropertyDeclarationIndex = it
                    .declarations()
                    .indexOfLastInstance<KoPropertyDeclaration>()

                val firstKoFunctionDeclarationIndex = it
                    .declarations()
                    .indexOfFirstInstance<KoFunctionDeclaration>()

                lastKoPropertyDeclarationIndex <= firstKoFunctionDeclarationIndex
            }
    }
And there are issues with my data classes:
Copy code
public data class Account(
    val id: Identity,
    val name: String
)
What I'm doing wrong?
👍 1
n
Thanks for your question, you catch our bug 🙂 I think this
assert
will works fine:
Copy code
@Test
    fun `properties are declared before functions`() {
        Konsist
            .scopeFromProject()
            .classes()
            .assert {
                val lastKoPropertyDeclarationIndex = it
                    .declarations()
                    .indexOfLastInstance<KoPropertyDeclaration>()

                val firstKoFunctionDeclarationIndex = it
                    .declarations()
                    .indexOfFirstInstance<KoFunctionDeclaration>()

                if (lastKoPropertyDeclarationIndex != -1 && firstKoFunctionDeclarationIndex != -1) {
                    lastKoPropertyDeclarationIndex < firstKoFunctionDeclarationIndex
                } else {
                    true
                }
            }
We will update this snippet in the next release.
p
Thanks for the response. The updated version is working fine 🙂
👍 2