mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
99 lines
3.1 KiB
Plaintext
99 lines
3.1 KiB
Plaintext
---
|
|
title: "Welcome"
|
|
keywords: [detekt, static, analysis, code, kotlin]
|
|
sidebar_position: 1
|
|
summary:
|
|
---
|
|
|
|

|
|

|
|
|
|
### Features
|
|
|
|
- Code smell analysis for your [Kotlin projects](https://kotlinlang.org/).
|
|
- Highly configurable rule sets.
|
|
- Code Smell baseline and suppression for legacy projects.
|
|
- Suppression of findings with `@Suppress` annotations.
|
|
- Support for different report formats: html, markdown, [SARIF](https://sarifweb.azurewebsites.net/) and xml (checkstyle). Is it not enough? You can extend detekt and create your own reports.
|
|
- Extensibility by enabling incorporation of personal rule sets, `FileProcessListener's` and `OutputReport's`.
|
|
- Complexity reports based on lines of code, cyclomatic complexity and number of code smells.
|
|
- First party integration with Gradle with our [Gradle plugin](#with-gradle).
|
|
- A community of [third party plugins](https://github.com/topics/detekt-plugin) that adds more rules and features to detekt.
|
|
|
|
### Quick Start with Gradle
|
|
|
|
Apply the following configuration to your Gradle project build file:
|
|
|
|
```kotlin
|
|
plugins {
|
|
id("io.gitlab.arturbosch.detekt").version("[detekt_version]")
|
|
}
|
|
|
|
repositories {
|
|
mavenCentral()
|
|
}
|
|
```
|
|
|
|
The format is very similar if you use the Gradle Groovy DSL. You can find what is the **latest version of detekt** in
|
|
the [release notes](/docs/introduction/changelog).
|
|
|
|
Once you have set up detekt in your project, simply run `gradle detekt`.
|
|
|
|
To change the default behaviour of detekt rules, first generate yourself a detekt configuration file by running the
|
|
`detektGenerateConfig` task and applying any changes to the generated file.
|
|
|
|
Don't forget to reference the newly generated config inside the `detekt { }` closure. Optionally, it is possible to
|
|
slim down the configuration file to only the changes from the default configuration, by applying the
|
|
`buildUponDefaultConfig` option:
|
|
|
|
```kotlin
|
|
detekt {
|
|
toolVersion = "[detekt_version]"
|
|
config = files("config/detekt/detekt.yml")
|
|
buildUponDefaultConfig = true
|
|
}
|
|
```
|
|
|
|
To enable/disable detekt reports use the `withType` method to set defaults for all detekt tasks at once:
|
|
|
|
```kotlin
|
|
// Kotlin DSL
|
|
tasks.withType<Detekt>().configureEach {
|
|
reports {
|
|
xml.required.set(true)
|
|
html.required.set(true)
|
|
txt.required.set(true)
|
|
sarif.required.set(true)
|
|
md.required.set(true)
|
|
}
|
|
}
|
|
```
|
|
|
|
```groovy
|
|
// Groovy DSL
|
|
tasks.withType(Detekt).configureEach {
|
|
reports {
|
|
xml.required.set(true)
|
|
html.required.set(true)
|
|
txt.required.set(true)
|
|
sarif.required.set(true)
|
|
md.required.set(true)
|
|
}
|
|
}
|
|
```
|
|
|
|
See [reporting](/docs/introduction/reporting) docs for more details on configuring reports.
|
|
|
|
### Adding more rule sets
|
|
|
|
detekt itself provides a wrapper over [ktlint](https://github.com/pinterest/ktlint) as the `formatting` rule set
|
|
which can be easily added to the gradle configuration:
|
|
|
|
```gradle
|
|
dependencies {
|
|
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:[detekt_version]"
|
|
}
|
|
```
|
|
|
|
Likewise custom [extensions](/docs/introduction/extensions) can be added to detekt.
|