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
- Suppress findings with Kotlin's
@Suppress
and Java's@SuppressWarnings
annotations - Specify code smell thresholds to break your build
- 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 - SonarQube integration
- Extensible by own rule sets,
FileProcessListener's
andOutputReport's
- IntelliJ integration
- Unofficial Maven plugin by Ozsie
Visit https://arturbosch.github.io/detekt/ for installation guides, release notes, migration guides, rule descriptions and configuration options.
- Changelog and migration guides: https://arturbosch.github.io/detekt/changelog.html
- Available CLI options: https://arturbosch.github.io/detekt/cli.html
- Rule set and rule descriptions: https://arturbosch.github.io/detekt/complexity.html
- Writing custom rules and extending detekt: https://arturbosch.github.io/detekt/extensions.html
- Suppressing findings? https://arturbosch.github.io/detekt/suppressing-rules.html https://arturbosch.github.io/detekt/baseline.html
- Configuring detekt? https://arturbosch.github.io/detekt/configurations.html
- Sample gradle integrations examples
- multi project (kotlin dsl): https://github.com/arturbosch/detekt/blob/master/build.gradle.kts
- single project (groovy dsl): https://github.com/arturbosch/kutils/blob/master/build.gradle
- single project (unofficial maven plugin): https://github.com/arturbosch/sonar-kotlin/blob/master/pom.xml
git clone https://github.com/arturbosch/detekt
cd detekt
./gradlew build shadowJar
java -jar detekt-cli/build/libs/detekt-cli-[version]-all.jar --help
Gradle 4.9+ is required:
buildscript {
repositories {
jcenter()
}
}
plugins {
id("io.gitlab.arturbosch.detekt").version("[version]")
}
detekt {
toolVersion = "[version]"
input = files("src/main/kotlin")
filters = ".*/resources/.*,.*/build/.*"
baseline = file("my-detekt-baseline.xml") // Just if you want to create a baseline file.
}
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.
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 - Added 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. New Rules: UnusedPrivateClass, VarCouldBeVal
- Shunsuke Maeda - Fix: to work on multi module project using maven plugin
- Mikhail Levchenko - New rules: Unnecessary let, ExplicitItLambdaParameter
- Scott Kennedy - Minor fixes
- Mickele Moriconi - Added: ConstructorParameterNaming and FunctionParameterNaming rules
- Lukasz Jazgar - Fixed configuring formatting rules
- Pavlos-Petros Tournaris - Lazy evaluation of Regex in Rules
- Erhard Pointl - Kotlin DSL and Gradle enhancements
- Tyler Thrailkill - FunctionNaming rule enhancements
- Tarek Belkahia - TooManyFunctions rule options
- Bournane Abdelkrim - Fix typos
- Rafael Toledo - Fix Gradle plugin badge
- Alberto Ballano - ExceptionRaisedInUnexpectedLocation rule improvements
- Guido Pio Mariotti - Documentation improvement
- Mygod - UnusedImports rule improvement
- Andreas Volkmann - yaml code comments
- glammers - Documentation improvement
- Ahmad El-Melegy - yaml syntax fix
- Arjan Kleene - Add unnecessary apply rule
- Paweł Gajda - Rule improvement: FunctionParameterNaming
- Alistair Sykes - Doc improvement
- Andrew Arnott - UnusedPrivateMember improvement
- Tyler Wong - UnderscoresInNumericLiterals rule
- Daniele Conti - ObjectPropertyNaming improvement
As mentioned in...
- SBCARS '18 - Are you still smelling it?: A comparative study between Java and Kotlin language by Flauzino et al.
- KotlinConf 2018 - Safe(r) Kotlin Code - Static Analysis Tools for Kotlin by Marvin Ramin
- droidcon NYC 2018 - Static Code Analysis For Kotlin
- Kotlin on Code Quality Tools - by @vanniktech Presentation Slides
- @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
- Gradle plugin that helps facilitate GitHub PR checking and automatic commenting of violations
- JetBrains - Creating Intellij + Kotlin
- PMD & Checkstyle & KtLint - Ideas for threshold values and style rules