detekt

Additional

Language
Kotlin
Version
v1.16.0 (Mar 11, 2021)
Created
Oct 24, 2016
Updated
Mar 12, 2021
Owner
Artur Bosch (arturbosch)
Contributors
Egor Neliuba (egor-n)
Artem Zinnatullin :slowpoke: (artem-zinnatullin)
Pavlos-Petros Tournaris (pavlospt)
Sebastiano Poggi (rock3r)
Janusz Bagiński (jbaginski)
Jonas Alves (jonasfa)
Sebastian Schuberth (sschuberth)
Scott Kennedy (scottkennedy)
Nelson Osacky (runningcode)
Sergey Solovyev (serso)
Brais Gabín (BraisGabin)
Serj Lotutovici (serj-lotutovici)
Rafael Toledo (rafaeltoledo)
Karol Wrótniak (koral--)
Sergii Pechenizkyi (plastiv)
dimsuz
The Gitter Badger (gitter-badger)
Said Tahsin Dane (tasomaniac)
Show all (151)151
Activity
Badge
Generate
Download
Source code

Advertisement

detekt

Meet detekt, a static code analysis tool for the Kotlin programming language. It operates on the abstract syntax tree provided by the Kotlin compiler.

Features

  • Code smell analysis for your Kotlin projects
  • Complexity reports based on lines of code, cyclomatic complexity and amount of code smells
  • Highly configurable rule sets
  • Suppression of findings with Kotlin's @Suppress and Java's @SuppressWarnings annotations
  • Specification of quality gates which will break your build
  • Code Smell baseline and suppression for legacy projects
  • Gradle plugin for code analysis via Gradle builds
  • SonarQube integration
  • Extensibility by enabling incorporation of personal rule sets, FileProcessListener's and OutputReport's
  • IntelliJ integration
  • Third party integrations for Maven, Bazel and Github Actions (Docker based and Javascript based)

Project Website

Visit the project website for installation guides, release notes, migration guides, rule descriptions and configuration options.

Quick-Links

Quick Start ...

with the command-line interface

curl -sSLO https://github.com/detekt/detekt/releases/download/v[version]/detekt && chmod a+x detekt
./detekt --help

You can find other ways to install detekt here

with Gradle

Gradle 5.4+ is required:

buildscript {
    repositories {
        jcenter()
    }

    // or

    mavenCentral()
    jcenter {
        content {
            // just allow to include kotlinx projects
            // detekt needs 'kotlinx-html' for the html report
            includeGroup "org.jetbrains.kotlinx"
        }
    }
}

plugins {
    id("io.gitlab.arturbosch.detekt").version("[version]")
}

detekt {
    buildUponDefaultConfig = true // preconfigure defaults
    allRules = false // activate all available (even unstable) rules.
    config = files("$projectDir/config/detekt.yml") // point to your custom config defining rules to run, overwriting default behavior
    baseline = file("$projectDir/config/baseline.xml") // a way of suppressing issues before introducing detekt

    reports {
        html.enabled = true // observe findings in your browser with structure and code snippets
        xml.enabled = true // checkstyle like format mainly for integrations like Jenkins
        txt.enabled = true // similar to the console output, contains issue signature to manually edit baseline files
        sarif.enabled = true // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with Github Code Scanning
    }
}


// Groovy dsl
tasks.detekt.jvmTarget = "1.8"

// or

// Kotlin dsl
tasks {
    withType<Detekt> {
        // Target version of the generated JVM bytecode. It is used for type resolution.
        this.jvmTarget = "1.8"
    }
}

See maven central for releases and sonatype for snapshots.

If you want to use a SNAPSHOT version, you can find more info on this documentation page.

Adding more rule sets

detekt itself provides a wrapper over ktlint as a formatting rule set which can be easily added to the Gradle configuration:

dependencies {
    detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:[version]"
}

Likewise custom extensions can be added to detekt.

Contributors

If you contributed to detekt but your name is not in the list, please feel free to add yourself to it!

Mentions

As mentioned in...

Integrations:

Custom rules from 3rd parties:

Credits