diff --git a/.github/workflows/pr_tests.yml b/.github/workflows/ci.yml similarity index 75% rename from .github/workflows/pr_tests.yml rename to .github/workflows/ci.yml index 5e7d0660..fbe76393 100644 --- a/.github/workflows/pr_tests.yml +++ b/.github/workflows/ci.yml @@ -2,7 +2,7 @@ name: PR Unit Tests on: pull_request: - types: [opened, reopened, synchronize] + types: [ opened, reopened, synchronize ] permissions: contents: read @@ -33,6 +33,19 @@ jobs: restore-keys: | gradle-${{ runner.os }}- + - name: Run Detekt + run: ./gradlew --no-daemon --console=plain :core:detekt + - name: Show Detekt summary + if: always() + run: | + SUMMARY_MD=core/build/reports/detekt/detekt.md + if [ -f "$SUMMARY_MD" ]; then + echo -e "## Detekt Report\n" >> "$GITHUB_STEP_SUMMARY" + cat "$SUMMARY_MD" >> "$GITHUB_STEP_SUMMARY" + else + echo "Detekt report not found." + fi + - name: Run unit tests run: ./gradlew --no-daemon jvmTest diff --git a/build.gradle.kts b/build.gradle.kts index e72c5f78..cee4737b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,7 @@ plugins { alias(libs.plugins.android.library).apply(false) alias(libs.plugins.compose.hotreload) apply false alias(libs.plugins.nexus.publish) + alias(libs.plugins.detekt).apply(false) } nexusPublishing { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 3b6a5143..b7b57014 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,6 +1,7 @@ @file:Suppress("UnstableApiUsage") @file:OptIn(ExperimentalKotlinGradlePluginApi::class) +import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.compose.internal.utils.getLocalProperty import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.dsl.JvmTarget @@ -12,6 +13,8 @@ plugins { alias(libs.plugins.compose.hotreload) alias(libs.plugins.kotlin.multiplatform) alias(libs.plugins.android.library) + alias(libs.plugins.detekt) + id("maven-publish") id("signing") } @@ -124,7 +127,33 @@ android { testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } } +val detektSourceDirs = listOf( + "src/commonMain/kotlin", + "src/cmpMain/kotlin", + "src/androidMain/kotlin", + "src/jvmMain/kotlin", + "src/iosMain/kotlin", + "src/webMain/kotlin" +).map(::file).filter(File::exists) + +detekt { + buildUponDefaultConfig = true + config.setFrom(files(rootProject.file("detekt.yml"))) + ignoreFailures = true + parallel = true + source.setFrom(detektSourceDirs) + baseline = file("$projectDir/detekt-baseline.xml") +} +tasks.withType().configureEach { + jvmTarget = JvmTarget.JVM_17.target + reports { + html.required.set(true) + xml.required.set(true) + txt.required.set(true) + sarif.required.set(false) + } +} val javadocJar = tasks.create("javadocJar") { archiveClassifier.set("javadoc") duplicatesStrategy = DuplicatesStrategy.EXCLUDE diff --git a/core/detekt-baseline.xml b/core/detekt-baseline.xml new file mode 100644 index 00000000..119a7fd5 --- /dev/null +++ b/core/detekt-baseline.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/detekt.yml b/detekt.yml new file mode 100644 index 00000000..33ff64f3 --- /dev/null +++ b/detekt.yml @@ -0,0 +1,35 @@ +build: + maxIssues: 500 # Change number of issues allowed as per need + +config: + validation: true + warningsAsErrors: false + checkExhaustiveness: false + # when writing own rules with new properties, exclude the property path e.g.: ['my_rule_set', '.*>.*>[my_property]'] + +processors: + active: true + exclude: + - 'DetektProgressListener' + # - 'KtFileCountProcessor' + # - 'PackageCountProcessor' + # - 'ClassCountProcessor' + # - 'FunctionCountProcessor' + # - 'PropertyCountProcessor' + # - 'ProjectComplexityProcessor' + # - 'ProjectCognitiveComplexityProcessor' + # - 'ProjectLLOCProcessor' + # - 'ProjectCLOCProcessor' + # - 'ProjectLOCProcessor' + # - 'ProjectSLOCProcessor' + # - 'LicenseHeaderLoaderExtension' + +console-reports: + active: true + # exclude: + # - 'ProjectStatisticsReport' + # - 'ComplexityReport' + # - 'NotificationReport' + # - 'IssuesReport' + # - 'FileBasedIssuesReport' + # - 'LiteIssuesReport' diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4b5be895..90b7a8ca 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -6,6 +6,7 @@ compose = "1.9.0" hot-reload = "1.0.0-rc01" nexusPublishPlugin = "2.0.0-rc-1" +detekt = "1.23.8" activity-core = "1.10.1" lucide = "1.0.0" window = "1.4.0" @@ -39,4 +40,5 @@ compose-hotreload = { id = "org.jetbrains.compose.hot-reload", version.ref = "ho kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } android-application = { id = "com.android.application", version.ref = "agp" } android-library = { id = "com.android.library", version.ref = "agp" } -nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublishPlugin" } \ No newline at end of file +nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexusPublishPlugin" } +detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } \ No newline at end of file