Hi, loving Konsist so far! If we expand our lint r...
# konsist
s
Hi, loving Konsist so far! If we expand our lint rules, I’m planning to write a blog post about our use case. Here is my question: As far as I understand, there is no way to show the warnings in the editor itself, right? So how should we approach this? Because we’re planning to use it as an alternative to Detekt. Should we maybe run the Konsist tests as part of the build step? I’m trying to understand what’s the best approach to detect the violations before opening a PR and getting that information from the CI.
p
The Konsist rules are executed with the tests, so the build pipeline will fail when there are violations. There is no IDE plugin available that is showing the violations after execution in the code. Detekt has a plugin for this.
s
Yeah agree, but I wonder what’s the recommended approach to fail even earlier. Should we make the
build
task depend on it, something like
preBuild.dependsOn konsistTask
?
p
By default there is no Konsist task but the Konsist rules are executed with the test task. You can create a custom task only for the Konsist rules and depend on it
i
For now I see two ways: 1.
build
task dependent on custom
konsistTask
(I personally I prefer to have all check isolated in CI - separate checks for tests, konsistTest, detek, ktlint.... so I would go with optional dependency task that will not trigger Konsist test on CI) 2. githook running this Konsist task Before each commit For the future I am hoping to
K2 Compiler
support and this should enable faster feedback BTW Thx @stelios I am glad you like it 🙏 I would love to see another community driven article 🙂
p
I also prefer option 1 with a custom task that filters the Konsist tests by a tag and makes the check task depend on it. So locally during development I use the check task and in the ci pipeline I have a separate job for it to be able to parallelize it.
Here is an example how this can be achieved. • Tag your Konsist test classes with a special tag.
Copy code
@Tag("Konsist")
• Exclude the Konsist tests for the default test task.
Copy code
tasks.test {
    useJUnitPlatform(){
        excludeTags("Konsist")
    }
}
• Create a custom test task.
Copy code
val konsistTask = "konsist"
tasks.register<Test>(konsistTask) {
    description = "Runs the Konsist Check...."
    group = LifecycleBasePlugin.VERIFICATION_GROUP

    useJUnitPlatform {
        includeTags("Konsist")
    }
}
• Let the check task depend on the newly created custom konsist task.
Copy code
tasks.check{
    dependsOn(tasks.named(konsistTask))
}
With this the konsist task can be executed separately in the ci pipeline and still is executed with the check task.
i
I am hoping to get warning/errors in IDE, but I am not sure yet if this will be even possible.
🙏 1
👍 1