Skip to content

Commit

Permalink
Add detekt (#2)
Browse files Browse the repository at this point in the history
Adding linting to a code project, with tools like Detekt for Kotlin, is
crucial for ensuring consistent coding styles, improving code quality,
and catching potential bugs early in the development process. Linting
promotes collaboration within development teams by enforcing uniform
coding conventions, enhancing code readability, and automating the
identification of common issues during code reviews. Detekt, being
Kotlin-specific, allows for customizable rules tailored to a project's
needs, ensuring adherence to best practices and Kotlin-specific coding
conventions. This leads to increased productivity, seamless integration
into CI/CD pipelines, and ultimately results in more maintainable and
reliable Kotlin projects.
  • Loading branch information
addyi authored Nov 11, 2023
1 parent 617b3af commit f8107d1
Show file tree
Hide file tree
Showing 7 changed files with 1,297 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
java-version: 17

- name: Clean build android app
run: ./gradlew clean androidApp:build
run: ./gradlew clean detekt androidApp:build
37 changes: 37 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,50 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask

plugins {
// this is necessary to avoid the plugins to be loaded multiple times in each subproject's classloader
alias(libs.plugins.android.application).apply(false)
alias(libs.plugins.android.library).apply(false)
alias(libs.plugins.jetbrains.compose).apply(false)
alias(libs.plugins.jetbrains.kotlin.multiplatform).apply(false)
alias(libs.plugins.jetbrains.kotlin.plugin.serialization).apply(false)
alias(libs.plugins.detekt)
id("dependency-version-management")
}

detekt {
// Documentation: https://detekt.dev/docs/gettingstarted/gradle/#kotlin-dsl-3

source.setFrom(".") // The directories where detekt looks for source files.

buildUponDefaultConfig = true // Applies the config files on top of detekt's default config file. `false` by default.
config.setFrom("${rootProject.rootDir}/detekt.yml")

parallel = true // Builds the AST in parallel.

baseline = file("${rootProject.rootDir}/detekt-baseline.xml") // TODO get rid of baseline as fast as possible

basePath = projectDir.absolutePath

allRules = true // Turns on all the rules. Default: false
}

tasks.withType<Detekt>().configureEach {
// include("**/special/package/**") // only analyze a sub package inside src/main/kotlin
exclude("**/build/**") // but exclude our legacy internal package
}

tasks.withType<DetektCreateBaselineTask>().configureEach {
// include("**/special/package/**") // only analyze a sub package inside src/main/kotlin
exclude("**/build/**") // but exclude our legacy internal package
}

dependencies {
detektPlugins(libs.detekt.rules.compose.kode)
detektPlugins(libs.detekt.rules.compose.nlopez)
detektPlugins(libs.detekt.rules.formatting.ktlint)
}

tasks.register("clean", Delete::class) {
delete(rootProject.buildDir)
delete(rootProject.projectDir.resolve("buildSrc/build"))
Expand Down
23 changes: 23 additions & 0 deletions detekt-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" ?>
<SmellBaseline>
<ManuallySuppressedIssues></ManuallySuppressedIssues>
<CurrentIssues>
<ID>ComposableFunctionName:main.android.kt$@Composable fun MainView()</ID>
<ID>Filename:main.android.kt$.main.android.kt</ID>
<ID>Filename:main.ios.kt$.main.ios.kt</ID>
<ID>FinalNewline:App.kt$.App.kt</ID>
<ID>FinalNewline:MainActivity.kt$com.myapplication.MainActivity.kt</ID>
<ID>FinalNewline:main.ios.kt$.main.ios.kt</ID>
<ID>FunctionNaming:main.ios.kt$fun MainViewController()</ID>
<ID>MissingPackageDeclaration:App.kt$.App.kt</ID>
<ID>MissingPackageDeclaration:main.android.kt$.main.android.kt</ID>
<ID>MissingPackageDeclaration:main.ios.kt$.main.ios.kt</ID>
<ID>ModifierMissing:App.kt$App</ID>
<ID>NewLineAtEndOfFile:App.kt$.App.kt</ID>
<ID>NewLineAtEndOfFile:MainActivity.kt$com.myapplication.MainActivity.kt</ID>
<ID>NewLineAtEndOfFile:main.ios.kt$.main.ios.kt</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val androidMain by getting { dependencies { api(libs.androidx.activity.compose) api(libs.androidx.appcompat) api(libs.androidx.core.ktx) api(libs.ktor.client.android) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val androidMain by getting { dependencies { implementation(project(":shared")) } }</ID>
<ID>UnusedPrivateProperty:build.gradle.kts$val iosMain by creating { dependsOn(commonMain) iosX64Main.dependsOn(this) iosArm64Main.dependsOn(this) iosSimulatorArm64Main.dependsOn(this) dependencies { implementation(libs.ktor.client.ios) } }</ID>
</CurrentIssues>
</SmellBaseline>
Loading

0 comments on commit f8107d1

Please sign in to comment.