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
  • l

    Lucas Mo

    07/21/2022, 8:44 PM
    I'm having a bit of a hard time replacing the deprecated "failFast" flag for the gradle alternative
    b
    • 2
    • 12
  • l

    Lucas Mo

    07/21/2022, 8:45 PM
    I'm not savvy on Groovy/Gradle, so I don't know where the new flag is supposed to go
  • d

    Davide Giuseppe Farella

    07/22/2022, 12:17 PM
    Hello people. Is it possible to have a master config file + another file for custom rules only? Use case More teams share the same config, which is fetched from a shared repo and ensures every team follows the same rule-set. But each team should be able to extend Detekt to create additional rules. What is the right way to define a configuration for additional rules only? Additional extra info I noticed that
    detekt.config
    accepts multiple files, but I’m unsure how it works. Do they have a particular priority? How could we add more than 1 config file to the Detekt plugin?
    g
    t
    • 3
    • 16
  • y

    yousef shaaban

    07/25/2022, 11:22 AM
    Hi any idea about this error when upgrade kotlin version from 1.6.20 to 1.7.10 and upgrade Android Gradle plugin AGP to 7.2.0 then run task call detektDebug task at the gradle i used detekt version 1.19.0 then i faced this error when run task incompatible classes were found in dependencies. Remove them from the classpath or use ‘-Xskip-metadata-version-check’ to suppress errors
  • j

    Javier

    07/25/2022, 12:49 PM
    Someone is sharing a detekt configuration via dependencies on multiple projects instead of copy/paste the yaml file?
    y
    s
    +2
    • 5
    • 15
  • d

    Davide Giuseppe Farella

    07/27/2022, 4:28 PM
    Is there a more reliable way to check if a parameter is a lambda, besides this horror?
    private fun isLambda(parameter: KtParameter) = ") -> " in parameter.text
    Note that
    isLambdaParameter
    and
    isFunctionTypeParameter
    evaluate the
    KtParameter
    as a parameter of a lambda block
    b
    • 2
    • 8
  • g

    gammax

    07/17/2022, 2:21 PM
    Hey hey :android-wave: Happy to share that 1.21.0 stable is out 🎉 https://github.com/detekt/detekt/releases/tag/v1.21.0
    🎉 11
    💃 1
    :kotlin-intensifies-purple: 4
    b
    m
    • 3
    • 7
  • a

    alp

    08/01/2022, 11:02 PM
    Hey detekt team, I have a question that is not about detekt functionality but about the functional tests for your plugin. I have a sample plugin that uses androids
    BaseExtension
    to access some information and it works fine on the my sample app project since I can find the extension via
    extensions.findByType(BaseExtension::class.java) // returns null in functional test but works fine on the actual app project
    but when I use
    GradleRunner
    for my plugin’s functional test, the expression above returns
    null
    even though I can find it via:
    extensions.findByName("android") // not null in both cases
    I was looking for a possible problem and found detekt project that has functional tests for android scenario and was wondering if you can suggest something. In my functional test I use this setup:
    File(projectRoot, "settings.gradle")
                .apply {
                    writeText(
                        """
                        include ':app'
                        """
                    )
                }
            File(projectRoot, "build.gradle")
                .apply {
                    writeText(
                        """
                        buildscript {
                            repositories {
                                google()
                                mavenCentral()
                            }
                            dependencies {
                                classpath "com.android.tools.build:gradle:7.0.1"
                                classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.32"
                            }
                        }
                        """
                    )
                }
            val appModule = File(projectRoot, "app").apply { mkdir() }
            File(appModule, "build.gradle")
                .apply {
                    writeText(
                        """
                        plugins {
                            id("com.android.application")
                            id("org.jetbrains.kotlin.android")
                            id("my.custom.plugin") // plugin under test
                        }
                        
                        android {
                            compileSdkVersion 30
                            defaultConfig {
                                applicationId "<http://my.custom.plugin.app|my.custom.plugin.app>"
                                
                                minSdkVersion 23
                                targetSdkVersion 30
                                
                                versionCode 1
                                versionName "1.0"
                            }
                        }
                        """
                    )
                }
    e
    • 2
    • 6
  • s

    samp

    08/02/2022, 6:37 PM
    what's the ETA to have a detekt release with kotlin 1.7 ?
    b
    • 2
    • 1
  • c

    cesards

    08/03/2022, 3:32 PM
    Hey @Peter Mandeljc I’m running into the same issue. Did you find a solution?
    p
    • 2
    • 4
  • c

    cesards

    08/03/2022, 3:40 PM
    Hi everyone! We are updating our base config rules and for a lot of the former rule sets we were using
    excludes: &generatedCode
    to exclude generated code from each of the rules that apply. I thought there might be a way nowadays to exclude generated code from all rules so after looking into it, I found a closed issue about the topic: https://github.com/detekt/detekt/issues/4743 so I went with:
    detekt {
        source = files("src/main/kotlin", "src/test/kotlin", "src/androidTest/kotlin")
    }
    but that didn’t make it. I saw another dev asking about this about two months ago but I’m not sure it got resolved: https://kotlinlang.slack.com/archives/C88E12QH4/p1654877805110359 I also landed on another thread where Nicola brought up:
    Yeah I believe the
    exclude
    has no effect because we changed how we collect the source sets.
    You’ll have to exclude using a like a package path or so. What happens is that excluded are computed for relative paths that are provided by the sourcesset from AGP
    I’m not sure I completely follow the implications of the changes. I could assume this is a generic issue for most of us. Any chance you could share how you deal with this, if that’s the case? Thanks in advance 🙏
    b
    p
    • 3
    • 5
  • e

    ephemient

    08/08/2022, 12:35 PM
    maybe something to ask #ktlint since detekt-formatting delegates to ktlint
    c
    • 2
    • 2
  • m

    Marcelo Hernandez

    08/10/2022, 11:25 PM
    Let's say I want to forbid
    androidx.paging.compose.items
    using
    ForbiddenMethodCall
    instead of
    ForbiddenImport
    , what pattern would I have to use given the following signature:
    public fun <T : Any> LazyListScope.items(
        items: LazyPagingItems<T>,
        key: ((item: T) -> Any)? = null,
        itemContent: @Composable LazyItemScope.(value: T?) -> Unit
    )
    b
    • 2
    • 3
  • z

    Zac Sweers

    08/13/2022, 4:43 PM
    does the detekt IJ plugin track android studio generally? Or only stable releases? I noticed 1.21.1 still isn’t available for EE
    c
    s
    • 3
    • 6
  • j

    Joe

    08/15/2022, 7:12 PM
    question about the
    InjectDispatcher
    rule, should the following violate it:
    class MyRepository(val dispatcher: CoroutineDispatcher) {
        @Inject // mark this constructor as the one used by guice at runtime, tests can still inject a TestDispatcher using the primary constructor
        constructor() : this(<http://Dispatchers.IO|Dispatchers.IO>)
    }
    This is basically equivalent to
    class MyRepository(dispatcher: CoroutineDispatcher = <http://Dispatchers.IO|Dispatchers.IO>)
    but still triggers the detekt rule. Or am I missing a difference?
    c
    • 2
    • 2
  • m

    Mahmoud Ahmed

    08/20/2022, 11:21 AM
    Hello, I want someone can give me example for magic number warning or wildcard import and remove it with @Suppress annotation as intelliJ not support this for kotlin
    m
    l
    • 3
    • 7
  • d

    dimsuz

    08/26/2022, 2:26 PM
    When I run detekt in type resolution mode, it also check generated sources (for example I use an "sqldelight" library and it generates stuff in
    build/generated/sqldelight/code.../SomeFile.kt
    and Detekt analyzes it and prints errors. How should I instruct it to ignore
    build/generated
    ? I recall there was some config option in gradle plugin, but cannot find it in the manual, maybe it got deprecated/removed.
    h
    • 2
    • 2
  • d

    dimsuz

    08/26/2022, 2:45 PM
    Another question. I have a lot of
    NamedArguments
    violation for stuff like this
    combine(myFlow, otherFlow, anotherFlow, ::Triple)
    I don't want to turn this into
    combine(flow = myFlow, flow2 = otherFlow, flow3 = anotherFlow, transform = ::Triple)
    Luckily I've found
    ignoreFunction
    is a thing. But when I do
    NamedArguments:
      ignoreFunction:
        - kotlinx.coroutines.flow.combine
    errors don't go away. Tried wrapping it in single quotes, tried doing
    ignoreFunction: [ 'kotlinx...combine' ]
    instead, still nothing. Is this a bug? this function is not part of some class, it's a top-level one
    s
    b
    • 3
    • 6
  • r

    Richard Gomez

    08/27/2022, 12:06 AM
    Perhaps a silly question, but what is the criteria for
    TooGenericExceptionCaught
    ? It's flagging this as being too generic, but
    IndexOutOfBoundsException
    seems pretty appropriate. https://github.com/rgmz/NewPipe/blob/75917c7f61cde0537075b3e1c5442cdf27755026/app/src/main/java/org/schabi/newpipe/info_list/StreamSegmentAdapter.kt#L54
    s
    • 2
    • 4
  • l

    lilypuchi

    08/29/2022, 10:00 AM
    I’ve written a custom rule as follows:
    class LayoutModifierRequiredRule: Rule() {
      ..
    
      override fun visitNamedFunction(function: KtFunction) {
        super.visitNamedFunction(function)
    
        // ignore non-@Composable functions
        if (!function.hasAnnotation("Composable")) { return }
        
        val doesModifierParameterExist = function.valueParameters.any { it.name == "Modifier" }
    
        if (!doesModifierParameterExist) {
          report(..)
        }
      }
    }
    and in detekt.yml I’ve added the rule as following
    LayoutModifierRequiredRule:
      active: true
      ignoreAnnotated: ['Preview']
    Even though I mention to ignore @Preview annotation, it still highlights the @Preview functions. Am I doing anything wrong here ?
    @Preview
    @Composable
    fun PreviewScreen() {
      MaterialTheme { .. }
    }
    b
    t
    • 3
    • 4
  • p

    PJ Walstrom

    08/30/2022, 6:44 AM
    Hello, we get a lot of security warnings because of a DoS vulnerability detected in snakeyaml 1.30 (see https://security.snyk.io/vuln/SNYK-JAVA-ORGYAML-2806360), in use by detekt 1.21.0. I can see that this is fixed in https://github.com/detekt/detekt/pull/5250. How is the procedure to release a new version of detekt? Could that be done soon?
    t
    • 2
    • 2
  • l

    Landry Norris

    08/31/2022, 7:30 PM
    I need to handle multiple exceptions (in this case, IllegalStateException and a custom exception class) in a catch block. As far as I can tell, Kotlin does not currently support multi catch, so I have to catch Exception and check the types. Detekt sees this and gives me a TooGenericExceptionCaught error. This would be fine if I could use multi catch to check for both types, but that’s not part of the language yet. Should I just disable the detekt error, or is there a good workaround?
    m
    e
    • 3
    • 5
  • c

    Colton Idle

    09/13/2022, 12:04 AM
    is there any way to include detekt via spotless or is it just better to install detekt as a typical gradle plugin?
    b
    • 2
    • 3
  • s

    Sebastian Schuberth

    09/15/2022, 12:37 PM
    For some reason showing SARIF report results stopped working for me, although the report seems to be uploaded correctly. Any idea why might go wrong in this test PR? The GitHub action is configured like so: https://github.com/oss-review-toolkit/ort/blob/26392e163d2dd63dd9937f5369e458315c39cd08/.github/workflows/static-analysis.yml#L24-L32
    • 1
    • 3
  • i

    igor.wojda

    09/16/2022, 9:28 AM
    Am I missing something or default Gradle
    detekt
    task does not verify Android project modules (Gradle subprojects. including the
    app
    default one)?
    j
    b
    • 3
    • 14
  • d

    dimsuz

    09/21/2022, 12:46 AM
    Just saw a changelog of the new release, I'm impressed as always, great work! (time to spice up some of my rules with type resolution)
  • e

    eygraber

    09/21/2022, 4:48 AM
    Just a heads up that 1.22.0 is likely going to cause a lot of issues for people again because of
    continuation_indent_size
    https://kotlinlang.slack.com/archives/CKS3XG0LS/p1663735640538999
    e
    z
    g
    • 4
    • 9
  • m

    mkrussel

    09/22/2022, 8:04 PM
    Not sure if this is a known problem or not, but the
    KDocReferencesNonPublicProperty
    is generating false positives when I use the ability to set the text for a code link to the name of a private property. This is a bad example but it shows that the property
    workItem
    is being accessed in KDoc.
    g
    • 2
    • 2
  • g

    gammax

    09/23/2022, 10:21 AM
    We need a Detekt custom reaction for this slack btw 🙂
    s
    • 2
    • 1
  • i

    igor.wojda

    09/23/2022, 10:43 AM
    Hello - how to enable this rule? https://github.com/detekt/detekt/blob/cb29e0a71d3f27134b769dfad296e7307c013242/det[…]o/gitlab/arturbosch/detekt/formatting/wrappers/TrailingComma.kt
    m
    g
    s
    • 4
    • 6
Powered by Linen
Title
i

igor.wojda

09/23/2022, 10:43 AM
Hello - how to enable this rule? https://github.com/detekt/detekt/blob/cb29e0a71d3f27134b769dfad296e7307c013242/det[…]o/gitlab/arturbosch/detekt/formatting/wrappers/TrailingComma.kt
m

Marek Czerwinski

09/23/2022, 10:51 AM
Hello, I haven't tried but maybe this will be helpful: https://github.com/detekt/detekt/blob/main/detekt-formatting/src/main/resources/config/config.yml#L182
g

gammax

09/23/2022, 11:16 AM
Have you imported the detekt formatting plugin?
i

igor.wojda

09/23/2022, 11:37 AM
Thx I was able to make it work. It looks like my default detekt config didn't have any rules from the above
detekt-formating
rule set. I added this manually and it had worked. @gammax is there a detekt check to make sure that custom config file contains all of the rules? (kid of detekt config meta check) As you see it is easy to miss
detekt-formating
rule set ot upgrade detekt without updating config files (thus config for some rules will stay kind of hidden)
BTW There may be also potential improvement for the documentation as it was not obvious how to enable these rule with custom config (I would expect to have some info here https://detekt.dev/docs/rules/formatting)
s

schalkms

09/24/2022, 9:30 AM
Thanks for the hint! May I ask you to submit your ideas via GitHub issues?
i

igor.wojda

09/24/2022, 10:53 AM
Two separate actions from this discussion 1. Docs update PR https://github.com/detekt/detekt/pull/5345 2. Added a comment to existing "detekt config upgrade" https://github.com/detekt/detekt/issues/4517
View count: 17