Skip to content

Commit

Permalink
detekt 配置和部分修复
Browse files Browse the repository at this point in the history
  • Loading branch information
ForteScarlet committed Apr 10, 2024
1 parent 4d84b8f commit b6129e2
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 4
ij_continuation_indent_size = 8
ij_continuation_indent_size = 4
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = true
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/test-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'gradle/**'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: '${{ github.workflow }}-${{ github.ref }}'
cancel-in-progress: true

env:
Expand Down Expand Up @@ -59,10 +59,7 @@ jobs:

detekt-check:
name: Detekt check
strategy:
matrix:
os: [ macos-latest, windows-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
Expand All @@ -80,6 +77,15 @@ jobs:
uses: actions/upload-artifact@v4
if: ${{ always() }}
with:
name: test-reports-${{ runner.os }}
path: '**/build/detekt/report'
name: detekt-reports
path: 'build/reports/detekt'
retention-days: 7

# https://detekt.dev/docs/introduction/reporting/#integration-with-github-code-scanning
# Make sure we always run this upload task,
# because the previous step may fail if there are findings.
- name: Upload SARIF to GitHub using the upload-sarif action
uses: github/codeql-action/upload-sarif@v2
if: ${{ always() }}
with:
sarif_file: 'build/reports/detekt/detekt.sarif'
25 changes: 20 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,42 @@ dependencies {

detekt {
source.setFrom(
"simbot-component-telegram-api",
"simbot-component-telegram-core",
"simbot-component-telegram-stdlib",
"simbot-component-telegram-type",
subprojects
// internal 处理器不管
// .filter { "internal-processors" !in it.path }
.map { it.projectDir.absoluteFile }
)

config.setFrom(rootDir.resolve("config/detekt/detekt.yml"))
baseline = file("$projectDir/config/detekt/baseline.xml")
buildUponDefaultConfig = true
parallel = true
reportsDir = rootProject.layout.buildDirectory.dir("detekt/report").get().asFile
reportsDir = rootProject.layout.buildDirectory.dir("reports/detekt").get().asFile
if (!isCi) {
autoCorrect = true
}
basePath = projectDir.absolutePath
}

// https://detekt.dev/blog/2019/03/03/configure-detekt-on-root-project/
tasks.withType<Detekt>().configureEach {
include("**/src/*Main/kotlin/**/*.kt")
include("**/src/*Main/kotlin/**/*.java")
include("**/src/*Main/java/**/*.kt")
include("**/src/*Main/java/**/*.java")
include("**/src/main/kotlin/**/*.kt")
include("**/src/main/kotlin/**/*.java")
include("**/src/main/java/**/*.kt")
include("**/src/main/java/**/*.java")

// internal 处理器不管
exclude("**/internal-processors/")
exclude("**/src/*/resources/")
exclude("**/build/")
exclude("**/*Test/kotlin/")
exclude("**/*Test/java/")
exclude("**/test/kotlin/")
exclude("**/test/java/")
exclude("**.kts")
}

16 changes: 8 additions & 8 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
build:
maxIssues: 10000 # 先不限制最大问题
excludeCorrectable: false
weights:
formatting: 10000 # 代码格式的问题,一般都有 autoCorrect, 需要尽可能不出错
comments: 0
complexity: 0
LongParameterList: 0
style: 0
# weights:
# formatting: 0 # 代码格式的问题
# comments: 0
# complexity: 0
# LongParameterList: 0
# style: 0

config:
validation: true
Expand Down Expand Up @@ -44,12 +44,12 @@ console-reports:

output-reports:
active: true
exclude:
# exclude:
# - 'TxtOutputReport'
# - 'XmlOutputReport'
# - 'HtmlOutputReport'
# - 'MdOutputReport'
- 'SarifOutputReport'
# - 'SarifOutputReport'

comments:
active: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private class ComponentEventProcessor(private val environment: SymbolProcessorEn
****************************
此文件内容是 **自动生成** 的
****************************
""".trimIndent()
""".trimIndent()
)
indent(" ")
}.build()
Expand Down Expand Up @@ -124,7 +124,11 @@ private class ComponentEventProcessor(private val environment: SymbolProcessorEn
* ```
*/
private fun generateEvents(optionalPropertiesWithNames: List<Pair<KSPropertyDeclaration, String>>): List<TypeSpec> {
data class TypeBasedEventData(val property: KSPropertyDeclaration, val typeName: TypeName, val typeBuilder: TypeSpec.Builder)
data class TypeBasedEventData(
val property: KSPropertyDeclaration,
val typeName: TypeName,
val typeBuilder: TypeSpec.Builder
)
// val eventTypesWithTypeKey = mutableMapOf<>()
val typeBasedEventTypes = optionalPropertiesWithNames.asSequence()
.map { (property, _) ->
Expand All @@ -140,7 +144,8 @@ private class ComponentEventProcessor(private val environment: SymbolProcessorEn
PropertySpec.builder(
name = TELEGRAM_EVENT_PROPERTY_SOURCE_CONTENT_NAME,
type = typeName,
KModifier.OVERRIDE, KModifier.PUBLIC
KModifier.OVERRIDE,
KModifier.PUBLIC
)
.addKdoc(
"Source content with type [%T]\n\n",
Expand Down Expand Up @@ -180,7 +185,8 @@ private class ComponentEventProcessor(private val environment: SymbolProcessorEn
PropertySpec.builder(
name = TELEGRAM_EVENT_PROPERTY_SOURCE_CONTENT_NAME,
type = propertyTypeName,
KModifier.OVERRIDE, KModifier.PUBLIC
KModifier.OVERRIDE,
KModifier.PUBLIC
)
.addKdoc(
"Source content from [%M] with type [%T]\n\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private class IncludeMessageElementsProcessor(val environment: SymbolProcessorEn
****************************
此文件内容是 **自动生成** 的
****************************
""".trimIndent()
""".trimIndent()
)

addFunction(function)
Expand Down Expand Up @@ -130,7 +130,6 @@ private class IncludeMessageElementsProcessor(val environment: SymbolProcessorEn
*```
*/
private fun generateIncludeFunction(impls: List<KSClassDeclaration>): FunSpec {

// kotlinx.serialization.modules.subclass
val memberName = MemberName("kotlinx.serialization.modules", "subclass")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private class UpdateEventProcessor(private val environment: SymbolProcessorEnvir
****************************
此文件内容是 **自动生成** 的
****************************
""".trimIndent()
""".trimIndent()
)
}.build()

Expand Down Expand Up @@ -184,8 +184,11 @@ private class UpdateEventProcessor(private val environment: SymbolProcessorEnvir
// subscribe<Type>(NAME, sequence, processor)
.addStatement(
"%M<%T>(%M, %L, %L)",
BotSubscribeExtensionMember, eventType,
nameMember, SEQUENCE_PARAM_NAME, PROCESSOR_PARAM_NAME
BotSubscribeExtensionMember,
eventType,
nameMember,
SEQUENCE_PARAM_NAME,
PROCESSOR_PARAM_NAME
)
.build()
)
Expand All @@ -203,8 +206,10 @@ private class UpdateEventProcessor(private val environment: SymbolProcessorEnvir
@see %M
@see %M
""".trimIndent(),
eventType, nameMember, propertyName,
""".trimIndent(),
eventType,
nameMember,
propertyName,
BotSubscribeExtensionMember,
MemberName(UpdateClassName, propertyName)
)
Expand Down
Loading

0 comments on commit b6129e2

Please sign in to comment.