appKODE / detekt-rules-compose

A collection of Detekt rules for Jetpack Compose
MIT License
136 stars 8 forks source link

[Question] No Compose in the report #18

Closed Drjacky closed 2 years ago

Drjacky commented 2 years ago

My detekt.gradle.kts in buildSrc:

import io.gitlab.arturbosch.detekt.Detekt
import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
import io.gitlab.arturbosch.detekt.extensions.DetektExtension

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

val analysisDir = file(projectDir)
val baselineFile = file("$rootDir/config/detekt/baseline.xml")
val configFile = file("$rootDir/config/detekt/detekt.yml")
//val statisticsConfigFile = file("$rootDir/config/detekt/statistics.yml")

val kotlinFiles = "**/*.kt"
val kotlinScriptFiles = "**/*.kts"
val resourceFiles = "**/resources/**"
val buildFiles = "**/build/**"

detekt {
    toolVersion = Versions.detektVersion
    buildUponDefaultConfig = true
    baseline = baselineFile
    config = files("config/detekt/detekt.yml")
    source = objects.fileCollection().from(
        DetektExtension.DEFAULT_SRC_DIR_JAVA,
        "src/test/java",
        DetektExtension.DEFAULT_SRC_DIR_KOTLIN,
        "src/test/kotlin"
    )
    reports {
        html.enabled = true
        html.destination = file("$projectDir/build/detekt/report.html")
        xml.enabled = true
        xml.destination = file("$projectDir/build/detekt/report.xml")
        txt.enabled = true
        txt.destination = file("$projectDir/build/detekt/report.txt")
    }
}

        const val detektVersion = "1.19.0"
        const val detektTwitterComposeRulesVersion = "0.0.4-SNAPSHOT"
        const val detektKodeComposeRulesVersions = "1.2.1"

dependencies {
    detektPlugins("io.gitlab.arturbosch.detekt:detekt-gradle-plugin:${Versions.detektVersion}")
//    detektPlugins("com.twitter.compose.rules:detekt:${Versions.detektTwitterComposeRulesVersion}")
    detektPlugins("ru.kode:detekt-rules-compose:${Versions.detektKodeComposeRulesVersions}")
}

val detektFormat by tasks.registering(Detekt::class) {
    description = "Formats whole project."
    parallel = true
    disableDefaultRuleSets = true
    buildUponDefaultConfig = true
    autoCorrect = true
    setSource(analysisDir)
//    config.setFrom(listOf(statisticsConfigFile, configFile))
    include(kotlinFiles)
    include(kotlinScriptFiles)
    exclude(resourceFiles)
    exclude(buildFiles)
    baseline.set(baselineFile)
    reports {
        xml.enabled = true
        html.enabled = true
        txt.enabled = true
    }
}

val detektAll by tasks.registering(Detekt::class) {
    description = "Runs the whole project at once."
    parallel = true
    buildUponDefaultConfig = true
    setSource(analysisDir)
//    config.setFrom(listOf(statisticsConfigFile, configFile))
    include(kotlinFiles)
    include(kotlinScriptFiles)
    exclude(resourceFiles)
    exclude(buildFiles)
    baseline.set(baselineFile)
    reports {
        xml.enabled = true
        html.enabled = true
        txt.enabled = true
    }
}

val detektProjectBaseline by tasks.registering(DetektCreateBaselineTask::class) {
    description = "Overrides current baseline."
    buildUponDefaultConfig.set(true)
    ignoreFailures.set(true)
    parallel.set(true)
    setSource(analysisDir)
//    config.setFrom(listOf(statisticsConfigFile, configFile))
    include(kotlinFiles)
    include(kotlinScriptFiles)
    exclude(resourceFiles)
    exclude(buildFiles)
    baseline.set(baselineFile)
}

and in the end of detekt.yml:

...
compose:
  ReusedModifierInstance: #finds usages of modifier parameter on non-top-level children of a composable function. This tends to happen during refactorings and often leads to incorrect rendering of a composable
    active: true
  UnnecessaryEventHandlerParameter: #suggests hoisting event argument passing to the upper level which often simplifies individual composable components
    active: true
  ComposableEventParameterNaming: #ensures that all event handler parameters of composable functions are named in the same Compose-like style, i.e. they have on prefix and do not use past tense
    active: true
  ComposableParametersOrdering: #suggests separating required an optional parameters of the composable function into groups
    active: true
  ModifierHeightWithText: #suggests using Modifier.heightIn() instead of Modifier.height() on a layouts which have Text children, so that if the text turns out to be long and would wrap, layout will not cut it off
    active: true
  ModifierParameterPosition: #ensures that modifier is declared as a first parameter
    active: true
  ModifierDefaultValue: #ensures that modifier parameter has a correct default value
    active: true
  MissingModifierDefaultValue: #checks if modifier default value is specified
    active: true
  PublicComposablePreview: #finds and reports composable previews which are not marked as private
    active: true
  TopLevelComposableFunctions: #ensures that all composable functions are top-level functions (disabled by default)
    active: true

And then this: gradle detektAll. The result doesn't have anything related to compose!

Drjacky commented 2 years ago

After update to 1.21.1 it worked.