-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add detekt convention && ci checks (#14)
* add detekt convention && ci checks * add gradle dsl protection
- Loading branch information
1 parent
139ceda
commit 0b996e0
Showing
7 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
build-scripts/src/main/kotlin/ru/vladislavsumin/convention/analyze/detekt-all.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
build-scripts/src/main/kotlin/ru/vladislavsumin/convention/analyze/detekt.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
id("ru.vladislavsumin.convention.analyze.detekt-all") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters