Questions tagged [detekt]
detekt is a static code analysis tool for the Kotlin programming language. It operates on the abstract syntax tree provided by the Kotlin compiler.
63
questions
2
votes
1
answer
63
views
detekt.yml file is not able to identify my custom rules
I'm using detekt to add lint to my project for the first time, I followed the instructions from different articles online. But now the after finishing all the steps, when I add my custom rule to ...
1
vote
1
answer
70
views
detekt - How to change function naming rule?
I want to modify the rules of naming function because I am working on a project Android with Compose, and need a function starting with upper-case.
Current condition:
@Compossable
fun SomeScreen() {} /...
0
votes
0
answers
49
views
how to run detect with auto-corrector?
./gradlew detekt return very big list with Indentation, and ./gradlew detekt --auto-correct return error - Unknown command-line option --auto-correct.
detect.yml
formatting:
active: true
android: ...
0
votes
1
answer
65
views
Ban uses of error() method call with detekt
I wish to ban the uses of error() method.
My goal is to Ban the use of Generic exception. I can use rule TooGenericExceptionThrown if the code throws the error explicitly. However, when folks use ...
1
vote
0
answers
47
views
Detekt VarCouldBeVal rule doesn't seem to work
I've noticed that Detekt doesn't report issues with this code
fun main() {
var thisCouldBeVal = "this could be val"
println(thisCouldBeVal)
}
Isn't this a clear case where ...
1
vote
1
answer
161
views
Can't use apply<Plugin>() in root build.gradle.kts
I am using composite build to manage my plugins. In the same composite build, I have DetektConventionPlugin plugin shown below and I wish to apply it using this pattern: apply<...
0
votes
0
answers
88
views
Detekt. Disabled rules are still applying
In my detekt.yml file I'm setting some rules to false for example
LongMethod:
active: false
threshold: 60
but, when I run ./gradlew detekt, the same rule is still showing up as an error.
Do ...
0
votes
0
answers
120
views
How do I pass variable as argument to CLI parameter in YAML file?
I am trying to run detekt only on changed files in a pull request. The following doesn't work when I try to pass CHANGED_FILES as an argument to the input parameter for detekt.
# This workflow ...
0
votes
0
answers
165
views
Detekt - Suppress an issue for a generated file
On Android, when using Jetpack Navigation SafeArgs, some classes are generated by the lib and those classes cause some issues like "ThrowsCount", "UseRequire" and "...
0
votes
1
answer
143
views
How to count references to a variable or function in Kotlin?
The question is about static compile time analysis. Let's say there is a file-level const val:
const val SOME_CONST_VAL = "SOME_CONST_VAL"
How is it possible to get the number of usages for ...
1
vote
1
answer
768
views
Detekt setting for exclude is ignored
How can I exclude the sample folder from the following rules? with this configuration it is not working and detekt keeps parsing the sample folder
UndocumentedPublicClass:
active: true
excludes: &...
1
vote
0
answers
130
views
How can I set up reviewdog for android and jetpack compose?
name: reviewdog
on: [ pull_request ]
jobs:
ktlint:
name: Ktlint Check Code Quality
runs-on: ubuntu-latest
steps:
- name: Clone repo
uses: ...
1
vote
1
answer
139
views
What is the use of LibraryEntitiesShouldNotBePublic Detekt Rule in Kotlin
I have a Kotlin Library into which I integrated the usage of Detekt static code linting. Most of the rules are clear to me and I fixed all the issues with my code except for one:
There is a rule ...
0
votes
0
answers
54
views
DeteKt: сheck for the use of the fragment constructor in Android
Is it possible to create DeteKt rule for checking is the Android fragment constructor used directly in the code instead newInstance?
I would like to create checks that prohibit the creation of a ...
0
votes
1
answer
222
views
Getting Schema validation: Incompatible types in detekt.yml in Android Studio
Any way I can fix the schema warning in detekt.yml I am attaching the screenshot and open to add more details
Minimum reproducible detekt.yml below
build:
maxIssues: 0
excludeCorrectable: false
...
1
vote
1
answer
226
views
Does not show output for all mutliple modules in an android project running the ./gradlew detekt
I am using detekt and have a android project that contains presentation, domain, and data modules.
When running ./gradlew detekt
It only show the output for the data module.
However, when I run the ...
1
vote
0
answers
123
views
Pass gradle step when detekt sucessfully autocorrects
I run detekt with gradle with autocorrect enabled. I fail the build on detekt errors. This results in me running detekt twice for autocorrectable problems:
The build fails and is autocorrected.
The ...
2
votes
0
answers
596
views
How can I access local.properties in Github Action yml file for ci?
I get data from local.properties in build.gradle like this.
android {
signingConfigs {
debug {
Properties properties = new Properties()
properties.load(project....
2
votes
1
answer
1k
views
JetPack Compose - Best practices for method length [closed]
I am trying to integrate detekt with JetPack Compose project and as a rule
LongMethod:
active: true
threshold: 60
and as compose recommend passing each parameter in separate line the method ...
4
votes
1
answer
1k
views
Android and Detekt: Aligning .idea CodeStyle with detekt
I have an Android project that i've set up with Detekt.
I'm currently using:
io.gitlab.arturbosch.detekt:detekt-gradle-plugin:1.19.0 (Root build.gradle)
io.gitlab.arturbosch.detekt:detekt-formatting:...
2
votes
0
answers
103
views
My CI build fails because of detect property
I just recently updated my arturbosch detekt library in my android app to 1.20.0-RC1 but when I run my build using bitrise CI tool, I get this error message:
I have checked my detekt config file and &...
0
votes
1
answer
284
views
How to check usage of 'it' parameter in lambda with Detekt custom rule?
I want to write a Detekt rule which disallows usage of implicit "it" variable in a multi-line lambda. I've written method override fun visitLambdaExpression(lambdaExpression: ...
0
votes
1
answer
2k
views
Configure rules in Detekt
I am adding Detekt to a new project.
But, I find that some rules are too strict.
How can I implement my own thresholds for a few rules?
I don't want to use Baseline files, because this is new code and ...
0
votes
1
answer
5k
views
Running detekt from the command line locally doeesn't produce problems
Android
detekt 1.19.0
When running this commmand I get the following output but not classes that have failed for the rules.
./gradlew detekt
37 kotlin files were analyzed.
Complexity Report:
...
1
vote
0
answers
1k
views
How do I create a detekt rule to stop certain class from being explicitly referenced as a property?
In our previous project, we have a class called AbstractActor to be inherited to do specific stuff, and some of our devs might hold its reference as a constructed valOrVar parameter or KTProperty, ...
1
vote
1
answer
1k
views
compilation error of jdk nashron when updated from jdk1.8 to jdk 11
Updated with more details :
My objective is to set source of below code .
source(sourceSets.map { it.javaDirectories }.flatten())
above code working fine with jdk 1.8 but when I changed to jdk ...
2
votes
1
answer
308
views
Detekt. Different thresholds for same rule
I'm using Detekt and I need to configure LargeClass rule. I want to set different thresholds for production and test classes. Is it possible to configure it such way?
1
vote
0
answers
172
views
IntelliJ Reformat Code Does Not Correct All Line Lengths
I have my IntelliJ editor configured to reformat lines that are longer than 120. It does some lines no problem. For example
val myVar = function(param1, param2, ......... paramN)
transitions to the ...
2
votes
0
answers
456
views
Error while setting up Detekt custom rules
I have setup Detekt in a multi module project. Below is my root level build.gradle
tasks.register("detektAll", Detekt) {
description = "Custom Detekt build for all modules"
...
2
votes
1
answer
948
views
Android and Kotlin DeteKt: Custom rules not running
Trying to create some playground over Detekt custom rules and it just doesn't work. Doesn't even try to find the rule-set file.
The gradle goes
plugins {
id 'com.android.application'
id '...
-1
votes
1
answer
390
views
.git/hooks/pre-commit: line 33: detekt: command not found
I am trying to use detekt on my android project but when i try to commit using sourcetree i get this error.
Checking prerequisites
Collecting modified files
Running detekt
.git/hooks/pre-commit: line ...
2
votes
1
answer
504
views
Detekt return type annotations always empty
I am trying to write a check to prevent returning a Type with a certain annotation.
Such as,
const val TEST_CONTENT =
"""
| package sample.test
|
| @...
2
votes
1
answer
816
views
How to enable type resolution for custom detekt gradle task?
I have a custom gradle task to run detekt only on files passed as argument.
tasks.register("detektCustom", io.gitlab.arturbosch.detekt.Detekt.class) { detektTask ->
detektTask.config....
1
vote
1
answer
390
views
Stylish safe way to check for nullability of multiple values with Detekt
I'm using Danger Detekt (static code quality measurement system based on ktlint). I've got a function that fetches data from 8 different endpoints. Then I need to check if these values are not null ...
3
votes
1
answer
4k
views
Android Detekt Build failed
I tried to generate code report using detekt and when execute the below command in terminal
gradle detekt
it showing build failed with below message.
* What went wrong:
Execution failed for task ':app:...
0
votes
1
answer
192
views
Need to block Android run on failed gradle task
I have an android project in Android studio that I would like to use detekt as a static code analyzer. I can run detekt through a gradle task and I am able to queue it up before the run of the app by ...
0
votes
0
answers
399
views
how to attach a task to run after the tasks from a plugin in gradle
I have installed the detekt plugin in gradle-kotlin with
plugins {
id("io.gitlab.arturbosch.detekt").version("1.10.0")
}
This yields tasks for me when I run tasks:
Verification ...
3
votes
1
answer
917
views
Retrieve Kotlin Property type from Kotlin psi API
I'm trying to create new rule for detekt project. To do this I have to know exact type of Kotlin property. For example, val x: Int has type Int.
Unfortunately, for property of type private val a = 3 ...
2
votes
1
answer
4k
views
How to suppress WildcardImport and MatchingDeclarationName for Detekt?
I need to suppress two errors: WildcardImport and MatchingDeclarationName. Probleme is that it is need to be applied to the whole file, is there any way to do this?
0
votes
1
answer
690
views
SonarQube Is there a gradle setting in detekt gradle plugin to generate report on remote host instead of in a file
When I use sonarqube plugin I'm not able to generate report on remote host on using my specific branch as lateast version is not supporting it and branch.name is deprecated
So When I use detekt ...
1
vote
1
answer
3k
views
How to generate and use a detekt baseline using the maven plugin?
I'm trying to use detekt in a multi-module Maven project using Kotlin with the detekt-maven-plugin.
Following the instructions found here to generate a baseline with the existing issues, I tried ...
5
votes
1
answer
3k
views
Disable automatic Detekt run in Gradle
I have added Detekt to my Gradle project. My intention was to invoke detekt on demand only, since it creates a lot of false positives. However, the detekt task is active by default (and breaks the ...
14
votes
5
answers
7k
views
How to get rid of from SpreadOperator performance warning that was given by Detekt while using Spring Boot?
Recently, I added Detekt analyzer to my application.
After I runned detekt (./gradlew detekt), I got SpreadOperator warning in my main class of application.
Warning on code: runApplication<...
3
votes
1
answer
922
views
How do a get a fully qualified domain name of class in Kotlin PSI?
I have a Kotlin data class:
package a.b.c
data class Example(
…
)
I am analyzing it with detekt which provides access to the Kotlin PSI.
I'm trying to get the FQDN of my class:
println(klass....
3
votes
1
answer
366
views
annotations vs annotationEntries in IntelliJ / Kotlin PSI
I have a Kotlin annotation:
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Type(
val type: String
)
It can be used on the Kotlin classes:
@Type(type = "...
4
votes
0
answers
253
views
Acquire annotation parameters (or annotation instance) from Kotlin PSI
I have a Kotlin annotation:
@Retention(AnnotationRetention.SOURCE)
@Target(AnnotationTarget.CLASS)
annotation class Type(
val type: String
)
It can be used on the Kotlin classes in two ways: ...
3
votes
2
answers
8k
views
Detekt task fails only if ran without check task
I'm migrating detekt from 1.0.0.RC7-2 to the 1.0.1 and changing to use the new plugin syntax. I managed to make it work, but only when the full check task is executed.
If only the detekt task is ...
3
votes
1
answer
705
views
How do I enable type resolution in detekt?
detekt is alerting me about the SpreadOperator rule. According to this issue, the rule can be suppressed in certain circumstances when type resolution is enabled. I can't find any documentation or ...
7
votes
1
answer
14k
views
Detekt: Autocorrect feature is not working
I have included detekt (https://github.com/arturbosch/detekt/) in my project:
root build.gradle
buildscript {
ext.kotlin_version = '1.3.50'
ext.detekt_version = "1.0.1"
repositories {
...
0
votes
0
answers
531
views
Detekt plugin not able to download from Maven central
I am working with Kotlin and want to do static analysis using Detekt plugin. My problem is, when I want to download it from Maven central repository, it is giving me below error. But when I use ...