Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ jobs:

coverage:
uses: ./.github/workflows/coverage.yml

code-style:
uses: ./.github/workflows/code-style.yml
24 changes: 24 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
workflow_call:

jobs:
code-style:
name: 👔 Code style
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/setup-jdk-gradle

- name: 🕵🏻‍♂️ Detekt
run: |
./gradlew --no-daemon --parallel --console=plain \
detekt
echo "### Detekt Report" >> $GITHUB_STEP_SUMMARY
if [ -f build/reports/detekt/detekt.txt ]; then
echo '```' >> $GITHUB_STEP_SUMMARY
cat build/reports/detekt/detekt.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "No report found." >> $GITHUB_STEP_SUMMARY
fi
19 changes: 19 additions & 0 deletions .idea/detekt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion android-test-util/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.jetbrains.kotlin.android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ class KoinTestRule(
override fun finished(description: Description) {
unloadKoinModules(modules)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ inline fun <reified T : Any> NavHostController.assertRoute() {
assertThat(currentDestination?.hasRoute<T>())
.withFailMessage("Expected %s route but current route is %s", T::class.java.name, currentDestination?.route)
.isTrue()
}
}
29 changes: 29 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import io.gitlab.arturbosch.detekt.Detekt
import kotlinx.kover.gradle.plugin.dsl.CoverageUnit
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

Expand All @@ -34,6 +35,7 @@ plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.about.libraries) apply false
alias(libs.plugins.kover)
alias(libs.plugins.detekt)
}

val koverProjects = listOf(
Expand Down Expand Up @@ -100,6 +102,33 @@ kover {
}
}

allprojects {
project.afterEvaluate {
apply(plugin = libs.plugins.detekt.get().pluginId)
detekt {
config.setFrom("$rootDir/detekt.yml")
buildUponDefaultConfig = true
allRules = true
parallel = true
ignoreFailures = false
}

dependencies {
detektPlugins(projects.detektRules)
}
}

tasks.withType<Detekt> { dependsOn(":detekt-rules:assemble") }
tasks.withType<Detekt>().configureEach {
reports {
txt.required.set(true)
html.required.set(false)
xml.required.set(false)
sarif.required.set(false)
}
}
}

subprojects {
tasks {
findByName("test") ?: return@tasks
Expand Down
32 changes: 32 additions & 0 deletions detekt-rules/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2025 Olivier Patry
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

plugins {
kotlin("jvm")
}

dependencies {
compileOnly(libs.detekt.api)
testImplementation(libs.detekt.test)
testImplementation(libs.junit)
testImplementation(libs.assertj.core)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.opatry.detekt

import io.gitlab.arturbosch.detekt.api.CodeSmell
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.Debt
import io.gitlab.arturbosch.detekt.api.Entity
import io.gitlab.arturbosch.detekt.api.Issue
import io.gitlab.arturbosch.detekt.api.Rule
import io.gitlab.arturbosch.detekt.api.Severity
import org.jetbrains.kotlin.psi.KtImportDirective

class CleanArchitectureBoundaryRule(config: Config = Config.empty) : Rule(config) {
private companion object {
private val violations = mapOf(
".domain." to listOf(".presentation.", ".data.", ".ui."),
".presentation." to listOf(".data.", ".ui."),
".ui." to listOf(".domain.", ".data."),
".navigation." to listOf(".domain.", ".data."),
)
}

override val issue = Issue(
id = "CleanArchitectureBoundaryRule",
severity = Severity.CodeSmell,
description = "Clean Architecture boundary violation detected",
debt = Debt.TWENTY_MINS,
)

override fun visitImportDirective(importDirective: KtImportDirective) {
super.visitImportDirective(importDirective)

val importPath = importDirective.importPath?.pathStr ?: return
val currentFile = importDirective.containingKtFile
val currentPackage = currentFile.packageFqName.asString()

checkArchitectureBoundaries(currentPackage, importPath, importDirective)
}

private fun checkArchitectureBoundaries(
currentPackage: String,
importPath: String,
importDirective: KtImportDirective,
) {
violations
.filterKeys { "$currentPackage.".contains(it) }
.forEach { (fromLayer, toLayers) ->
toLayers
.filter { importPath.contains(it) }
.forEach { toLayer ->
val message = "Layer ${fromLayer.trim('.')} should not import from ${toLayer.trim('.')} layer"
report(
CodeSmell(
issue = issue,
entity = Entity.from(importDirective),
message = message,
)
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.opatry.detekt

import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.api.RuleSet
import io.gitlab.arturbosch.detekt.api.RuleSetProvider

class CustomRuleSetProvider : RuleSetProvider {
override val ruleSetId: String = "h2go-rules"

override fun instance(config: Config) = RuleSet(
ruleSetId,
listOf(
CleanArchitectureBoundaryRule(config)
)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
net.opatry.detekt.CustomRuleSetProvider
Loading