Anouar di Kali
01/02/2024, 7:26 PMbaseline.xml
using the detektBaseline
task. Do you have any idea about the source of this issue?
Execution failed for task ':detektBaseline'
> Cannot access input property 'source' of task ':detektBaseline'. Accessing unreadable inputs or outputs is not supported. Declare the task as untracked by u
sing Task.doNotTrackState(). For more information, please refer to <https://docs.gradle.org/8.5/userguide/incremental_build.html#disable-state-tracking> in the
Gradle documentation.
> Failed to create MD5 hash for file content.
detekt configuration :
detekt {
source.setFrom(file(projectDir))
parallel = true
autoCorrect = true
tasks.withType<Detekt> {
exclude("**/resources/**")
exclude("**/build/**")
include("**/*.kt")
include("**/*.kts")
}
baseline = file("${rootProject.projectDir}/config/baseline.xml")
}
Arthur Krukowski
01/03/2024, 10:33 AM--auto-correct
option. When i specify it, the baseline file is ignored. Any thoughts on why this might be occurring?
./gradlew detekt // respects baseline file
./gradlew detekt --auto-correct // ignores baseline file
neerav
01/03/2024, 11:03 AMbuild.gradle.kts
file
But apart from app’s I have 3 other modules/sub library. So how to configure detekt so that it can also smell code from those modules/libraries as well ?
Thanks simple smile
detekt {
// Version of Detekt that will be used. When unspecified the latest detekt
// version found will be used. Override to stay on the same version.
toolVersion = "1.21.0"
// The directories where detekt looks for source files.
// Defaults to `files("src/main/java", "src/test/java", "src/main/kotlin", "src/test/kotlin")`.
source = files("src/main/java", "src/main/kotlin", "src/test/java")
// Builds the AST in parallel. Rules are always executed in parallel.
// Can lead to speedups in larger projects. `false` by default.
parallel = false
// Define the detekt configuration(s) you want to use.
// Defaults to the default detekt configuration.
config = files("$rootDir/config/detekt/detekt.yml")
// Applies the config files on top of detekt's default config file. `false` by default.
buildUponDefaultConfig = true
// Turns on all the rules. `false` by default.
allRules = true
// Specifying a baseline file. All findings stored in this file in subsequent runs of detekt.
baseline = file("$rootDir/config/detekt/baseline.xml")
// Disables all default detekt rulesets and will only run detekt with custom rules
// defined in plugins passed in with `detektPlugins` configuration. `false` by default.
disableDefaultRuleSets = false
// Adds debug output during task execution. `false` by default.
debug = true
// If set to `true` the build does not fail when the
// maxIssues count was reached. Defaults to `false`.
ignoreFailures = false
basePath = projectDir.absolutePath
reports.html.required.set(true)
reports.xml.required.set(true)
}
stojan
01/06/2024, 12:12 PMcollectAsState()
that's useful on other platforms, but probably wrong most of the time on Android. On Android we should be using collectAsStateWithLifecycle()
. This is where a detekt rule might help.
The way I see it, it can be one rule that covers both. And it has a deny list of functions/imports that the user can configure to fail the build.
Are you aware if something like this exists? Would detekt be the right tool to implement this?
ThanksColton Idle
01/08/2024, 4:46 PMBrais Gabin
01/10/2024, 10:04 AM@Composable
) This change affects multiple areas of detekt. One of them is the configuration, how are we going to configure those multiple instances? If you are interested in the topic and want to give your 2 cents this is your issue: https://github.com/detekt/detekt/issues/6738Ward Bonnefond
01/22/2024, 9:00 PMParameter 'v' is never used, could be renamed to _
Rafs
02/04/2024, 9:53 AMBrais Gabin
02/04/2024, 2:07 PMEduard Boloș
02/05/2024, 12:37 PMbindingContext
is BindingContext.EMPTY
, which makes it impossible for me to check for the type of a KtNameReferenceExpression
using bindingContext.getType(receiverExpression)
.
The second problem is when running tests, where I am overcoming the empty BindingContext
issue by creating an environment using io.github.detekt.test.utils.createEnvironment
, when I am trying to replace some code, I am getting an error: Missing extension point: <http://org.jetbrains.kotlin.com|org.jetbrains.kotlin.com>.intellij.treeCopyHandler in container {}
(code snippet and full stack trace in thread)seb
02/06/2024, 7:45 PMeygraber
02/07/2024, 5:37 PMusers.map { it.name }.toTypedArray()
) fit in detekt's rule sets or is it something that should be kept 3rd party?Bernhard
02/08/2024, 1:34 PMconfig:
validation: true
complexity:
TooManyFunctions:
active: false
libraries:
LibraryEntitiesShouldNotBePublic:
active: true
which gives me a - Property 'libraries' is misspelled or does not exist.
using this script
detekt {
config.setFrom("$projectDir/../build-support/detekt-library.yml")
dependencies {
versionCatalogs.named("libs").findLibrary("gradle-detect-libraries").ifPresent {
detektPlugins(it)
}
}
}
Bernhard
02/08/2024, 1:38 PMkenkyee
02/15/2024, 5:23 PMJoel Pedraza
02/15/2024, 6:46 PMPeter
02/16/2024, 8:45 AMerror(exception)
Nick Kleban
02/16/2024, 2:57 PMtasks.withType<Detekt> { dependsOn(":my-rules:assemble") }
I’ve added similar configuration to all my modules, but when I change my custom rule and run detekt
old version of the rule instead of new one is launched.
Only project clean + detekt helps me.
Configuration and build cache are enabled.
How I can ensure that the newest version of rules is launched.Emanuel Moecklin
02/20/2024, 2:00 AMpaid
) I need to run two different Detekt tasks to get full coverage:
1. ./gradlew detektPaidDebug
only finds defects in the app module but not in library modules
2. ./gradlew detektDebug
only finds defects in library modules but not in the app module
When I run ./gradlew detekt
it finds defects in all modules. However we want to run with type resolution. Is this a known issue or am I doing something wrong?
As a reference, the configuration
subprojects {
apply plugin: "io.gitlab.arturbosch.detekt"
// includes the custom rules module
dependencies {
detektPlugins(project(":lib-code-quality"))
}
def baseDir = rootProject.projectDir
def baseLineFile = file("$baseDir/config/detekt/${project.name}/detekt-baseline.xml")
def reportPath = "$baseDir/build/reports/detekt/${project.name}"
detekt {
debug = false
parallel = true
config.setFrom(file("$baseDir/config/detekt/detekt-config.yml"))
baseline = baseLineFile
buildUponDefaultConfig = true
allRules = true
}
tasks.withType(Detekt).configureEach {
reports {
html.required.set(true)
html.outputLocation.set(file("$reportPath/detekt.html"))
txt.required.set(true)
txt.outputLocation.set(file("$reportPath/detekt.txt"))
xml.required.set(false)
md.required.set(false)
sarif.required.set(false)
}
}
tasks.withType(DetektCreateBaselineTask).configureEach {
baseline.set(baseLineFile)
}
}
Sebastian Schuberth
02/21/2024, 10:35 PMmergeDetektReports
task simply is not called via finalizedBy
. But more importantly, it's also not called when specified explicitly on the command line...Adam Ahmed
02/23/2024, 4:28 PM./gradlew fastDetekt
just doesn’t seem to do anything. What am I missing here?
abstract class GitChangedFilesValueSource : ValueSource<List<String>, ValueSourceParameters.None> {
@get:Inject
abstract val execOperations: ExecOperations
override fun obtain(): List<String> {
val output = ByteArrayOutputStream()
execOperations.exec {
commandLine("git", "diff", "--name-only", "--diff-filter=ACM")
standardOutput = output
}
val result = String(output.toByteArray(), Charset.defaultCharset()).trim().split("\n")
println("GitChangedFilesValueSource invoked, changed files: $result") // this prints when I invoke the task
return result
}
}
// This is called in my Application convention plugin
internal fun Project.registerFastDetekt() {
val changedFiles = providers.of(GitChangedFilesValueSource::class) {}
tasks.register<Detekt>("fastDetekt") {
include(changedFiles.get())
doLast {
println("Changed files: ${changedFiles.get()}") // This never prints anything when I invoke the task!
}
}
}
Javier
02/24/2024, 2:43 PMdetekt - ReturnCount: Function generateProperties has 3 return statements which exceeds the limit of 2.
?
I would like to avoid nesting and doing multiple returns is easy, readable and avoid nesting, for example:
override fun generateProperties(
callableId: CallableId,
context: MemberGenerationContext?
): List<FirPropertySymbol> {
if (callableId.callableName != atomicName) return emptyList()
val owner: FirClassSymbol<*> = context?.owner ?: return emptyList()
...
}
Xavier F. Gouchet
02/29/2024, 9:18 AM./gradlew :detektJvmMain
), my rule does have the type resolution and behaves as expected, but against the common source set (calling ./gradlew :detektMetadataMain
), the bindingContext
is always null. Is this expected, or is there a way to have a binding context against non jvm sources?Ward Bonnefond
02/29/2024, 3:45 PMPablichjenkov
02/29/2024, 9:38 PMXanderZhu
03/04/2024, 4:41 PMdependencies {
ktlintRuleset("com.github.username:rulseset:main-SNAPSHOT")
}
Is there a possibility to use these ktlint rules with detekt?eygraber
03/04/2024, 4:59 PMJavier
03/05/2024, 9:32 AMSebastian Schuberth
03/13/2024, 8:24 PMDetekt
tasks have their own jvmTarget
? Shouldn't it always match Kotlin's? And what does it default to if it's not specified?Stanislav Kral
03/17/2024, 11:23 AMdetekt
and detektMain
give me different violations in one source file for a multimodule project?
topnax@topnax-ryzen:<workdir>$ ./gradlew detekt
> Task :core-service:detekt FAILED
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:14:33: In most cases using a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty. [SpreadOperator]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core-service:detekt'.
> Analysis failed with 1 weighted issues.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
BUILD FAILED in 1s
1 actionable task: 1 executed
topnax@topnax-ryzen:<workdir>$ ./gradlew detektMain
> Task :core-service:detektMain FAILED
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:14:33: Used in this way a spread operator causes a full copy of the array to be created before calling a method. This may result in a performance penalty. [SpreadOperator]
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:11:5: Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided. [UnsafeCallOnNullableType]
<workdir>/core-service/src/main/kotlin/cz/ayeto/backend/CoreApplication.kt:18:13: Calling !! on a nullable type will throw a NullPointerException at runtime in case the value is null. It should be avoided. [UnsafeCallOnNullableType]
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':core-service:detektMain'.
> Analysis failed with 3 weighted issues.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at <https://help.gradle.org>.
BUILD FAILED in 1s
6 actionable tasks: 4 executed, 2 up-to-date
Root buildscript:
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import io.gitlab.arturbosch.detekt.Detekt
plugins {
val kotlinVersion = "1.9.22"
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
id("io.gitlab.arturbosch.detekt") version "1.23.5"
kotlin("jvm") version kotlinVersion apply true
}
allprojects {
apply(plugin = "io.gitlab.arturbosch.detekt")
detekt {
buildUponDefaultConfig = true
}
tasks.withType<Detekt>().configureEach {
buildUponDefaultConfig = true
reports {
html.required = true
// disabled until GitLab adds SARIF support
// sarif.required = true
}
}
repositories {
mavenLocal()
mavenCentral()
}
}
subprojects {
apply {
...
Any help would be appreciated.
Thanks