From 6dc8b752e027418f98d15eb2b7e2e309533e0caa Mon Sep 17 00:00:00 2001 From: Konstantin Pavlov <1517853+kpavlov@users.noreply.github.com> Date: Mon, 26 Jan 2026 19:02:22 +0200 Subject: [PATCH] ci: integrate Detekt static analysis tool (#493) - Add Detekt configuration (`detekt.yml`) with custom rules - Apply Detekt plugin to all subprojects - Configure Detekt tasks in Gradle workflow - Update Gradle dependency versions to include Detekt plugin ## Motivation and Context Enhance static code analysis for improved code quality. ## Breaking Changes No ## Types of changes - [x] CI update - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update ## Checklist - [x] I have read the [MCP Documentation](https://modelcontextprotocol.io) - [x] My code follows the repository's style guidelines - [x] New and existing tests pass locally - [ ] I have added appropriate error handling - [ ] I have added or updated documentation as needed --- .github/workflows/codeql.yml | 1 + .gitignore | 4 +++- .idea/detekt.xml | 14 ++++++++++++++ .idea/externalDependencies.xml | 7 +++++++ .idea/ktlint-plugin.xml | 7 +++++++ build.gradle.kts | 10 ++++++++++ .../src/main/kotlin/mcp.multiplatform.gradle.kts | 9 +++++++++ detekt.yml | 7 +++++++ gradle/libs.versions.toml | 14 ++++++++------ 9 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 .idea/detekt.xml create mode 100644 .idea/externalDependencies.xml create mode 100644 .idea/ktlint-plugin.xml create mode 100644 detekt.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index fba2019..4657da9 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -71,6 +71,7 @@ jobs: :kotlin-sdk:compileKotlinJvm \ :integration-test:compileKotlinJvm \ :conformance-test:testClasses \ + detekt \ -Pkotlin.incremental=false \ --no-daemon --stacktrace --rerun-tasks diff --git a/.gitignore b/.gitignore index a8c18dd..805579c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,13 +11,15 @@ build/ .idea/compiler.xml .idea/libraries/ .idea -!.idea/icon.png *.iws *.iml *.ipr out/ !**/src/main/**/out/ !**/src/test/**/out/ +!.idea/icon.png +!.idea/detekt.xml +!.idea/externalDependencies.xml ### Kotlin ### .kotlin diff --git a/.idea/detekt.xml b/.idea/detekt.xml new file mode 100644 index 0000000..a408ca9 --- /dev/null +++ b/.idea/detekt.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/.idea/externalDependencies.xml b/.idea/externalDependencies.xml new file mode 100644 index 0000000..0a081df --- /dev/null +++ b/.idea/externalDependencies.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/.idea/ktlint-plugin.xml b/.idea/ktlint-plugin.xml new file mode 100644 index 0000000..e8bd90c --- /dev/null +++ b/.idea/ktlint-plugin.xml @@ -0,0 +1,7 @@ + + + + DISTRACT_FREE + DEFAULT + + \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index bcdf96f..2161a96 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,8 @@ +import dev.detekt.gradle.extensions.FailOnSeverity + plugins { id("mcp.dokka") + alias(libs.plugins.detekt) alias(libs.plugins.ktlint) alias(libs.plugins.kover) } @@ -18,6 +21,13 @@ dependencies { subprojects { apply(plugin = "org.jlleitschuh.gradle.ktlint") apply(plugin = "org.jetbrains.kotlinx.kover") + apply(plugin = "dev.detekt") + + detekt { + config = files("$rootDir/detekt.yml") + buildUponDefaultConfig = true + failOnSeverity.set(FailOnSeverity.Never) + } } dokka { diff --git a/buildSrc/src/main/kotlin/mcp.multiplatform.gradle.kts b/buildSrc/src/main/kotlin/mcp.multiplatform.gradle.kts index a676db7..f3d4616 100644 --- a/buildSrc/src/main/kotlin/mcp.multiplatform.gradle.kts +++ b/buildSrc/src/main/kotlin/mcp.multiplatform.gradle.kts @@ -61,3 +61,12 @@ kotlin { explicitApi = ExplicitApiMode.Strict jvmToolchain(21) } + +tasks.named("detekt").configure { + dependsOn( + "detektMainJvm", + "detektCommonMainSourceSet", + "detektTestJvm", + "detektCommonTestSourceSet", + ) +} diff --git a/detekt.yml b/detekt.yml new file mode 100644 index 0000000..f9eba19 --- /dev/null +++ b/detekt.yml @@ -0,0 +1,7 @@ +config: + validation: true + warningsAsErrors: true + +complexity: + LongMethod: + excludes: ['**Test.kt'] diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fed638b..5b6b087 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,13 +1,14 @@ [versions] # plugins version -kotlin = "2.2.21" -dokka = "2.1.0" atomicfu = "0.29.0" -ktlint = "14.0.1" -kover = "0.9.4" -netty = "4.2.9.Final" -mavenPublish = "0.35.0" binaryCompatibilityValidatorPlugin = "0.18.1" +detekt = "2.0.0-alpha.1" +dokka = "2.1.0" +kotlin = "2.2.21" +kover = "0.9.4" +ktlint = "14.0.1" +mavenPublish = "0.35.0" +netty = "4.2.9.Final" openapi-generator = "7.18.0" # libraries version @@ -69,6 +70,7 @@ ktor-client-cio = { group = "io.ktor", name = "ktor-client-cio", version.ref = " ktor-server-cio = { group = "io.ktor", name = "ktor-server-cio", version.ref = "ktor" } [plugins] +detekt = { id = "dev.detekt", version.ref = "detekt" } kotlinx-binary-compatibility-validator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version.ref = "binaryCompatibilityValidatorPlugin" } kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" }