Skip to content

Commit

Permalink
Prepare Detekt 1.23.0 (#6120)
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico committed May 24, 2023
1 parent f3f0ce4 commit ad80630
Show file tree
Hide file tree
Showing 40 changed files with 10,253 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/Versions.kt
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget

object Versions {

const val DETEKT: String = "1.23.0-RC3"
const val DETEKT: String = "1.23.0"
const val SNAPSHOT_NAME: String = "main"
val JVM_TARGET: JvmTarget = JvmTarget.JVM_1_8

Expand Down
105 changes: 105 additions & 0 deletions website/docs/gettingstarted/compilerplugin.mdx
@@ -0,0 +1,105 @@
---
title: "Run detekt using the Compiler Plugin"
keywords: [detekt, static, analysis, code, kotlin]
sidebar:
permalink: compilerplugin.html
folder: gettingstarted
summary:
sidebar_position: 7
---

You can integrate detekt in your project using the Detekt Compiler Plugin instead of the classic [Detekt Gradle Plugin](/docs/gettingstarted/gradle). Detekt offers a compiler plugin for K1 which allows you to run detekt as part of the Kotlin compilation process. This allows you to run detekt on your code without having separate tasks to invoke and results in much faster execution of detekt, especially if you're using [type resolution](/docs/gettingstarted/type-resolution).

:::caution

Please note that Detekt Compiler Plugin is an **experimental extension** of detekt. We expect it to be stable with the upcoming release of detekt (2.x)

:::

## Using the Compiler Plugin

To use the detekt Compiler Plugin, you will have to add the following Gradle Plugin:

```kotlin
plugins {
id("io.github.detekt.gradle.compiler-plugin") version "[detekt_version]"
}
```

## Configuring the Compiler Plugin

The compiler plugin can be configured using the `react{}` block in your gradle file.

The following options are allowed:

```kotlin
detekt {
// Define the detekt configuration(s) you want to use.
// Defaults to the default detekt configuration.
config.setFrom("path/to/config.yml")

// Applies the config files on top of detekt's default config file. `false` by default.
buildUponDefaultConfig = false

// Turns on all the rules. `false` by default.
allRules = false

// Specifying a baseline file. All findings stored in this file in subsequent runs of detekt.
baseline = file("path/to/baseline.xml")

// Disables all default detekt rulesets and will only run detekt with custom rules
// defined in plugins passed in with `detektPlugins` configuration. `false` by default.
disableDefaultRuleSets = false

// Adds debug output during task execution. `false` by default.
debug = false

// Kill switch to turn off the Compiler Plugin execution entirely.
enableCompilerPlugin = true
}
```

Moreover, detekt reports can be configured at the Kotlin Compilation tasks level as follows

```kotlin
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
detekt {
reports {
xml.enabled.set(true)
txt.enabled.set(false)
create("custom") {
enabled.set(false)
}
}
}
}
```

## Adding third party plugins

As for the Detekt Gradle Plugin, you can add third party plugins to the Compiler Plugin using the `detektPlugins` configuration.

```kotlin
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:[detekt_version]")
}
```

## Running the Compiler Plugin

The compiler plugin will run during your `compileKotlin` tasks execution:

```shell
$ ./gradlew compileKotlin

> Task :example:compileKotlin
w: Analysis failed with 1 weighted issues.
w: file:///.../example/src/main/java/Sample.kt:4:17 MagicNumber: This expression contains a magic number. Consider defining it to a well named constant.

BUILD SUCCESSFUL in 1s
5 actionable tasks: 1 executed, 4 up-to-date
```

## Known Issues

1. The rule `InvalidPackageDeckaration` is known to not be working well with the Compiler Plugin [#5747](https://github.com/detekt/detekt/issues/5747).
38 changes: 32 additions & 6 deletions website/src/pages/changelog.md
Expand Up @@ -6,30 +6,37 @@ keywords: [changelog, release-notes, migration]

# Changelog and Migration Guide

#### 1.23.0-RC3 - 2023-04-29
#### 1.23.0 - 2023-05-22

##### Notable Changes

- This is the first version of Detekt that ships with the `detekt-compiler-plugin`. The Detekt Compiler plugin is still experimental but we're moving it closer to Detekt to make it easier to integrate. From now on the compiler plugin will follow the same versioning schema as Detekt. We invite you to try it and provide feedback till we stabilize it. - [#5492](https://github.com/detekt/detekt/pull/5492)
- We added **20** new Rules to detekt
- This is the first version of Detekt that ships with the `detekt-compiler-plugin`. The [Detekt Compiler plugin](/docs/gettingstarted/compilerplugin) is still experimental, but we're moving it closer to Detekt to make it easier to integrate. From now on the compiler plugin will follow the same versioning schema as Detekt. We invite you to try it and provide feedback till we stabilize it. You can read more about it in the [official documentation page](/docs/gettingstarted/compilerplugin) - [#5492](https://github.com/detekt/detekt/pull/5492)
- We added **25** new Rules to detekt
- `BracesOnIfStatements` - [#5700](https://github.com/detekt/detekt/pull/5700)
- `BracesOnWhenStatements` - [#5838](https://github.com/detekt/detekt/pull/5838)
- `CastNullableToNonNullableType` - [#5653](https://github.com/detekt/detekt/pull/5653)
- `DoubleNegativeLambda` - [#5937](https://github.com/detekt/detekt/pull/5937)
- `ForbiddenAnnotation` - [#5515](https://github.com/detekt/detekt/pull/5515)
- `PropertyUsedBeforeDeclaration` - [#6062](https://github.com/detekt/detekt/pull/6062)
- `StringShouldBeRawString` - [#5705](https://github.com/detekt/detekt/pull/5705)
- `SuspendFunSwallowedCancellation` - [#5666](https://github.com/detekt/detekt/pull/5666)
- `UnusedParameter` - [#5722](https://github.com/detekt/detekt/pull/5722)
- `UnusedPrivateProperty` - [#5722](https://github.com/detekt/detekt/pull/5722)
- Plus the bump to KtLint 0.49.0 added the following rules to the `detekt-formatting` ruleset:
- `UseLet` - [#6091](https://github.com/detekt/detekt/pull/6091)
- `UnnecessaryBracesAroundTrailingLambda` - [#6029](https://github.com/detekt/detekt/pull/6029)
- Plus the bump to KtLint 0.49.1 added the following rules to the `detekt-formatting` ruleset:
- `ClassName` - [#6037](https://github.com/detekt/detekt/pull/6037)
- `EnumWrapping` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `FunctionName` - [#6037](https://github.com/detekt/detekt/pull/6037)
- `IfElseBracing` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `IfElseWrapping` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `MultilineExpressionWrapping` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `NoBlankLineInList` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `NoConsecutiveComments` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `NoEmptyFirstLineInClassBody` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `NoSingleLineBlockCommentRule` - [#6104](https://github.com/detekt/detekt/pull/6104)
- `ParameterWrapping` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `PropertyName` - [#6037](https://github.com/detekt/detekt/pull/6037)
- `PropertyWrapping` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `StringTemplateIndent` - [#6028](https://github.com/detekt/detekt/pull/6028)
- `TryCatchFinallySpacing` - [#6028](https://github.com/detekt/detekt/pull/6028)
Expand All @@ -47,11 +54,22 @@ keywords: [changelog, release-notes, migration]
- We fixed the `includes`/`excludes` logic on the config file as they were overriding each other - [#5782](https://github.com/detekt/detekt/pull/5782)
- We fully removed support for Spek from `detekt-test-utils`. The recommended testing framework is JUnit - [#5785](https://github.com/detekt/detekt/pull/5785)
- The minimum supported Gradle version is now `v6.8.3` - [#5616](https://github.com/detekt/detekt/pull/5616)
- This version of detekt is built with Gradle `v8.0.2`, AGP `8.0.0`, Kotlin `1.8.21` and KtLint `0.49.0` (see [#5893](https://github.com/detekt/detekt/pull/5893) [#5723](https://github.com/detekt/detekt/pull/5723) [#5877](https://github.com/detekt/detekt/pull/5877) [#6028](https://github.com/detekt/detekt/pull/6028) [#6043](https://github.com/detekt/detekt/pull/6043) [#5995](https://github.com/detekt/detekt/pull/5995))
- This version of detekt is built with Gradle `v8.1`, AGP `8.0.1`, Kotlin `1.8.21` and KtLint `0.49.1` (see [#5893](https://github.com/detekt/detekt/pull/5893) [#5723](https://github.com/detekt/detekt/pull/5723) [#5877](https://github.com/detekt/detekt/pull/5877) [#6028](https://github.com/detekt/detekt/pull/6028) [#6043](https://github.com/detekt/detekt/pull/6043) [#5995](https://github.com/detekt/detekt/pull/5995) [#5996](https://github.com/detekt/detekt/pull/5996))
- We now added a [Code of Conduct](https://github.com/detekt/detekt/blob/main/.github/CODE_OF_CONDUCT.md) to our repo. Please read it and follow it when interacting with our community on our channels.

##### Changelog

- SerialVersionUIDInSerializableClass - Update the error location - [#6114](https://github.com/detekt/detekt/pull/6114)
- Reduce LoopWithTooManyJumpStatements finding scope - [#6110](https://github.com/detekt/detekt/pull/6110)
- Add alias for SuspendFunWithCoroutineScopeReceiver - [#6089](https://github.com/detekt/detekt/pull/6089)
- CastNullableToNonNullableType - Check the SimpleType instead of typeElement - [#6071](https://github.com/detekt/detekt/pull/6071)
- Update plugin com.gradle.enterprise to v3.13.1 - [#6069](https://github.com/detekt/detekt/pull/6069)
- CanBeNonNullable: Check parent condition for checking if nullability info is used or not - [#6064](https://github.com/detekt/detekt/pull/6064)
- Add configuration to add alternate trimming methods - [#6063](https://github.com/detekt/detekt/pull/6063)
- Check if property is documented at class header - [#6061](https://github.com/detekt/detekt/pull/6061)
- OutdatedDocumentation - Check if only public property is documented - [#6057](https://github.com/detekt/detekt/pull/6057)
- UnnecessaryLet: fix false positive in call chains - [#6052](https://github.com/detekt/detekt/pull/6052)
- Add `comments` with a list of regexes to `ForbiddenComment` - [#5981](https://github.com/detekt/detekt/pull/5981)
- Fix incomplete `requireRootInDeclaration` check in `InvalidPackageDeclaration` - [#6045](https://github.com/detekt/detekt/pull/6045)
- BracesOnWhenStatements: fix false positive for necessary braces - [#6042](https://github.com/detekt/detekt/pull/6042)
- Fix redundant ClassOrdering violations using maximum increasing section - [#6003](https://github.com/detekt/detekt/pull/6003)
Expand Down Expand Up @@ -144,6 +162,10 @@ keywords: [changelog, release-notes, migration]

##### Dependency Updates

- Update dependency io.github.detekt.sarif4k:sarif4k to v0.4.0 - [#6113](https://github.com/detekt/detekt/pull/6113)
- Update dependency org.jetbrains.kotlinx:kotlinx-coroutines-core to v1.7.1 - [#6097](https://github.com/detekt/detekt/pull/6097)
- Update dependency org.jetbrains.kotlinx:kotlinx-coroutines-core to v1.7.0 - [#6074](https://github.com/detekt/detekt/pull/6074)
- Update com.android.tools.build - [#6065](https://github.com/detekt/detekt/pull/6065)
- Update JaCoCo to v0.8.10 - [#6044](https://github.com/detekt/detekt/pull/6044)
- Update plugin pluginPublishing to v1.2.0 - [#5975](https://github.com/detekt/detekt/pull/5975)
- Update ktlint to v0.48.1 - [#5661](https://github.com/detekt/detekt/pull/5661)
Expand All @@ -160,6 +182,10 @@ keywords: [changelog, release-notes, migration]

##### Housekeeping & Refactorings

- Inline Cases enum and inline other external test code into the test classes - [#6107](https://github.com/detekt/detekt/pull/6107)
- Update codecov/codecov-action digest to eaaf4be - [#6102](https://github.com/detekt/detekt/pull/6102)
- Remove unnecessary baselines - [#6092](https://github.com/detekt/detekt/pull/6092)
- Remove unused `dependenciesAsNames` - [#6059](https://github.com/detekt/detekt/pull/6059)
- Reduce eager POM task creation - [#6041](https://github.com/detekt/detekt/pull/6041)
- Improve our configuration of `ClassNaming` and `FunctionNaming` - [#6019](https://github.com/detekt/detekt/pull/6019)
- Comment text in the Issue/PR Template - [#5992](https://github.com/detekt/detekt/pull/5992)
Expand Down Expand Up @@ -191,7 +217,7 @@ keywords: [changelog, release-notes, migration]

##### Contributors

We would like to thank the following contributors that made this release possible: @3flex, @BeBAKE, @BraisGabin, @Goooler, @SaumyaBhushan, @TWiStErRob, @VitalyVPinchuk, @adef145, @asomov, @atulgpt, @chao2zhang, @cketti, @cortinico, @drawers, @dzirbel, @igorwojda, @lexa-diky, @luanpotter, @marschwar, @mjovanc, @mmorozkov, @ncteisen, @osipxd, @ov7a, @schalkms, @t-kameyama
We would like to thank the following contributors that made this release possible: @3flex, @BeBAKE, @BraisGabin, @Goooler, @SaumyaBhushan, @TWiStErRob, @VitalyVPinchuk, @adef145, @asomov, @atulgpt, @chao2zhang, @cketti, @cortinico, @drawers, @dzirbel, @igorwojda, @lexa-diky, @luanpotter, @marschwar, @mjovanc, @mmorozkov, @ncteisen, @osipxd, @ov7a, @schalkms, @t-kameyama, @tresni

See all issues at: [1.23.0](https://github.com/detekt/detekt/milestone/88)

Expand Down
2 changes: 1 addition & 1 deletion website/src/remark/detektVersionReplace.js
Expand Up @@ -3,7 +3,7 @@ const visit = require("unist-util-visit");
// Remark plugin that is replacing the [detekt_version] with the latest
// released version. Please note that this field is updated automatically
// by the `applyDocVersion` task.
const detektVersion = "1.23.0-RC3";
const detektVersion = "1.23.0";

const plugin = (options) => {
const transformer = async (ast) => {
Expand Down
@@ -0,0 +1,4 @@
{
"label": "Getting Started",
"position": 3
}
@@ -0,0 +1,10 @@
```
Usage: java -jar detekt-generator-[detekt_version]-all.jar [options]
Options:
--generate-custom-rule-config, -gcrc
Generate custom rules configuration files. The files will be
placed under 'resources' folder of each rule respectively
(e.g. 'custom-rule/src/main/resources/config/config.yml').
--input, -i
Input paths to rules to analyze. Multiple paths are separated by comma.
```
@@ -0,0 +1,89 @@
```
Usage: detekt [options]
Options:
--all-rules
Activates all available (even unstable) rules.
Default: false
--auto-correct, -ac
Allow rules to auto correct code if they support it. The default rule
sets do NOT support auto correcting and won't change any line in the
users code base. However custom rules can be written to support auto
correcting. The additional 'formatting' rule set, added with
'--plugins', does support it and needs this flag.
Default: false
--base-path, -bp
Specifies a directory as the base path.Currently it impacts all file
paths in the formatted reports. File paths in console output and txt
report are not affected and remain as absolute paths.
--baseline, -b
If a baseline xml file is passed in, only new code smells not in the
baseline are printed in the console.
--build-upon-default-config
Preconfigures detekt with a bunch of rules and some opinionated defaults
for you. Allows additional provided configurations to override the
defaults.
Default: false
--classpath, -cp
EXPERIMENTAL: Paths where to find user class files and depending jar
files. Used for type resolution.
--config, -c
Path to the config file (path/to/config.yml). Multiple configuration
files can be specified with ',' or ';' as separator.
--config-resource, -cr
Path to the config resource on detekt's classpath (path/to/config.yml).
--create-baseline, -cb
Treats current analysis findings as a smell baseline for future detekt
runs.
Default: false
--debug
Prints extra information about configurations and extensions.
Default: false
--disable-default-rulesets, -dd
Disables default rule sets.
Default: false
--excludes, -ex
Globbing patterns describing paths to exclude from the analysis.
--generate-config, -gc
Export default config. Path can be specified with --config option
(default path: default-detekt-config.yml)
Default: false
--help, -h
Shows the usage.
--includes, -in
Globbing patterns describing paths to include in the analysis. Useful in
combination with 'excludes' patterns.
--input, -i
Input paths to analyze. Multiple paths are separated by comma. If not
specified the current working directory is used.
--jdk-home
EXPERIMENTAL: Use a custom JDK home directory to include into the
classpath
--jvm-target
EXPERIMENTAL: Target version of the generated JVM bytecode that was
generated during compilation and is now being used for type resolution
(1.8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 or 19)
Default: 1.8
--language-version
EXPERIMENTAL: Compatibility mode for Kotlin language version X.Y,
reports errors for all language features that came out later
Possible Values: [1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, 2.0]
--max-issues
Return exit code 0 only when found issues count does not exceed
specified issues count.
--parallel
Enables parallel compilation and analysis of source files. Do some
benchmarks first before enabling this flag. Heuristics show performance
benefits starting from 2000 lines of Kotlin code.
Default: false
--plugins, -p
Extra paths to plugin jars separated by ',' or ';'.
--report, -r
Generates a report for given 'report-id' and stores it on given 'path'.
Entry should consist of: [report-id:path]. Available 'report-id' values:
'txt', 'xml', 'html', 'md', 'sarif'. These can also be used in
combination with each other e.g. '-r txt:reports/detekt.txt -r
xml:reports/detekt.xml'
--version
Prints the detekt CLI version.
Default: false
```
69 changes: 69 additions & 0 deletions website/versioned_docs/version-1.23.0/gettingstarted/cli.mdx
@@ -0,0 +1,69 @@
---
title: "Run detekt using Command Line Interface"
keywords: [cli]
sidebar:
permalink: cli.html
folder: gettingstarted
summary:
sidebar_position: 1
---

import CliOptions from "./_cli-options.md";
import CliGeneratorOptions from "./_cli-generator-options.md";

## Install the cli

There are different ways to install the Command Line Interface (CLI):

### MacOS, with [Homebrew](https://brew.sh/):

```sh
brew install detekt
detekt [options]
```

### Windows, with [Scoop](https://scoop.sh/)

```powershell
scoop install detekt
detekt [options]
```

### Any OS:

```sh
curl -sSLO https://github.com/detekt/detekt/releases/download/v[detekt_version]/detekt-cli-[detekt_version].zip
unzip detekt-cli-[detekt_version].zip
./detekt-cli-[detekt_version]/bin/detekt-cli --help
```

### NixOS

As a prerequisite, you have to add the unstable channel via `nix-channel` and then execute the following command.

```sh
nix-shell -I nixpkgs=channel:nixpkgs-unstable -p detekt
```

## Use the cli

detekt will exit with one of the following exit codes:

| Exit code | Description |
| --------- | ------------------------------------------------------------------------------ |
| 0 | detekt ran normally and maxIssues count was not reached in BuildFailureReport. |
| 1 | An unexpected error occurred |
| 2 | MaxIssues count was reached in BuildFailureReport. |
| 3 | Invalid detekt configuration file detected. |

The following parameters are shown when `--help` is entered.

<CliOptions />

## Use the cli to generate configuration for custom rules

<CliGeneratorOptions />

```sh
java -jar detekt-generator-[detekt_version]-all.jar -gcrc -i /path/to/rule1, /path/to/rule2
```

0 comments on commit ad80630

Please sign in to comment.