https://kotlinlang.org logo
Docs
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
detekt
  • v

    Venkat , Bangalore , India

    05/27/2020, 8:52 PM
    Hi All, I could see a difference between gradle-detekt-plugin (1.9.1) and detekt-sonar-plugin(2.0.0) reported issues... with same config yml file.. also anyone please tell me when can we expect detekt-sonar plugin will be updated based on 1.9.1?
    s
    a
    • 3
    • 20
  • v

    Venkat , Bangalore , India

    05/27/2020, 8:53 PM
    is it a good practice to use both?
    a
    • 2
    • 2
  • v

    voben

    05/29/2020, 4:49 PM
    I can’t seem to get autocorrect to work. This is what my detekt.gradle file looks like. Any ideas?
    apply plugin: 'io.gitlab.arturbosch.detekt'
    
    detekt {
        parallel = true
        config = files("$rootDir/codeQuality/detekt.yml")
        autoCorrect = true
        reports {
            xml {
                enabled = false
            }
            txt {
                enabled = false
            }
        }
    }
    c
    • 2
    • 14
  • p

    Pamm Sar

    06/01/2020, 8:21 AM
    Hi all - I can’t get the detekt to run as a task for specific module. I followed these steps for the app & submodules I want to apply it on: https://arturbosch.github.io/detekt/gradletask.html when I run
    ./gradlew :app:detekt
    (or
    ./gradlew :submodule-name:detekt
    ) I get the following output:
    Task 'detekt' not found in project ':app'. Some candidates are: 'test'.
    however if I run just
    ./gradlew detekt
    it runs the task.
    v
    a
    • 3
    • 23
  • j

    Javier

    06/01/2020, 4:35 PM
    Is it possible to run detekt only on the files that changed from last commit?
    g
    s
    • 3
    • 2
  • r

    Rodrigo Silva

    06/01/2020, 8:16 PM
    Hi guys. I'm using sonarqube with detekt, but coverage is always 0%. My configuration looks like this:
    a
    • 2
    • 5
  • t

    thuytrinh

    06/02/2020, 2:34 PM
    Hi everyone, I’m sorry if this has been discussed already somewhere. I’m trying to get the benefit of the
    ThrowsCount
    rule. I have a violated code here:
    private fun ensureScanningIsPossible() {
        if (!isDiscoveryPermissionGranted) {
            throw DiscoveryErrors.DiscoveryPermissionsMissingError(neededDiscoveryPermissions)
        } else if (isDiscoveryOngoing) {
            throw DiscoveryErrors.DiscoveryAlreadyStarted
        } else if (!isBluetoothAvailable()) {
            throw DiscoveryErrors.BluetoothDisabledError
        } // More to come later...
    }
    Why is this discouraged? The doc said: “Functions should have clear 
    throw
     statements”. How can we achieve a “clear” version? I tried to refactor by using nullable type but I feel a bit skeptical about the new code:
    private fun ensureScanningIsPossible() {
        val error: DiscoveryErrors? = when {
            !isDiscoveryPermissionGranted -> DiscoveryErrors.DiscoveryPermissionsMissingError(neededDiscoveryPermissions)
            isDiscoveryOngoing -> DiscoveryErrors.DiscoveryAlreadyStarted
            !isBluetoothAvailable() -> DiscoveryErrors.BluetoothDisabledError
            else -> null
        }
        error?.let { throw it }
    }
    g
    v
    • 3
    • 13
  • r

    Rodrigo Silva

    06/03/2020, 6:41 PM
    How do I configure to disable the ImportWildCard in the gradle?I am running datekBaseline and manually adding it to the blacklist.
    l
    s
    • 3
    • 3
  • d

    dead.fish

    06/12/2020, 8:44 AM
    Could any of the regular devs have a look at https://github.com/detekt/detekt/pull/2787 and tell me if I’m on the right track or if I am horribly wrong off road? Thanks 😄
    g
    s
    • 3
    • 4
  • v

    Venkat , Bangalore , India

    06/15/2020, 12:43 PM
    Hi All, I am facing strange issue with SpreadOperator as Sonar blocked it https://arturbosch.github.io/detekt/performance.html#spreadoperator . We have gone through this link but we could not understand how to fix this issue if the array is dynamic ( coming from an external library).. Can any one please help me on how to fix this issue.?
    c
    b
    • 3
    • 4
  • s

    sanogueralorenzo

    07/02/2020, 4:34 PM
    Hello everyone, does anyone have the detektAll tasks but in groovy? 😄 https://github.com/sanogueralorenzo/Android-Kotlin-Clean-Architecture/blob/master/build.gradle.kts#L35 I see myself converting to kts everytime just to add the task 😄
    g
    • 2
    • 2
  • p

    pedro

    07/04/2020, 3:19 PM
    I’m having problems using detekt in my project… (kotlin jvm project) I have different problems if I use 1.9.1 or 1.10.0 1.10.0
    Execution failed for task ':foo:detekt'.
    > Could not resolve all files for configuration ':foo:detekt'.
       > Could not find io.gitlab.arturbosch.detekt:detekt-cli:1.10.0.
         Searched in the following locations:
           - <https://repo.maven.apache.org/maven2/io/gitlab/arturbosch/detekt/detekt-cli/1.10.0/detekt-cli-1.10.0.pom>
         If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
    I have seen someone mentioning in github issues that it seems that some artifacts weren’t published in all repositories If I try to use 1.9.1:
    > Could not find org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.1.
         Searched in the following locations:
           - <https://repo.maven.apache.org/maven2/org/jetbrains/kotlinx/kotlinx-html-jvm/0.7.1/kotlinx-html-jvm-0.7.1.pom>
         If the artifact you are trying to retrieve can be found in the repository but without metadata in 'Maven POM' format, you need to adjust the 'metadataSources { ... }' of the repository declaration.
         Required by:
             project :foo > io.gitlab.arturbosch.detekt:detekt-cli:1.9.1
    I’ve tried all possible combinations of the instructions in the website and still haven’t got it to work. Can someone help?
    g
    b
    • 3
    • 19
  • b

    bbaldino

    07/08/2020, 5:23 PM
    I can't seem to get the
    ForbiddenMethodCall
    to work, I've got it configured like so:
    style:
      active: true
      ForbiddenMethodCall:
        active: true
        methods: ['java.util.concurrent.ExecutorService.submit', 'kotlin.io.println']
    in a custom
    detekt.yml
    (which doesn't contain much else). I'm using the maven plugin and have it pointing to that config file. (I added
    println
    in there to try and test after the first one wasn't working.) It's not triggering for
    println
    calls or
    ExecutorService.submit
    calls. I tried adding another rule and that did work...so maybe I've just got something misconfigured for
    ForbiddenMethodCall
    ?
    g
    • 2
    • 25
  • n

    nkiesel

    07/09/2020, 12:59 AM
    How can I override settings from a global detekt settings in a module for a multi-module gradle build? Right now I have a
    detekt-config.yml
    in my root directory, and another `detekt-config.yml`in my module directory. To use both, I use
    detekt { config = files("${project.rootDir}/detekt-config.yml", "detekt-config.yml") }
    . Is there a better way which e.g. does not require to repeat the base config file name or perhaps even a
    mergeConfigs: true
    which will automatically merge these? I tried
    detekt { config += files("detekt-config.yml") }
    but that did not work.
    g
    • 2
    • 2
  • b

    bbaldino

    07/14/2020, 5:01 PM
    Does detekt have any built-in rules related to inconsistent synchronization? I'm trying to make a case for detekt over spotbugs, but this is a feature we've gotten from spotbugs and haven't found something similar in the detekt docs.
    g
    b
    • 3
    • 8
  • m

    Marco Righini

    07/17/2020, 10:53 AM
    Hi everybody! What’s the way to overwrite the detekt autocorrect flag (defined in
    detekt
    block in the gradle file) with a command line gradle task parameter? I checked the docs but I didn’t find how. I’ve also tried
    ./gradlew detekt -Pauto-correct=true
    and
    ./gradlew detekt -PautoCorrect=true
    along with some other similar commands but none of them worked.
    b
    g
    • 3
    • 3
  • r

    Rodrigo Silva

    07/19/2020, 4:13 PM
    Hi all. I'm getting this warning:
    detekt(DetektExtension.() -> Unit): Unit' is deprecated. Either apply detekt plugin to root project
    why? gradle version: 6.5 detekt version: 1.10.
    g
    d
    • 3
    • 4
  • d

    dead.fish

    07/20/2020, 1:39 PM
    Hi all! Are there any more sophisticated complexity checks that somebody wrote based on Detekt?
    ComplexMethod
    only works on single methods, but I’m looking for class and inter-class complexity calculation. Is this even possible with Detekt?
    g
    s
    • 3
    • 2
  • c

    Charles

    07/29/2020, 2:28 PM
    Using
    detekt
    +
    ktlint
    I'm used to using the Android Studio shortcuts to format a file to fix basic issues. After attempting to upgrade to
    1.10.0
    this no longer seems to fix the new
    Indentation
    issue being reported. If a file format command doesn't fix that we can't reasonably upgrade our projects. Any ideas?
    p
    b
    • 3
    • 15
  • z

    zmunm

    08/05/2020, 3:56 AM
    Hi. I need help.. There are some code like this
    Observable.something()
        .map {
            mutableList.apply {
                addAll(list)
            }
        }
    Console says
    UnnecessaryApply
    .. But I need
    return MutableList
    I don't know if this is really wrong. How can I fix it? Thank you for reading..
    n
    g
    b
    • 4
    • 15
  • s

    Slackbot

    08/07/2020, 9:04 AM
    This message was deleted.
    g
    r
    • 3
    • 4
  • o

    orafaaraujo

    08/07/2020, 9:04 AM
    Hi, all Does anyone know how to generate a single report on a multi module project? My goal is make Danger (
    danger-kotlin_detekt
    ) read only one file… Thanks in advance
    👍 1
    • 1
    • 4
  • z

    zmunm

    08/14/2020, 6:39 AM
    Hi.. I found a simple typo.. https://arturbosch.github.io/detekt/style.html#noncompliant-code-39
    a?.let { 1.plus(1) } // can be replaced with `if (a == null) 1.plus(1)`
    to
    a?:let { 1.plus(1) } // can be replaced with `if (a == null) 1.plus(1)`
    a?.let { 1.plus(1) } // can be replaced with `if (a != null) 1.plus(1)`
    b
    • 2
    • 4
  • a

    Artur Bosch

    08/17/2020, 3:50 PM
    Hi all, we have a bunch of new releases around detekt [1.11.0](https://github.com/detekt/detekt/releases/tag/v1.11.0): • sonar-detekt [2.2.0](https://github.com/detekt/sonar-kotlin/releases/tag/2.2.0) • intellij-plugin [1.5.0](https://github.com/detekt/detekt-intellij-plugin/releases/tag/v1.5.0) • first public release of the experimental detekt-as-a-compiler-plugin [0.3.0](https://github.com/detekt/detekt-compiler-plugin/tree/v0.3.0) • maven-plugin [1.11.0](https://github.com/Ozsie/detekt-maven-plugin/releases/tag/1.11.0) • github action [1.11.0](https://github.com/marketplace/actions/detekt-all) happy coding!
    🎉 8
    o
    • 2
    • 3
  • j

    Jukka Siivonen

    08/18/2020, 9:25 AM
    So I have updated to latest version of IDEA and Detekt IDEA plugin and now get errors about "Unexpected indentation", IDEA format does not fix the problem so I wonder what is causing this
    g
    • 2
    • 3
  • s

    sanogueralorenzo

    08/25/2020, 11:52 PM
    Hello everyone, I was testing out 1.12.0 through cli with the formatting jar too and I noticed this strange formatting after running detekt, is this correct? Looks strange there is no spacing at all after the correction Running with the build-upon-default-config
    java -jar config/detekt/detekt-cli-1.12.0-all.jar --build-upon-default-config --includes "**/src/main/**/*.kt" -p config/detekt/detekt-formatting-1.12.0.jar --auto-correct --baseline "config/detekt/baseline.yml" --parallel
    b
    • 2
    • 1
  • a

    Adam

    08/26/2020, 1:15 PM
    I’m seeing lots of results for
    ParameterListWrapping
    in 1.12.0 that look either questionable or wrong. Avoiding upgrading for now, rather than disabling the rule. A couple of examples: Questionable. Fails with
    Argument should be on a separate line (unless all arguments can fit a single line)
    and
    Missing newline before ")"
    .
    foo(bar.apply {
        // stuff
    })
    Wrong? Fails
    function(arg1, arg2, arg3)
    with
    Argument should be on a separate line (unless all arguments can fit a single line)
    .
    json(
        """
        {
            "array": [
                ${function(arg1, arg2, arg3)}
            ]
        }
        """.trimIndent()
    )
    Related to this ktlint PR?
    b
    • 2
    • 2
  • j

    Javier

    09/02/2020, 8:54 AM
    [UP] I am having problems with the pre-commit hook. First the changes are commit and after that, I have to commit again to commit the files changed by detekt, anyone is having this issue?
    👀 1
    b
    g
    s
    • 4
    • 6
  • s

    sanogueralorenzo

    09/09/2020, 12:12 PM
    Hello 👋 I was trying to write a pre-commit hook that runs only on changed files (so it takes a second instead of 15 running everything) and I was facing some issues: Some notes: I'm using detekt-cli jar (so I can use the
    -input
    only on changed files) and also to avoid the gradle overhead/plugin
    # Get kotlin changed files
    changedFiles=$(git --no-pager diff --diff-filter=d --name-only HEAD | grep '\.kt[s"]\?$')
    
    if [ -n "$changedFiles" ]; then
      # `paste -sd "," -` replaces newlines with commas so detekt cli -i parameter can take it
      java -jar config/detekt/detekt-cli-1.11.2-all.jar --build-upon-default-config --config "config/detekt/detekt.yml" --baseline "config/detekt/baseline.xml" -p config/detekt/detekt-formatting-1.11.2.jar --auto-correct -i "$( printf "%s" "$changedFiles" | paste -sd "," - )"
    
      if [ $? -ne 0 ]; then
        echo "***********************************************"
        echo "                 Detekt failed                 "
        echo " Please fix the above issues before committing "
        echo "***********************************************"
        exit 1
      fi
    fi
    The above takes around 2 seconds and it is working properly from the tests I've been doing My main issue is that from
    java -jar
    to
    --auto-correct
    is something I already have in my top level detekt task and my top level detekt baseline task (and I wouldn't want to have all that script line repeated in several files since you will have to remember to update all of them when updating version. Is there any way to reuse that part? Thanks! 🙏
    👋 1
    b
    • 2
    • 4
  • k

    kenkyee

    09/09/2020, 11:07 PM
    There's an open issue
    c
    • 2
    • 1
Powered by Linen
Title
k

kenkyee

09/09/2020, 11:07 PM
There's an open issue
c

chao

09/09/2020, 11:08 PM
Thanks Found it https://github.com/detekt/detekt/issues/3062
View count: 19