Skip to content

Konsist facilitates codebase standardization by enforcing coding conventions and guarding the project architecture.

License

Notifications You must be signed in to change notification settings

JonathanSarco/konsist

 
 

Repository files navigation

Konsist

Kotlin Check Workflow

Konsist is a library that guards the consistency of Kotlin projects by promoting the standardization of the Kotlin codebase. It enforces coding conventions and project architecture. Konsist tests are written in Kotlin and can be easily integrated with popular testing frameworks such as JUnit4, JUnit5.

Dependencies

// Gradle Kotlin:
testImplementation("com.lemonappdev:konsist:0.12.1")

// Gradle Groovy:
testImplementation "com.lemonappdev:konsist:0.12.1"

// Maven:
<dependency>
    <groupId>com.lemonappdev</groupId>
    <artifactId>konsist</artifactId>
    <version>0.12.1</version>
    <scope>test</scope>
</dependency>

Check the Konsist documentation to learn more about Konsist and take a look at getting started guide.

Examples

Konsist API reflects the structure of Kotlin code. Konsist guards are written in form of unit tests.

General Kotlin Check

@Test
fun `classes with 'UseCase' suffix should reside in 'usecase' package`() {
    Konsist.scopeFromProject()
        .classes()
        .withNameEndingWith("UseCase")
        .assert { it.resideInPackage("..usecase..") }
}

Android Specific Check

@Test
fun `classes extending 'ViewModel' should have 'ViewModel' suffix`() {
    Konsist.scopeFromProject()
        .classes()
        .withAllParentsOf(ViewModel::class)
        .assert { it.name.endsWith("ViewModel") }
}

Spring Specific Check

@Test
fun `interfaces with 'Repository' annotation should have 'Repository' suffix`() {
    Konsist
        .scopeFromProject()
        .interfaces()
        .withAllAnnotationsOf(Repository::class)
        .assert { it.hasNameEndingWith("Repository") }
}

Architecture Layers Check

@Test
fun `clean architecture layers have correct dependencies`() {
    Konsist
        .scopeFromProduction()
        .assertArchitecture {
            // Define layers
            val domain = Layer("Domain", "com.myapp.domain..")
            val presentation = Layer("Presentation", "com.myapp.presentation..")
            val data = Layer("Data", "com.myapp.data..")

            // Define architecture assertions
            domain.dependsOnNothing()
            presentation.dependsOn(domain)
            data.dependsOn(domain)
        }
}

Check out our snippet page for a feast of examples!

Articles

Star History

Star History Chart

Community & Support

Use #konsist channel at kotlinlang Slack Workspace (preferred) or start GitHub discussion.

Contributing

Please be sure to review Konsist contributing guidelines to learn how to support the project.

Licence

Konsist is distributed under the terms of the Apache License (Version 2.0). See LICENSE.md for details.

About

Konsist facilitates codebase standardization by enforcing coding conventions and guarding the project architecture.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 99.3%
  • Python 0.7%