Skip to content

Commit

Permalink
Add Detekt and fix project errors (#108)
Browse files Browse the repository at this point in the history
  • Loading branch information
crocsandcoffee committed Dec 23, 2022
1 parent 395814b commit ead10bd
Show file tree
Hide file tree
Showing 174 changed files with 2,128 additions and 666 deletions.
25 changes: 25 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,28 @@ To build and run the android app (emulator or real android device is needed)
```shell
$ ./gradlew :app-android:installDebug
```

### 🔬 Verifications

To verify checks, run the following commands on your local machine

#### General Check

Run all configured checks for the project
```shell
$ ./gradlew check
```

#### Detekt

For code analysis and enforcing code guidelines

1. Run for whole project:
```shell
$ ./gradlew detekt
```

2. Run for specific module:
```shell
$ ./gradlew module:detekt
```
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with Dodo.
* If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.dodo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with Dodo.
* If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.dodo

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with Dodo.
* If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.dodo.di

Expand Down
10 changes: 6 additions & 4 deletions app-desktop/src/jvmMain/kotlin/social/androiddev/desktop/Main.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* This file is part of Dodo.
*
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* Dodo is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
*
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* Dodo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Dodo. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with Dodo.
* If not, see <https://www.gnu.org/licenses/>.
*/
package social.androiddev.desktop

Expand All @@ -27,7 +30,6 @@ import social.androiddev.root.navigation.DefaultRootComponent

@OptIn(ExperimentalDecomposeApi::class) // Using LifecycleController
fun main() {

startKoin {
modules(appModule())
}
Expand Down
120 changes: 120 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import io.gitlab.arturbosch.detekt.report.ReportMergeTask

plugins {
// Suppressed because of https://youtrack.jetbrains.com/issue/KTIJ-19369
@Suppress("DSL_SCOPE_VIOLATION")
alias(libs.plugins.io.gitlab.arturbosch.detekt.gradle)
}

buildscript {

repositories {
Expand All @@ -13,4 +23,114 @@ buildscript {
classpath(libs.com.squareup.sqldelight.gradle.plugin)
classpath(libs.org.jetbrains.kotlinx.atomicfu.plugin)
}
}

val sarifReportMerge by tasks.registering(ReportMergeTask::class) {
output.set(rootProject.buildDir.resolve("reports/detekt/merged_report.sarif"))
}

subprojects {

/**
* Start Configuring Detekt
*/
coreDetektSetup()

beforeEvaluate {
dependencies {
detektPlugins(libs.io.gitlab.arturbosch.detekt.formatting)
detektPlugins(libs.com.twitter.compose.rules.detekt)
}
}

/**
* Workaround for:
* The Kotlin source set androidAndroidTestRelease was configured but not added to any
* Kotlin compilation. You can add a source set to a target's compilation by connecting it
* with the compilation's default source set using 'dependsOn'.
* See https://kotlinlang.org/docs/reference/building-mpp-with-gradle.html#connecting-source-sets
*
* Remove log pollution until Android support in KMP improves.
*/
afterEvaluate {
project.extensions.findByType<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension>()?.let { ext ->
ext.sourceSets.removeAll { sourceSet ->
setOf(
"androidAndroidTestRelease",
"androidTestFixtures",
"androidTestFixturesDebug",
"androidTestFixturesRelease",
).contains(sourceSet.name)
}
}
}
}

/**
* To run detekt simply:
* 1. ./gradlew module:detekt for each module
* 2. ./gradlew detekt for whole project
*/
fun Project.coreDetektSetup() {

// Apply Plugin to sub-project
apply(plugin = "io.gitlab.arturbosch.detekt")

// Configure Detekt
detekt {
config = files("$rootDir/config/detekt/detekt.yml")
buildUponDefaultConfig = true
ignoredBuildTypes = listOf("release")
source = files(
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_JAVA,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_JAVA,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_SRC_DIR_KOTLIN,
io.gitlab.arturbosch.detekt.extensions.DetektExtension.DEFAULT_TEST_SRC_DIR_KOTLIN,
// Kotlin Multiplatform
"src/commonMain/kotlin",
"src/commonTest/kotlin",
"src/androidMain/kotlin",
"src/androidTest/kotlin",
"src/iosMain/kotlin",
"src/iosTest/kotlin",
"src/jvmMain/kotlin",
"src/jvmTest/kotlin",
"src/desktopMain/kotlin",
"src/desktopTest/kotlin",
"src/jsMain/kotlin",
"src/jsTest/kotlin",
)
}

tasks.withType<Detekt>().configureEach detekt@{
exclude("**/build/**", "**/generated/**", "**/resources/**")
basePath = rootProject.projectDir.absolutePath
autoCorrect = true // Auto corrects common formatting issues
// Configure reports here
reports {
xml.required.set(false)
txt.required.set(false)
md.required.set(false)

html {
required.set(true)
outputLocation.set(
layout.buildDirectory.file("reports/detekt.html")
)
}

sarif.required.set(true)
}

// Merged Report
finalizedBy(sarifReportMerge)
sarifReportMerge.configure {
input.from(this@detekt.sarifReportFile)
}
}

tasks.withType<DetektCreateBaselineTask>().configureEach detekt@{
exclude("**/build/**", "**/generated/**", "**/resources/**")
basePath = rootProject.projectDir.absolutePath
}
}
Loading

0 comments on commit ead10bd

Please sign in to comment.