Meet detekt, a static code analysis tool for the Kotlin programming language. It operates on the abstract syntax tree provided by the Kotlin compiler.
- code smell analysis for your kotlin projects
- complexity report based on logical lines of code, McCabe complexity and amount of code smells
- highly configurable (rule set or rule level)
- suppress findings with Kotlin's @Suppress and Java's @SuppressWarnings annotations
- specify code smell thresholds to break your build or print a warning
- code Smell baseline and ignore lists for legacy projects
- gradle plugin for code analysis via Gradle builds
- gradle tasks to use local
intellij
distribution for formatting and inspecting kotlin code - optionally configure detekt for each sub module by using profiles (gradle-plugin)
- sonarqube integration
- extensible by own rule sets and
FileProcessListener's
- intellij integration
- unofficial maven plugin by the user Ozsie
Visit https://arturbosch.github.io/detekt/ for installation guides, release notes, migration guides, rule descriptions and configuration options.
git clone https://github.com/arturbosch/detekt
cd detekt
./gradlew build shadowJar
java -jar detekt-cli/build/libs/detekt-cli-[version]-all.jar --help
buildscript {
repositories {
jcenter()
}
}
plugins {
id "io.gitlab.arturbosch.detekt" version "1.0.0.[version]"
}
detekt {
version = "1.0.0.[version]"
defaultProfile {
input = file("src/main/kotlin")
filters = ".*/resources/.*,.*/build/.*"
}
}
detekt itself provides a wrapper over KtLint as a formatting
rule set
which can be easily added to the gradle configuration:
dependencies {
detekt "io.gitlab.arturbosch.detekt:detekt-formatting:1.0.0.[version]"
}
Likewise custom extensions can be added to detekt.
If you contributed to detekt but your name is not in the list, please feel free to add yourself to it!
- Artur Bosch - Maintainer
- Marvin Ramin - Collaborator, Bunch of rules, Active on Issues, refactorings, MultiRule
- schalks - Collaborator, Active on Issues, Bunch of rules, Project metrics
- Niklas Baudy - Active on Issues, Bunch of rules, Bug fixes
- lummax - Cli enhancements
- Svyatoslav Chatchenko - Active on Issues, NamingConventions and UnusedImport fixes
- Sean Flanigan - Config from classpath resource
- Sebastian Schuberth - Active on Issues, Windows support
- Olivier Lemasle - NP-Bugfix, rules fixes, Gradle plugin improvement
- Marc Prengemann - Support for custom output formats, prototyped Rule-Context-Issue separation
- Sebastiano Poggi - Enhanced milestone report script, Magic number fixes
- Ilya Tretyakov - Sonar runs should not auto correct formatting.
- Andrey T - Readme fix
- Ivan Balaksha - Rules: UnsafeCast, SpreadOperator, UnsafeCallOnNullableType, LabeledExpression
- Anna Y - Readme fix
- Karol Wrótniak - Treat comments as not empty blocks
- Radim Vaculik - VariableMaxLength - bugfix
- Martin Nonnenmacher - UndocumentedPublicClass - enum support
- Dmytro Troynikov - Updated Magic Number rule to ignore Named Arguments
- Andrew Ochsner - Updated Readme for
failFast
option - Paul Merlin - Gradle build improvements
- Konstantin Aksenov - Coding improvement
- Matthew Haughton - Started type resolution, Dependency updates, Coding + Documentation improvements
- Janusz Bagiński - Fixed line number reporting for MaxLineLengthRule
- Mike Kobit - Gradle build improvements
- Philipp Hofmann - Readme improvements
- Olivier PEREZ - Fixed Typo in Readme
- Sebastian Kaspari - Html-Output-Format, Documentation fix
- Ilya Zorin - Rule improvement: UnnecessaryAbstractClass
- Gesh Markov - Improve error message for incorrect configuration file
- Patrick Pilch - Rule improvement: ReturnCount
- Serj Lotutovici - Rule improvement: LongParameterList
- Dmitry Primshyts - Rule improvement: MagicNumber
- Egor Neliuba - Rule improvement: EmptyFunctionBlock, EmptyClassBlock
- Said Tahsin Dane - Gradle plugin improvements
- Misa Torres - Added: TrailingWhitespace and NoTabs rules
- R.A. Porter - Updated Readme links to RuleSets
- Robbin Voortman - Rule improvement: MaxLineLength
- Mike Gorunov — Rule improvement: UndocumentedPublicFunction
- Joey Kaan - New rule: MandatoryBracesIfStatements
- Dmitriy Samaryan - Rule fix: SerialVersionUIDInSerializableClass
- Mariano Simone - Rule improvement: UnusedPrivateMember
- Shunsuke Maeda - Fix: to work on multi module project using maven plugin
- Scott Kennedy - Minor fixes
As mentioned in...
- @medium/acerezoluna/static-code-analysis-tools-for-kotlin-in-android
- @medium/annayan/writing-custom-lint-rules-for-your-kotlin-project-with-detekt
- Free Continuous Integration for modern Android apps with CircleCI
- Static code analysis for Kotlin in Android
- The Art of Android DevOps
- Android Basics: Continuous Integration
- Kotlin Static Analysis — why and how?
- Check the quality of Kotlin code
Integrations:
- SonarKotlin
- Codacy
- Gradle plugin that generates ErrorProne, Findbugs, Checkstyle, PMD, CPD, Lint, Detekt & Ktlint Tasks for every subproject
- Java library for parsing report files from static code analysis
- sputnik is a free tool for static code review and provides support for detekt
- Novoda Gradle Static Analysis plugin
- Maven plugin that wraps the Detekt CLI
- JetBrains - Creating Intellij + Kotlin
- PMD & Checkstyle & KtLint - Ideas for threshold values and style rules