detekt / detekt

Static code analysis for Kotlin
https://detekt.dev
Apache License 2.0
6.09k stars 755 forks source link

Config baseline from build.gradle again dont works #4835

Closed pavlo-kravchenko closed 1 year ago

pavlo-kravchenko commented 2 years ago

I have investigated bug 3985 and it should be fixed. But I run into it again in version 1.20.0

I write

    detekt {
        config = files("config/detekt/detekt.yml")
        baseline = file("config/detekt/baseline.xml")

        basePath = projectDir
    }

In my allprojects { }

But baseline not used. Used only detekt-baseline.xml from app (if exist) or not used baseline.

cortinico commented 2 years ago

But baseline not used. Used only detekt-baseline.xml from app (if exist) or not used baseline.

Are you invoking detekt or detetkMain? Which project are you applying this to (Android/JVM/KMP)?

pavlo-kravchenko commented 2 years ago

But baseline not used. Used only detekt-baseline.xml from app (if exist) or not used baseline.

Are you invoking detekt or detetkMain? Which project are you applying this to (Android/JVM/KMP)?

detekt Android

BraisGabin commented 2 years ago

If you define the baseline like this: file("config/detekt/baseline.xml") I don't get how you get a baseline file called detekt-baseline.xml, it should be named baseline.xml. Could you provide a reproducer?

pavlo-kravchenko commented 2 years ago

If you define the baseline like this: file("config/detekt/baseline.xml") I don't get how you get a baseline file called detekt-baseline.xml, it should be named baseline.xml. Could you provide a reproducer?

I created detekt-baseline.xml with help command detektBaseline Renamed detekt-baseline.xml to baseline.xml Moved from app/ to config/detekt/ And run detekt Have error But If I run detektBaseline again and created detekt-baseline.xml in app/ and run detekt it works

From this I conclude What setting a custom path for baseline doesn't work

BraisGabin commented 2 years ago

Ok! So you are complaining about the path. Not the beaseline feature.

I tried to reproduce your issue and it works as expected on my end. a baseline is created in app/config/detekt/baseline.xml. For sure, if I move it anywhere else it stops working. baseline = file("config/detekt/baseline.xml") is a relative path (relative to the gradle project). It's not an absolute path.

The strange thing is that you say that detektBaseline generates the file named detekt-baseline.xml and then you need to rename it. detekt-baseline.xml is the default value, but it's strange that we are taking that default value. Could you provide a reproducer project? I can't reproduce your issue on my project.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 90 days with no activity. Please comment or this will be closed in 7 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 7 days with no activity.

MudraPatel commented 2 weeks ago

The issue arises when I move the detekt-baseline.xml file from its default path (project/app/detekt-baseline.xml) to a new location (project/config/detekt/detekt-baseline.xml). When I attempt to run gradle app:detekt, the Gradle tool in Android Studio fails to recognize the new path. But when i run it from command line(./gradlew detekt) it work properly.

detekt {
    buildUponDefaultConfig = false 
    allRules = false 
    config.setFrom("$projectDir/config/detekt/detekt.yml") 
    baseline = file("$projectDir/config/detekt/detekt-baseline.xml") 
    disableDefaultRuleSets = false
    debug = false
    enableCompilerPlugin = true
}