Skip to content

Commit

Permalink
chore: move detekt to external project and migrate config to plugin (…
Browse files Browse the repository at this point in the history
…AR-2904) (#1294)

* chore: move config to external proj ref

* chore: remove internal module

* chore: remove internal module

* chore: comments

* chore: refactor config detekt as plugin

* chore: refactor config detekt as plugin

* chore: refactor config detekt as plugin, comments

* chore: pr comments
  • Loading branch information
yamilmedina committed Jan 4, 2023
1 parent 24e64e6 commit bec2e66
Show file tree
Hide file tree
Showing 12 changed files with 74 additions and 175 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ buildscript {
}

repositories {
mavenLocal()
wireDetektRulesRepo()
google()
mavenCentral()
}
Expand All @@ -31,6 +33,7 @@ plugins {
id("org.jetbrains.dokka")
id("org.jetbrains.kotlinx.kover") version "0.5.1" // TODO(upgrade): Breaking changes in 0.6.0
id("scripts.testing")
id("scripts.detekt")
}

dependencies {
Expand All @@ -45,9 +48,9 @@ tasks.withType<Test> {

allprojects {
repositories {
mavenLocal()
google()
mavenCentral()
mavenLocal()
maven {
url = uri("https://maven.pkg.github.com/wireapp/core-crypto")
credentials {
Expand Down Expand Up @@ -89,5 +92,3 @@ rootProject.plugins.withType<org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJ
}

tasks.dokkaHtmlMultiModule.configure {}

apply(from = "$rootDir/gradle/detekt.gradle")
1 change: 1 addition & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
implementation(libs.kotlin.plugin)
implementation("org.jetbrains.dokka:dokka-gradle-plugin:${libs.versions.dokka.get()}")
implementation("com.android.tools.build:gradle:${libs.versions.agp.get()}")
implementation("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${libs.versions.detekt.get()}")
}

gradlePlugin {
Expand Down
20 changes: 20 additions & 0 deletions buildSrc/src/main/kotlin/ProjectExtensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import org.codehaus.groovy.runtime.ProcessGroovyMethods
import org.gradle.api.Project
import org.gradle.api.artifacts.dsl.RepositoryHandler
import org.gradle.kotlin.dsl.ivy
import java.util.Properties
import java.util.concurrent.TimeUnit

Expand Down Expand Up @@ -41,3 +43,21 @@ fun String.execute(): Process = ProcessGroovyMethods.execute(this).also {
* Run command and return the output as text
*/
fun Process.text(): String = ProcessGroovyMethods.getText(this)

/**
* Configure the repository for wire's detekt custom rules
*/
fun RepositoryHandler.wireDetektRulesRepo() {
val repo = ivy("https://raw.githubusercontent.com/wireapp/wire-detekt-rules/main/dist") {
patternLayout {
artifact("/[module]-[revision].[ext]")
}
metadataSources.artifact()
}
exclusiveContent {
forRepositories(repo)
filter {
includeModule("com.wire", "detekt-rules")
}
}
}
48 changes: 48 additions & 0 deletions buildSrc/src/main/kotlin/scripts/detekt.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package scripts

import com.wire.kalium.plugins.libs
import getLocalProperty
import io.gitlab.arturbosch.detekt.Detekt

plugins {
id("io.gitlab.arturbosch.detekt")
}

dependencies {
val detektVersion = libs.findVersion("detekt").get()
detekt("io.gitlab.arturbosch.detekt:detekt-cli:$detektVersion")
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion")
detektPlugins("com.wire:detekt-rules:1.0.0-SNAPSHOT") {
isChanging = true
}
}

detekt {
buildUponDefaultConfig = true
// activate all available (even unstable) rules.
// allRules = false
config = files("$rootDir/detekt/detekt.yml")
source = files("$rootDir")
// a way of suppressing issues before introducing detekt
baseline = file("$rootDir/detekt/baseline.xml")

// dynamic prop to enable and disable autocorrect, enabled locally via local.properties file
val autoFixEnabled = getLocalProperty("detektAutofix", "false")
autoCorrect = autoFixEnabled.toBoolean()
println("> Detekt autoCorrect: $autoFixEnabled")
}

tasks.withType<Detekt> {
reports.html.required.set(true) // observe findings in your browser with structure and code snippets
reports.xml.required.set(true)
reports.txt.required.set(false)

// general detekt ignore patterns of files, instead of by rule
exclude(
"buildSrc/**",
"**/build/**",
"**/test/**",
"**/*Test/**",
"**/protobuf/**",
)
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/scripts/testing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import OnlyAffectedTestTask
OnlyAffectedTestTask.TestTaskConfiguration.values().forEach {
project.tasks.register(it.taskName, OnlyAffectedTestTask::class) {
targetTestTask = it.testTarget
ignoredModules = mutableListOf("android", "detekt-rules", "protobuf", "protobuf-codegen")
ignoredModules = mutableListOf("android", "protobuf", "protobuf-codegen")
}
}
8 changes: 0 additions & 8 deletions detekt-rules/build.gradle.kts

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions detekt-rules/src/main/java/com/wire/detekt/rules/RuleExtensions.kt

This file was deleted.

This file was deleted.

This file was deleted.

30 changes: 0 additions & 30 deletions gradle/detekt.gradle

This file was deleted.

0 comments on commit bec2e66

Please sign in to comment.