Build and test deteKT static analysis diKTat code style License codecov

Releases Maven Central FOSSA Status ktlint Chat on Telegram

Hits-of-Code Lines of code GitHub repo size Awesome Kotlin Badge

DiKTat is a strict coding standard for Kotlin and a collection of Kotlin code style rules implemented as AST visitors on the top of KTlint. It can be used for detecting and autofixing code smells in CI/CD process. The full list of available supported rules and inspections can be found here.

Now diKTat was already added to the lists of static analysis tools, to kotlin-awesome and to kompar. Thanks to the community for this support!

See first

Codestyle Inspections Examples Demo White Paper Groups of Inspections

Why should I use diktat in my CI/CD?

There are several tools like detekt and ktlint that are doing static analysis. Why do I need diktat?

First of all - actually you can combine diktat with any other static analyzers. And diKTat is even using ktlint framework for parsing the code into the AST. And we are trying to contribute to those projects. Main features of diktat are the following:

  1. More inspections. It has 100+ inspections that are tightly coupled with it's codestyle.

  2. Unique inspections that are missing in other linters.

  3. Highly configurable. Each and every inspection can be configured and suppressed both from the code or from the configuration file.

  4. Strict detailed coding convention that you can use in your project.

Run as CLI-application

  1. Install KTlint manually: here

    OR use curl:

    curl -sSLO && chmod a+x ktlint
    # another option is "brew install ktlint"
  2. Load diKTat manually: here

    OR use curl:

    $ curl -sSLO
  3. Finally, run KTlint (with diKTat injected) to check your *.kt files in dir/your/dir:

    $ ./ktlint -R diktat.jar --disabled_rules=standard "dir/your/dir/**/*.kt"

To autofix all code style violations use -F option.

Run with Maven using diktat-maven-plugin

This plugin is available since version 0.1.3. You can see how it is configured in our project for self-checks: pom.xml. If you use it and encounter any problems, feel free to open issues on github.

Add this plugin to your pom.xml:


To run diktat in only-check mode use command $ mvn diktat:[email protected]. To run diktat in autocorrect mode use command $ mvn diktat:[email protected].

Run with Gradle using diktat-gradle-plugin

Requires a gradle version no lower than 5.3.

This plugin is available since version 0.1.5. You can see how the plugin is configured in our examples: build.gradle.kts. Add this plugin to your build.gradle.kts:

plugins {
    id("org.cqfn.diktat.diktat-gradle-plugin") version "1.0.2"

Or use buildscript syntax:

buildscript {
    repositories {
    dependencies {

apply(plugin = "org.cqfn.diktat.diktat-gradle-plugin")

You can then configure diktat using diktat extension:

diktat {
    inputs {
        include("src/**/*.kt")  // path matching this pattern (per PatternFilterable) that will be checked by diktat
        exclude("src/test/kotlin/excluded/**")  // path matching this pattern will not be checked by diktat
    debug = true  // turn on debug logging

Also diktat extension has different reporters. You can specify json, html, checkstyle, plain (default) or your own custom reporter:

diktat {
    reporter = "json" // "html", "checkstyle", "plain"

Example of your custom reporter:

diktat {
    reporter = "custom:name:pathToJar"

Name parameter is the name of your reporter and as the last parameter you should specify path to jar, which contains your reporter. Example of the junit custom reporter.

You can also specify an output.

diktat {
    reporter = "json"
    output = "someFile.json"

You can run diktat checks using task diktatCheck and automatically fix errors with tasks diktatFix.

Run with Spotless

Spotless is a linter aggregator.


Diktat can be run via spotless-gradle-plugin since version 5.10.0

Add this plugin to your build.gradle.kts
plugins {
   id("com.diffplug.spotless") version "5.10.0"

spotless {
   kotlin {
   kotlinGradle {
You can provide a version and configuration path manually as configFile.
spotless {
   kotlin {


Diktat can be run via spotless-maven-plugin since version 2.8.0

Add this plugin to your pom.xml
         <diktat />
You can provide a version and configuration path manually as configFile
  <version>1.0.2</version> <!-- optional -->
  <configFile>full/path/to/diktat-analysis.yml</configFile> <!-- optional, configuration file path -->

Customizations via diktat-analysis.yml

In KTlint, rules can be configured via .editorconfig, but this does not give a chance to customize or enable/disable each and every rule independently. That is why we have supported diktat-analysis.yml that can be easily changed and help in customization of your own rule set. It has simple fields: name — name of the rule, enabled (true/false) — to enable or disable that rule (all rules are enabled by the default), configuration — a simple map of some extra unique configurations for this particular rule. For example:

  # all rules are enabled by the default. To disable add 'enabled: false' to the config.
  enabled: true 
    isCopyrightMandatory: true
    copyrightText: Copyright (c) Jeff Lebowski, 2012-2020. All rights reserved.

Note, that you can specify and put diktat-analysis.yml that contains configuration of diktat in the parent directory of your project on the same level where build.gradle/pom.xml is stored.
See default configuration in diktat-analysis.yml
Also see the list of all rules supported by diKTat.

Suppress warnings on individual code blocks

In addition to enabling/disabling warning globally via config file (enable = false), you can suppress warnings by adding @Suppress annotation on individual code blocks

For example:

class SomeClass {
    fun methODTREE(): String {


Suppress groups of inspections

It is easy to suppress even groups of inspections in diKTat.

These groups are linked to chapters of Codestyle.

To disable chapters, you will need to add the following configuration to common configuration (- name: DIKTAT_COMMON):

    disabledChapters: "1, 2, 3"

Mapping of inspections to chapters can be found in Groups of Inspections .

How to contribute?

Main components are:

  1. diktat-rules — number of rules that are supported by diKTat;
  2. diktat-test-framework — functional/unit test framework that can be used for running your code fixer on the initial code and compare it with the expected result;
  3. also see our demo: diktat-demo in a separate repository.

Mainly we wanted to create a common configurable mechanism that will give us a chance to enable/disable and customize all rules. That's why we added logic for:

  1. Parsing .yml file with configurations of rules and passing it to visitors;
  2. Passing information about properties to visitors. This information is very useful, when you are trying to get, for example, a filename of file where the code is stored;
  3. We added a bunch of visitors, checkers and fixers that will extended KTlint functionaliity with code style rules;
  4. We have proposed a code style for Kotlin language.

Before you make a pull request, make sure the build is clean as we have lot of tests and other prechecks:

$ mvn clean install

Also see our Contributing Policy and Code of Conduct


Strict coding standard for Kotlin and a custom set of rules for detecting code smells, code style issues and bugs

Diktat Info

⭐ Stars 339
🔗 Source Code
🕒 Last Update 6 months ago
🕒 Created 2 years ago
🐞 Open Issues 91
➗ Star-Issue Ratio 4
😎 Author analysis-dev