Peter
11/14/2024, 12:25 PMPair
as return type 🤔Emil Kantis
11/20/2024, 12:06 PMJoão Silva
11/21/2024, 5:33 PMLongMethod
rule for @Composable
functions?
I've had the need to suppress it multiple times the more I write compose.
It can happen because of multiple lambdas, decision making, or any other reason.
Do you think it would be a good addition to change the current function to accept a new config like ignoredAnnotations
so that we can configure it? What are your toughts?
Thank you!Sebastian Schuberth
11/22/2024, 10:58 AMGMachine
11/24/2024, 1:42 PMAntonis Radz
11/26/2024, 4:42 PMtasks.withType<io.gitlab.arturbosch.detekt.Detekt> detekt@{
config.setFrom(files("$rootDir/detekt-config.yml"))
baseline.set(file("$rootDir/detekt-baseline.xml"))
setSource(files(rootDir))
include("**/*.kt")
exclude("**/*.kts")
exclude("**/resources/**")
exclude("**/build/**")
}
But this seems to be really slow, on CI it runs around 20mins, and project isn't big. Any ideas? Before CI was running around 5minsGMachine
11/27/2024, 2:55 PMproductArgs.favoriteLink!!.id
as UnnecessaryNotNullOperator
, even though productArgs.favoriteLink
is in another module and cannot be smart casted (Android Studio confirms this).
if (productArgs.favoriteLink != null) {
println(productArgs.favoriteLink!!.id) // Reported as UnnecessaryNotNullOperator
println(productArgs.favoriteLink.id) // Compiler error: smart cast not possible
}
Here’s how I resolve my classpath using a Gradle task:
tasks.register("resolveClasspath") {
def resolvedClasspath = providers.provider {
def classpathFiles = files()
// Iterate over application variants during the configuration phase
android.applicationVariants.all { variant ->
classpathFiles += variant.javaCompileProvider.get().classpath.filter { it.exists() }
}
// Convert classpath to a comma-separated string for later use
classpathFiles.files.collect { it.absolutePath }.join(",")
}
doLast {
println(resolvedClasspath.get())
}
}
Any ideas why Detekt might generate false positives in this setup? Am I missing something in my configuration? 🤔eygraber
11/27/2024, 8:21 PMarve
12/02/2024, 1:46 PMdetekt.yaml
?
(or even better, to the txt report)hfhbd
12/03/2024, 8:18 AMLouis
12/04/2024, 5:35 PMsubprojects {
apply {
plugin("io.gitlab.arturbosch.detekt")
}
detekt {
source.setFrom("src/main/kotlin", "src/main/java")
buildUponDefaultConfig = true
config.setFrom("$rootDir/detekt/config.yml")
baseline = file("$projectDir/detekt/baseline.xml")
autoCorrect = true
parallel = true
ignoreFailures = false
buildUponDefaultConfig = true
autoCorrect = true
ignoredBuildTypes = ["release", "benchmarkDebug", "benchmarkRelease"]
basePath = rootDir
}
dependencies {
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.7")
detektPlugins("io.nlopez.compose.rules:detekt:0.4.17")
}
}
Eric
01/21/2025, 3:25 PMfun foo() = "blah"
but I'd like to enforce that multi-line expression bodies have a line break after the =
or at least have it consistent within a single class/fileLouis
01/22/2025, 10:11 AMUnexpected error while running detekt analysis
io.gitlab.arturbosch.detekt.api.Config$InvalidConfigurationError: Provided configuration file is invalid: Structure must be from type Map<String,Any>!
while constructing a mapping
in reader, line 1, column 1:
build:
^
found duplicate key formatting
in reader, line 1056, column 1:
formatting:
^
Zsolt.bertalan
02/13/2025, 9:41 PMCzerwinskimarek88
02/14/2025, 8:56 AM<http://logger.info|logger.info> { "This is a very long logging message that exceeds the character limit, but I want Detekt to ignore it." }
I’ve tried various approaches, but I couldn’t find an in-built option to ignore specific function calls (like <http://logger.info|logger.info>
, logger.debug
, logger.warn
).
Is there a way to achieve this? Maybe there's a configuration option or a custom rule I could create?
Thanks in advance for your help! 🚀Brian Hartvigsen
02/21/2025, 6:53 PMMissingUseCall
rule detects the following as not using use
?
val code = """
fun <T> MyCloseable.useMe(block: (object) -> T) = use { block(this) }
fun MyCloseable.useMe() = use {}
fun test() {
MyCloseable(0).use {}
MyCloseable(1).useMe()
MyCloseable(2).useMe { it.doStuff() }
}
${myClosable(clazz)}
""".trimIndent()
These are obviously contrived, we have a pattern that would look more like:
MyCloseable(0).use { it.subPropertyClosable.use { sub -> sub.doStuff() } }
I was trying to shorthand that to something like the useMe
block except it's more like fun <T> MyCloseable.useMe(block: () -> T ) = use { subPropertyCloseable.use { block() } }
, but I get an error that MyCloseable
is doesn't call use
to access the Closeable
.Kim
02/24/2025, 3:48 AMrepo: local
as in the guides but would be nice to have some sensible default hooks support with .pre-commit-hooks.yaml
at the repo top level.eygraber
03/05/2025, 11:49 PMForbiddenMethodCall
value for tests instead of the whole rule?Max
03/21/2025, 3:44 PM@RequiresFullAnalysis
, but I don't see it in api. I use 1.23.8
version.
Has something changed? How can I use it?David Glasser
03/26/2025, 10:11 PMDoug McCluer
03/31/2025, 3:14 PMcontext(Activity)
fun finishWithContextReceiver(){
finish()
}
HÃ¥kon Pettersen
04/04/2025, 4:21 AM@Suppress("all")
like this:
ForbiddenSuppress:
active: true
rules: ["all", "CyclomaticComplexMethod"]
Currently, @Suppress("all")
isn't being caught, whereas "CyclomaticComplexMethod"
works as expected. Has anyone encountered this issue?
docs: https://detekt.dev/docs/rules/style/#forbiddensuppressmaarten ha
05/02/2025, 12:03 PMtasks {
withType<io.gitlab.arturbosch.detekt.Detekt> {
parallel = true
config.setFrom(files("/config/detekt/detekt.yml"))
buildUponDefaultConfig = true
jvmTarget = "$projectJvmTarget"
autoCorrect = true
setSource(files("src/main/kotlin", "src/test/kotlin"))
setOf(
"**/*.kt",
"**/*.kts",
".*/resources/.*",
".*/build/.*",
"/versions.gradle.kts",
).forEach {
include(it)
}
reports {
html.required.set(true)
html.outputLocation.set(file("reports/detekt/detekt.html"))
sarif.required.set(true)
sarif.outputLocation.set(file("reports/detekt/detekt.sarif"))
}
outputs.dir("reports/detekt/")
}
}
dependencies {
...
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.8")
}
For the detekt config I just ran the generate config task. Have not changed anything in ithfhbd
05/15/2025, 8:29 AMOleksandr Balan
06/11/2025, 10:08 AMErnestas
06/19/2025, 5:48 AMbuild.gradle
does not see the task - detektMain
, only - detekt
is available. I can still run the detektMain
task manually without problems though.Maxime Michel
07/09/2025, 11:46 AMmy-project:
-> android
|-> androidApp (Android application module)
|-> other android specific modules
-> build-logic
|-> convention
|-> Detekt.kt (Detekt specific configurations are contained here)
|-> MultiplatformLibraryConventionPlugin.kt
-> ios (iOS application)
-> kmp
|-> data
|-> domain
|-> presentation
-> testing
|-> detekt
|-> konsist
This is a somewhat generic KMP project structure I think (but this works without issues so I'm not planning on changing this structure).
The contents of the :testing:detekt
module is attached as an image.
I followed the documentation and updated my Detekt.kt
file to apply (or so I thought) the new rule I created:
internal fun Project.configureDetekt() {
configure<DetektExtension> {
source.from(files("$projectDir/src"))
config.from(files(
"$rootDir/config/quality/detekt/detekt-config.yml",
"$rootDir/testing/detekt/src/main/resources/config/config.yml",
))
baseline = file("$rootDir/config/quality/detekt/baseline.xml")
autoCorrect = true
}
tasks.withType<Detekt> {
exclude("**/test/")
exclude(".*/tmp/.*")
dependsOn(":testing:detekt:assemble")
}
dependencies {
CONFIGURATION_DETEKT_PLUGINS(libs.findLibrary("detekt.cli").get())
CONFIGURATION_DETEKT_PLUGINS(libs.findLibrary("detekt.formatting").get())
CONFIGURATION_DETEKT_PLUGINS(libs.findLibrary("detekt.libraries").get())
CONFIGURATION_DETEKT_PLUGINS(project(":testing:detekt"))
}
}
In my custom rule, I added an override for the visitKtFile
function that simply prints the file name but this does nothing and I see no logs when running the detekt task.Vanessa Johnson
07/14/2025, 1:19 PMEugen Martynov
07/14/2025, 2:02 PMAditya Bhaskar
07/14/2025, 5:17 PMUnusedPrivateMember
and NullableToStringCall
errors, and a few ISEs:
> A failure occurred while executing io.gitlab.arturbosch.detekt.invoke.DetektWorkAction
> java.lang.IllegalStateException: Analyzing something.kt led to an exception.
Location: java.base/java.util.concurrent.CompletableFuture.encodeThrowable(Unknown Source)
The original exception message was: java.lang.NullPointerException
Running detekt '1.23.8' on Java '21.0.6+-13391695-b895.109' on OS 'Mac OS X'
If the exception message does not help, please feel free to create an issue on our GitHub page.
Given this PR is still draft, is this to be expected?