### Start local development server with yarn start Source: https://github.com/detekt/detekt/blob/main/website/README.md Starts a local development server and opens a browser window. Most changes are reflected live without restarting the server. ```bash $ yarn start ``` -------------------------------- ### Install dependencies with yarn Source: https://github.com/detekt/detekt/blob/main/website/README.md Installs all dependencies for the detekt website project. ```bash $ yarn ``` -------------------------------- ### Configure detekt 2.0 preview in Gradle (Kotlin DSL) Source: https://github.com/detekt/detekt/blob/main/README.md Gradle Kotlin DSL setup for the detekt 2.0 preview (2.0.0-alpha.6). Includes configuration for default rules, custom config file, baseline, and multiple report formats, with JVM target 1.8. Requires Gradle 8.14.3+. ```kotlin plugins { id("dev.detekt") version "2.0.0-alpha.6" } repositories { mavenCentral() } detekt { buildUponDefaultConfig = true // preconfigure defaults allRules = false // do not activate every rule by default config.setFrom("$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 } tasks.withType().configureEach { reports { html.required.set(true) // observe findings in your browser with structure and code snippets checkstyle.required.set(true) // checkstyle(xml) like format mainly for integrations like Jenkins sarif.required.set(true) // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with GitHub Code Scanning markdown.required.set(true) // simple Markdown format } jvmTarget.set("1.8") } tasks.withType().configureEach { jvmTarget.set("1.8") } ``` -------------------------------- ### Commit message with Co-authored-by trailer Source: https://github.com/detekt/detekt/blob/main/AGENTS.md Example commit message format for AI-assisted contributions. Includes a Co-authored-by trailer to credit AI agents as co-authors. ```text feat: add new rule for detecting X Co-authored-by: Claude Co-authored-by: Your Name ``` -------------------------------- ### Rule Documentation KDoc Template Source: https://github.com/detekt/detekt/blob/main/AGENTS.md Use this KDoc template when implementing a new detekt rule. It requires a summary, a detailed explanation, and and examples. The class extends Rule and takes a Config parameter. ```kotlin /** * Summary of what the rule detects. * * Detailed explanation of why this is a code smell * and how to fix it. * * * // Bad code example * * * * // Good code example * */ class MyRule(config: Config) : Rule(config) { // Implementation } ``` -------------------------------- ### Configure detekt 1.x stable in Gradle (Kotlin DSL) Source: https://github.com/detekt/detekt/blob/main/README.md Gradle Kotlin DSL setup for the stable detekt 1.23.8 release. Configures default rules, custom config, baseline, and report formats (html, xml, sarif, md) with JVM target 1.8. Requires Gradle 6.8.3+. ```kotlin plugins { id("io.gitlab.arturbosch.detekt") version "1.23.8" } repositories { mavenCentral() } detekt { buildUponDefaultConfig = true // preconfigure defaults allRules = false // do not activate every rule by default config.setFrom("$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 } tasks.withType().configureEach { reports { html.required.set(true) // observe findings in your browser with structure and code snippets xml.required.set(true) // checkstyle-compatible XML format, mainly for integrations like Jenkins sarif.required.set(true) // standardized SARIF format (https://sarifweb.azurewebsites.net/) to support integrations with GitHub Code Scanning md.required.set(true) // simple Markdown format } jvmTarget = "1.8" } tasks.withType().configureEach { jvmTarget = "1.8" } ``` -------------------------------- ### Run detekt CLI with --help Source: https://github.com/detekt/detekt/blob/main/README.md Downloads the detekt CLI jar for a specific version and runs it with the --help flag to list available options. ```sh curl -sSLO https://github.com/detekt/detekt/releases/download/v[version]/detekt-cli-[version]-all.jar java -jar detekt-cli-[version]-all.jar --help ``` -------------------------------- ### Run all tests Source: https://github.com/detekt/detekt/blob/main/AGENTS.md Run all tests, including functional tests and functional tests against the minimum supported Gradle version. ```bash ./gradlew test detektFunctionalTest detektFunctionalTestMinSupportedGradle ``` -------------------------------- ### Build static site with yarn generate-and-build Source: https://github.com/detekt/detekt/blob/main/website/README.md Generates static content into the build directory, which can be served using any static content hosting service. ```bash $ yarn generate-and-build ``` -------------------------------- ### Clone and build detekt Source: https://github.com/detekt/detekt/blob/main/AGENTS.md Clone the detekt repository, optionally publish to Maven local before running Gradle plugin functional tests, and build the project while skipping slow documentation generation. ```bash git clone https://github.com/detekt/detekt.git cd detekt # NOTE: Only required before running Gradle plugin functional tests # ./gradlew publishToMavenLocal # Build (excluding slow documentation generation) ./gradlew build -x dokkaGenerate ``` -------------------------------- ### Sample3.kt lines 30-33 Source: https://github.com/detekt/detekt/blob/main/detekt-report-html/src/test/resources/HtmlOutputFormatTest.html Code snippet for the third issue in Sample3.kt, showing lines 30 to 33 with the info at line 33. ```kotlin 30 val val30 = 30 31 val val31 = 31 32 val val32 = 32 33 val val33 = 33 ``` -------------------------------- ### Full multi-module detekt configuration (Kotlin DSL) Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx Full detekt configuration for a multi-module Gradle project using the Kotlin DSL. Must be translated to Groovy if not using Kotlin DSL. Note the new toolVersion property and that config accepts multiple files. ```gradle plugins { id("io.gitlab.arturbosch.detekt") version "[1.0.0.RC9]" } ... subprojects { ... apply { plugin("io.gitlab.arturbosch.detekt") ... } val userHome = System.getProperty("user.home") detekt { debug = true toolVersion = usedDetektVersion config = files( project.rootDir.resolve("detekt-core/src/main/resources/default-detekt-config.yml"), project.rootDir.resolve("reports/failfast.yml") ) filters = ".*/resources/.*,.*/build/.*" baseline = project.rootDir.resolve("reports/baseline.xml") reports { xml.enabled = true html { enabled = true destination = project.rootDir.resolve("reports/detekt.html") } } idea { path = "$userHome/.idea" codeStyleScheme = "$userHome/.idea/idea-code-style.xml" inspectionsProfile = "$userHome/.idea/inspect.xml" report = "project.projectDir/reports" mask = "*.kt" } } ``` -------------------------------- ### Configure detekt for all subprojects Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx Apply detekt to all subprojects by configuring the detekt block in the root build file. ```gradle subprojects { detekt { // properties } } ``` -------------------------------- ### Old detekt configuration with profiles Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx Old configuration syntax using defaultProfile or profile("main") blocks, which was removed in RC9. ```gradle detekt { defaultProfile { // or profile("main") {...} // properties } } ``` -------------------------------- ### Migrate RuleSetProvider to return rule factories Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the migration of RuleSetProvider to return rule factories instead of instances. The ruleSetId is now a RuleSetId, and instance() takes no config and returns a list of rule constructors. ```diff class MyRuleSetProvider : RuleSetProvider { - override val ruleSetId = "MyRuleSet" + override val ruleSetId = RuleSetId("MyRuleSet") - override fun instance(config: Config) = RuleSet( - ruleSetId, - listOf( - MyRule(config), - ), - ) + override fun instance(): RuleSet = RuleSet( + ruleSetId, + listOf( + ::MyRule, + ), + ) } ``` -------------------------------- ### Generate rules documentation with yarn generate Source: https://github.com/detekt/detekt/blob/main/website/README.md Generates rules documentation from the detekt rule source code so it can be viewed on the website. ```bash $ yarn generate ``` -------------------------------- ### Sample1.kt lines 8-14 Source: https://github.com/detekt/detekt/blob/main/detekt-report-html/src/test/resources/HtmlOutputFormatTest.html Code snippet for the first issue in Sample1.kt, showing lines 8 to 14 with the error at line 11. ```kotlin 8 val val8 = 8 9 val val9 = 9 10 val val10 = 10 11 val val11 = 11 12 val val12 = 12 13 val val13 = 13 14 val val14 = 14 ``` -------------------------------- ### Migrate Rule class to 2.x API Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the migration from the 1.x Rule API to the 2.x API. The Rule constructor now takes a description parameter, Issue and Debt are removed, CodeSmell is renamed to Finding, and the issue override is gone. ```diff -class MyRule(config: Config) : Rule(config) { - override val issue = Issue( - javaClass.simpleName, - Severity.Style, - "Detects something I dislike.", - Debt.FIVE_MINS, - ) - - override fun visitNamedFunction(function: KtNamedFunction) { - report(CodeSmell(issue, Entity.from(function), "Don't do this.")) - } -} +class MyRule(config: Config) : Rule( + config, + description = "Detects something I dislike.", +) { + override fun visitNamedFunction(function: KtNamedFunction) { + report(Finding(Entity.from(function), "Don't do this.")) + } +} ``` -------------------------------- ### Add detekt-report-complexity and detekt-report-statistics plugins Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Adds the first-party plugins for the complexity and statistics reports, which moved from core. Use a detekt version that includes these plugins and keep the plugin versions aligned with detekt itself. ```kotlin dependencies { detektPlugins("dev.detekt:detekt-report-complexity:") detektPlugins("dev.detekt:detekt-report-statistics:") } ``` -------------------------------- ### New detekt configuration without profiles Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx New configuration syntax without profiles, introduced in RC9. ```gradle detekt { // properties } ``` -------------------------------- ### Generate documentation for rule changes Source: https://github.com/detekt/detekt/blob/main/AGENTS.md Generate documentation when modifying rules. ```bash ./gradlew generateDefaultDetektConfig generateDeprecationList ``` -------------------------------- ### Sample2.kt lines 19-25 Source: https://github.com/detekt/detekt/blob/main/detekt-report-html/src/test/resources/HtmlOutputFormatTest.html Code snippet for the second issue in Sample2.kt, showing lines 19 to 25 with the error at line 22. ```kotlin 19 val val19 = 19 20 val val20 = 20 21 val val21 = 21 22 val val22 = 22 23 val val23 = 23 24 val val24 = 24 25 val val25 = 25 ``` -------------------------------- ### Migration: build configuration with deprecated thresholds and new maxIssues Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx Shows the deprecated warningThreshold and failThreshold properties alongside the new maxIssues property. The threshold definition changed from value > threshold to value >= threshold, and the deprecated properties will be removed in a later release. ```yaml build: warningThreshold: 5 // deprecated failThreshold: 10 // deprecated maxIssues: 10 ``` -------------------------------- ### New Gradle detekt configuration with profiles Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx The new M12 way to configure the detekt Gradle plugin using profile closures. Allows different configurations for production and test code, and per-module detekt-rules configuration. ```groovy detekt { profile("main") { version = "1.0.0.M11" input = "$project.projectDir/src" filters = '.*/test/.*' config = "$project.projectDir/detekt-config.yml" output = "$project.projectDir/output.xml" } profile("test") { filters = ".*/src/main/kotlin/.*" config = "$project.projectDir/detekt-test-config.yml" } idea { path = "$userHome/.idea" codeStyleScheme = "$userHome/.idea/idea-code-style.xml" inspectionsProfile = "$userHome/.idea/inspect.xml" mask = "*.kt," } } ``` -------------------------------- ### Update @Configuration import to dev.detekt.api Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the new import path for the @Configuration annotation, which moved from an internal package to the public API. ```diff -import io.gitlab.arturbosch.detekt.api.internal.Configuration +import dev.detekt.api.Configuration ``` -------------------------------- ### Use lazy property assignment in detekt extension Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows how to use lazy property assignment with .set() in the detekt extension. ```diff detekt { - parallel = true - buildUponDefaultConfig = true + parallel.set(true) + buildUponDefaultConfig.set(true) } ``` -------------------------------- ### Update detektPlugins coordinates for formatting wrapper Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the change in coordinates for the formatting wrapper plugin. ```diff dependencies { - detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8") + detektPlugins("dev.detekt:detekt-rules-ktlint-wrapper:2.0.0") } ``` -------------------------------- ### Add libraries and ruleauthors rule sets for detekt 2.0.0-alpha.6 Source: https://github.com/detekt/detekt/blob/main/README.md Adds the libraries and ruleauthors rule sets from detekt for version 2.0.0-alpha.6. These are extra rule sets available from detekt and are added via Gradle dependencies. ```kotlin dependencies { detektPlugins("dev.detekt:detekt-rules-libraries:2.0.0-alpha.6") detektPlugins("dev.detekt:detekt-rules-ruleauthors:2.0.0-alpha.6") } ``` -------------------------------- ### CLI list separator change for --input Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the change in list separators for CLI options like --input. In 1.x, commas were accepted; in 2.x, only the platform path separator (colon on *nix, semicolon on Windows) is used. ```diff -detekt --input src/main/kotlin,src/test/kotlin +detekt --input src/main/kotlin:src/test/kotlin ``` -------------------------------- ### Gradle buildscript for applying detekt plugin Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx Shows the old and new Gradle plugin coordinates for applying the detekt plugin. The old coordinate is for version <= 1.0.0.RC9.2, the new one for version >= 1.0.0-RC10. ```groovy buildscript { repositories { jcenter() maven { url "https://plugins.gradle.org/m2/" } } dependencies { // https://mvnrepository.com/artifact/gradle.plugin.io.gitlab.arturbosch.detekt/detekt-gradle-plugin // for version <= 1.0.0.RC9.2 classpath "gradle.plugin.io.gitlab.arturbosch.detekt:detekt-gradle-plugin:[version]" // https://mvnrepository.com/artifact/io.gitlab.arturbosch.detekt/detekt-gradle-plugin?repo=gradle-plugins // for version >= 1.0.0-RC10 classpath "io.gitlab.arturbosch.detekt:detekt-gradle-plugin:[version]" } } apply plugin: "io.gitlab.arturbosch.detekt" ``` -------------------------------- ### Old Gradle detekt configuration without profiles Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx The previous way to configure the detekt Gradle plugin before M12, using a flat detekt closure. This is replaced by the profile-based configuration. ```groovy detekt { version = "1.0.0.M11" input = "$project.projectDir/src" filters = '.*/test/.*' config = "$project.projectDir/detekt-config.yml" output = "$project.projectDir/output.xml" idea { path = "$userHome/.idea" codeStyleScheme = "$userHome/.idea/idea-code-style.xml" inspectionsProfile = "$userHome/.idea/inspect.xml" mask = "*.kt," } } ``` -------------------------------- ### Gradle dependencies for detekt plugins Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx Defines custom detekt RuleSets and the detekt-formatting rules using the detektPlugins configuration. This is required for detekt RC10 and later. ```kotlin dependencies { detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:[version]") detektPlugins("your.custom.detekt.rules:rules:[version]") } ``` -------------------------------- ### Add formatting, libraries, and ruleauthors rule sets for detekt 1.23.8 Source: https://github.com/detekt/detekt/blob/main/README.md Adds the ktlint wrapper (as detekt-formatting) plus libraries and ruleauthors rule sets for detekt 1.23.8. For 1.23.8, the ktlint wrapper keeps its former detekt-formatting artifact name. ```kotlin dependencies { detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8") detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-libraries:1.23.8") detektPlugins("io.gitlab.arturbosch.detekt:detekt-rules-ruleauthors:1.23.8") } ``` -------------------------------- ### Update Gradle plugin imports to dev.detekt.gradle Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the new import paths for Gradle plugin extension points when extending the plugin with custom task types or convention plugins. ```diff -import io.gitlab.arturbosch.detekt.Detekt -import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask -import io.gitlab.arturbosch.detekt.extensions.DetektExtension -import io.gitlab.arturbosch.detekt.report.ReportMergeTask +import dev.detekt.gradle.Detekt +import dev.detekt.gradle.DetektCreateBaselineTask +import dev.detekt.gradle.extensions.DetektExtension +import dev.detekt.gradle.report.ReportMergeTask ``` -------------------------------- ### NoUnitKeyword compliant: no Unit Source: https://github.com/detekt/detekt/blob/main/detekt-generator/src/test/resources/RuleSet.md Compliant code for the NoUnitKeyword rule: no explicit :Unit return type. ```kotlin fun stuff() {} ``` -------------------------------- ### 2.x type-aware rule with RequiresAnalysisApi and analyze {} Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the 2.x style of a type-aware detekt rule using the RequiresAnalysisApi marker interface and the analyze {} block. This rule only runs in full analysis mode; in light mode it is skipped. ```kotlin class MyRule(config: Config) : Rule( config, description = "..." ), RequiresAnalysisApi { override fun visitCallExpression(expression: KtCallExpression) { analyze(expression) { val symbol = expression.resolveToCall()?.successfulFunctionCallOrNull()?.symbol // ... } } } ``` -------------------------------- ### Disable AGP 9.0.0 new DSL and built-in Kotlin in gradle.properties Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-2.0.0.mdx Add these properties to gradle.properties to disable the new DSL and built-in Kotlin in AGP 9.0.0 projects, which is required for this alpha of Detekt to run. ```properties android.newDsl=false android.builtInKotlin=false ``` -------------------------------- ### Run detekt on itself Source: https://github.com/detekt/detekt/blob/main/AGENTS.md Run detekt on itself. This must pass before submitting pull requests. ```bash ./gradlew detektMain detektTest detektFunctionalTest detektTestFixtures ``` -------------------------------- ### Rename `formatting` to `ktlint` and replace `android` flag Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the migration for the ktlint rule set: the ID changed from `formatting` to `ktlint`, and the `android` flag was replaced by `code_style` and `indentStyle`. The `DiscouragedCommentLocation` rule was removed. ```diff -formatting: +ktlint: active: true - android: false + code_style: 'intellij_idea' # or 'android_studio', 'ktlint_official' + indentStyle: 'space' autoCorrect: true ``` -------------------------------- ### Naming rule configuration for RC5-6 migration Source: https://github.com/detekt/detekt/blob/main/website/src/pages/changelog-rc.mdx YAML configuration for the new naming rules introduced in RC5-6: VariableNaming, ObjectPropertyNaming, and TopLevelPropertyNaming. These replace the removed ConstantNaming rule and add private property patterns. ```yaml VariableNaming: active: true variablePattern: '[a-z][A-Za-z0-9]*' privateVariablePattern: '(_)?[a-z][A-Za-z0-9]*' ObjectPropertyNaming: active: true propertyPattern: '[A-Za-z][_A-Za-z0-9]*' TopLevelPropertyNaming: active: true constantPattern: '[A-Z][_A-Z0-9]*' propertyPattern: '[a-z][A-Za-z\d]*' privatePropertyPattern: '(_)?[a-z][A-Za-z0-9]*' ``` -------------------------------- ### Replace build.maxIssues with failOnSeverity in Gradle Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Replaces the removed weight-based build.maxIssues mechanism. detekt now fails the build when it finds an issue at or above a configured severity, which defaults to Error. Use FailOnSeverity.Never for the old 'never fail' behaviour. ```diff detekt { - // build.maxIssues in detekt.yml + failOnSeverity.set(FailOnSeverity.Error) // Info | Warning | Error | Never } ``` -------------------------------- ### Update imports for detekt 2.x packages Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Updates imports for custom rule sets and extensions. All detekt packages moved under dev.detekt, and the shaded IntelliJ classes are replaced with com.intellij.*. ```diff -import io.gitlab.arturbosch.detekt.api.Rule -import io.gitlab.arturbosch.detekt.rules.isPartOf -import org.jetbrains.kotlin.com.intellij.psi.PsiElement +import dev.detekt.api.Rule +import dev.detekt.psi.isPartOf +import com.intellij.psi.PsiElement ``` -------------------------------- ### Update Gradle plugin ID to dev.detekt Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the change from the old plugin ID to the new one in the plugins block. ```diff plugins { - id("io.gitlab.arturbosch.detekt") version "1.23.8" + id("dev.detekt") version "2.0.0" } ``` -------------------------------- ### Update custom Config implementation for type-safe lookups Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the required changes for custom Config implementations: the abstract member now takes a type parameter, and the old valueOrNull/valueOrDefault methods are replaced by a single type-safe method. ```diff class MyConfig : Config { - override fun valueOrNull(key: String): Any? = ... - override fun valueOrDefault(key: String, default: Any): Any = ... + override fun valueOrNull(key: String, type: KClass): T? = ... } ``` -------------------------------- ### Baseline ID format change (diff) Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the change in baseline ID format: the file name and signature are now separated by ':' instead of '$'. The old format (with '$') will not match in detekt 2.x, so previously suppressed issues are reported again. ```diff -TooGenericExceptionCaught:Junk.kt$Junk$e: RuntimeException +TooGenericExceptionCaught:Junk.kt:Junk$e: RuntimeException ``` -------------------------------- ### YAML list change for `config.excludes` Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows that `config.excludes` is now a list instead of a comma-separated string. Comma-separated strings are no longer accepted where a list is expected. ```diff config: - excludes: 'my_rule_set,.*>.*>[my_property]' + excludes: ['my_rule_set', '.*>.*>[my_property]'] ``` -------------------------------- ### Add ktlint wrapper rule set to detekt 2.0.0-alpha.6 Source: https://github.com/detekt/detekt/blob/main/README.md Adds the ktlint wrapper rule set to detekt 2.0.0-alpha.6 via Gradle. Use this in the Gradle configuration to enable the ktlint integration as a detekt plugin. ```kotlin dependencies { detektPlugins("dev.detekt:detekt-rules-ktlint-wrapper:2.0.0-alpha.6") } ``` -------------------------------- ### Update Maven coordinates to dev.detekt group Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the change in Maven coordinates for the detekt-api artifact. ```diff -implementation("io.gitlab.arturbosch.detekt:detekt-api:1.23.8") +implementation("dev.detekt:detekt-api:2.0.0") ``` -------------------------------- ### Update Gradle report names to checkstyle and markdown Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Updates the Gradle report configuration for XML and Markdown reports. The 1.x report names 'xml' and 'md' are renamed to 'checkstyle' and 'markdown'. ```diff tasks.withType().configureEach { reports { - xml.required.set(true) + checkstyle.required.set(true) - md.required.set(true) + markdown.required.set(true) } } ``` -------------------------------- ### Move UnnecessaryLet rule to standard-library in detekt.yml Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the required change in detekt.yml to move the UnnecessaryLet rule from the style rule set to the new standard-library rule set in detekt 2.x. The diff format indicates lines to remove (prefixed with -) and lines to add (prefixed with +). ```diff -style: - UnnecessaryLet: - active: true +standard-library: + UnnecessaryLet: + active: true ``` -------------------------------- ### 1.x type-aware rule with @RequiresTypeResolution Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the 1.x style of a type-aware detekt rule using the @RequiresTypeResolution annotation and BindingContext. This pattern is removed in 2.x. ```kotlin @RequiresTypeResolution class MyRule(config: Config) : Rule(config) { override fun visitCallExpression(expression: KtCallExpression) { val descriptor = expression.getResolvedCall(bindingContext)?.resultingDescriptor ?: return // ... } } ``` -------------------------------- ### MagicNumber noncompliant: wildcard import Source: https://github.com/detekt/detekt/blob/main/detekt-generator/src/test/resources/RuleSet.md Noncompliant code for the MagicNumber rule: a wildcard import. ```kotlin import foo.* ``` -------------------------------- ### MagicNumber compliant: specific import Source: https://github.com/detekt/detekt/blob/main/detekt-generator/src/test/resources/RuleSet.md Compliant code for the MagicNumber rule: a specific import instead of a wildcard. ```kotlin import foo.bar ``` -------------------------------- ### Update CLI report IDs to checkstyle and markdown Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Updates the CLI report IDs for XML and Markdown reports. The 1.x IDs 'xml' and 'md' are renamed to 'checkstyle' and 'markdown' respectively. ```diff -detekt --report xml:report.xml --report md:report.md +detekt --report checkstyle:report.xml --report markdown:report.md ``` -------------------------------- ### YAML type change for `active` in `MagicNumber` Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Shows the required change for the `active` property in the `MagicNumber` rule: 1.x accepted a quoted string `"true"` and coerced it, but 2.x requires the boolean `true`. ```diff style: MagicNumber: - active: "true" + active: true ``` -------------------------------- ### Detektion API changes in 2.x Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Diff showing the changes to Detektion in 2.x: findings replaced by issues, add() replaced by the + operator, and addData/getData replaced by userData. Detektion is now an immutable class and no longer implements UserDataHolder. ```diff -detektion.findings // Map> -detektion.add(notification) // mutates in place -detektion.addData(key, value) / getData(key) +detektion.issues // List +detektion + notification // returns a new Detektion +detektion.userData // Map; use `detektion + (key to value)` ``` -------------------------------- ### Remove compiler plugin from Gradle build Source: https://github.com/detekt/detekt/blob/main/website/src/components/MigrationGuide.mdx Removal of the Kotlin compiler plugin in detekt 2.x. The Gradle plugin and the detekt-compiler-plugin artifact are gone with no replacement; use the Gradle plugin or CLI instead. ```diff plugins { - id("io.github.detekt.gradle.compiler-plugin") version "1.23.8" } detekt { - enableCompilerPlugin = true } ``` -------------------------------- ### NoUnitKeyword noncompliant: explicit Unit Source: https://github.com/detekt/detekt/blob/main/detekt-generator/src/test/resources/RuleSet.md Noncompliant code for the NoUnitKeyword rule: explicit :Unit return type. ```kotlin fun stuff(): Unit {} ```