Skip to content

Commit

Permalink
Add detekt convention && ci checks (#14)
Browse files Browse the repository at this point in the history
* add detekt convention && ci checks

* add gradle dsl protection
  • Loading branch information
VladislavSumin authored Jan 2, 2025
1 parent 139ceda commit 0b996e0
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,27 @@ on:
workflow_dispatch:

jobs:
detekt:
name: Detekt
runs-on: ubuntu-24.04
timeout-minutes: 15
steps:
- name: Clone repository
uses: actions/checkout@v4

- name: Setup java
uses: ./.github/actions/setup_java

- name: Gradle cache
uses: ./.github/actions/gradle_cache
with:
key: "detekt"

- name: Run gradle
uses: ./.github/actions/run_gradle
with:
gradle_command: detekt

check:
name: Check
runs-on: ubuntu-24.04
Expand Down
1 change: 1 addition & 0 deletions build-scripts/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dependencies {

implementation(vsCoreLibs.gradlePlugins.kotlin.core)
implementation(vsCoreLibs.gradlePlugins.android)
implementation(vsCoreLibs.gradlePlugins.detekt)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ru.vladislavsumin.convention.analyze

/**
* Настройка detekt плагина по умолчанию для всех модулей.
*/

check(project === rootProject) { "This convention may be applied only to root project" }

allprojects {
apply {
plugin("ru.vladislavsumin.convention.analyze.detekt")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ru.vladislavsumin.convention.analyze

import io.gitlab.arturbosch.detekt.Detekt
import ru.vladislavsumin.utils.protectFromDslAccessors
import ru.vladislavsumin.utils.vsCoreLibs

/**
* Настройка detekt плагина по умолчанию. Должна подключаться ко всем модулям в которых нужен detekt.
*/

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

// Почему важно разделять таски созданные плагином и таски созданные вручную?
// По умолчанию мы хотим с помощью детекта анализировать только код внутри модуля, но иногда нам могут потребоваться
// дополнительные кастомные detekt таски, которые будут анализировать код по другим путям.

// Конфигурируем на уровне тасок, а не на уровне плагина, так как таски созданные в ручную не подтягивают дефолтные
// значения из конфигурации плагина, а мы хотим применить дефолтный конфиг ко всем таскам.
tasks.withType<Detekt>().configureEach {
autoCorrect = true
parallel = true
buildUponDefaultConfig = true
config.setFrom(rootProject.layout.projectDirectory.file("config/analyze/detekt.yml"))
}

// Дефолтные пути по которым detekt ищет файлы нас не устраивают, поэтому вручную проставляем пути для тасок с
// именем "detekt" - так мы отделяем таски созданные вручную от тех что плагин создает автоматически.
tasks.named<Detekt>("detekt").configure {
source = fileTree(project.projectDir) {
include("src/**/*")
include("build.gradle.kts")
include("settings.gradle.kts")
}
}

protectFromDslAccessors {
dependencies {
// Добавляет проверку форматирования кода.
detektPlugins(vsCoreLibs.detekt.formatting)
}
}
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
id("ru.vladislavsumin.convention.analyze.detekt-all")
}
25 changes: 25 additions & 0 deletions config/analyze/detekt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Default config location
# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml

naming:
FunctionNaming:
# Allow start function name from upper case to use in compose
functionPattern: '([A-z][a-zA-Z0-9]*)|(`.*`)'

formatting:
TrailingCommaOnCallSite:
active: true
useTrailingCommaOnCallSite: true
TrailingCommaOnDeclarationSite:
active: true
useTrailingCommaOnDeclarationSite: true

complexity:
LongParameterList:
active: false
TooManyFunctions:
active: false

style:
ReturnCount:
active: false
5 changes: 5 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ kotlin-coroutines = "1.9.0"
kotlin-serialization = "1.7.3"

gradlePlugins-android = "8.5.2"
gradlePlugins-detekt = "1.23.7"
decompose = "3.2.2"

[libraries]

# Gradle Plugins
gradlePlugins-kotlin-core = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin-core" }
gradlePlugins-android = { module = "com.android.tools.build:gradle", version.ref = "gradlePlugins-android" }
gradlePlugins-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "gradlePlugins-detekt" }

# Kotlin
kotlin-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutines" }
Expand All @@ -22,3 +24,6 @@ kotlin-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializat

# Decompose
decompose-core = { module = "com.arkivanov.decompose:decompose", version.ref = "decompose" }

# Other
detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "gradlePlugins-detekt" }

0 comments on commit 0b996e0

Please sign in to comment.