GithubHelp home page GithubHelp logo

sk1nnyy / konsist Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lemonappdev/konsist

0.0 0.0 0.0 6.64 MB

Konsist is a powerful static code analyzer tailored for Kotlin, focused on ensuring codebase consistency and adherence to coding conventions.

Home Page: https://docs.konsist.lemonappdev.com

License: Apache License 2.0

Python 0.87% Kotlin 99.13%

konsist's Introduction

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.13.0")

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

// Maven:
<dependency>
    <groupId>com.lemonappdev</groupId>
    <artifactId>konsist</artifactId>
    <version>0.13.0</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")
        .assertTrue { it.resideInPackage("..usecase..") }
}

Android Specific Check

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

Spring Specific Check

@Test
fun `interfaces with 'Repository' annotation should have 'Repository' suffix`() {
    Konsist
        .scopeFromProject()
        .interfaces()
        .withAllAnnotationsOf(Repository::class)
        .assertTrue { 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

Write a message on the #konsist channel at kotlinlang Slack Workspace (preferred) or start a 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.

konsist's People

Contributors

nataliapeterwas avatar igorwojda avatar renovate[bot] avatar jonathansarco avatar guiguegon avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.