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

    09/14/2020, 3:18 PM
    Hi Everyone, Could you please help me on how Detekt is different from Android lint. would be helpful for me to a deeper knowledge .. I mean what kind of issues Detekt uniquely reports compared to AndroidLint
    z
    e
    • 3
    • 5
  • g

    gabrielfv

    09/16/2020, 11:22 PM
    Hello, how do I find out if a method call stands for an extension for nullable type. If i have the method
    Type?.extForNullable()
    I want to identify in a rule if this method is called, and not a version of it exclusive for a non-null instance of
    Type
    , or a more specialized version of it, like
    SpecificType?.extForNullable()
    , even if
    SpecificType : Type
    . I’m trying to visit dot-qualified expressions, since if I go for a safe expression I’m not calling a nullable version any way, but idk how to follow from here
    g
    • 2
    • 1
  • d

    Daniel Svensson

    09/22/2020, 8:26 AM
    As kotlin doesn't have any granular
    -Werror=...
    etc I was hoping to convince detekt to error out if there are any: unused variables, unused methods, useless
    foo?.bar
    etc, but I can't seem to find it in the configuration. Am I missing something?
    b
    • 2
    • 4
  • m

    Marcelo Hernandez

    09/24/2020, 6:47 PM
    Hello. I am trying to resolve the return type of a function that returns a
    Flow<T>
    (including subclasses) in
    visitNamedFunction
    . I am new to the APIs in
    kotlin-compiler-embeddable
    . I am trying to use:
    bindingContext[BindingContext.FUNCTION, function].returnType
    but that seems to resolve to an
    UnresolvedType
    . I have also tried
    function.getResolvedCall(bindingContext)
    but that always returns
    null
    . Is there any way to resolve types that are not considered built-in?
    • 1
    • 1
  • k

    karandeep singh

    09/25/2020, 8:32 AM
    Also, is anyone aware of any issues adding detekt with novoda plugin? (https://github.com/novoda/gradle-static-analysis-plugin)
    s
    t
    • 3
    • 7
  • t

    themishkun

    09/26/2020, 10:00 AM
    Hi everyone, I wonder if detekt can export rules as part of the library (like android lint does). So, If I maintain a kotlin lib and want to highlight common errors, can I provide detekt rules that would be automagically included in consumer's detekt suite after she adds lib dependency (without explicitly declaring rule)?
    g
    • 2
    • 1
  • r

    robstoll

    10/01/2020, 5:19 AM
    updating to detekt 1.14.1 fails for me with:
    Could not find io.gitlab.arturbosch.detekt:detekt-bom:1.14.1.
                  Searched in the following locations:
                    - <https://plugins.gradle.org/m2/io/gitlab/arturbosch/detekt/detekt-bom/1.14.1/detekt-bom-1.14.1.pom>
                    - <https://repo.maven.apache.org/maven2/io/gitlab/arturbosch/detekt/detekt-bom/1.14.1/detekt-bom-1.14.1.pom>
                    - <https://jcenter.bintray.com/io/gitlab/arturbosch/detekt/detekt-bom/1.14.1/detekt-bom-1.14.1.pom>
    is this version not yet published?
    g
    • 2
    • 3
  • b

    BorzdeG

    10/06/2020, 5:56 PM
    1: Task failed with an exception.
    -----------
    * What went wrong:
    Execution failed for task ':myproject:detekt'.
    > Could not resolve all files for configuration ':myproject:detekt'.
       > Could not resolve org.jetbrains.kotlinx:kotlinx-html-jvm.
         Required by:
             project :myproject > io.gitlab.arturbosch.detekt:detekt-cli:1.14.1 > io.gitlab.arturbosch.detekt:detekt-bom:1.14.1
          > Cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
              - jvm-api
              - jvm-runtime
              - metadata-api
            All of them match the consumer attributes:
              - Variant 'jvm-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'jvm-runtime' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'metadata-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'kotlin-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'common' but the consumer didn't ask for it
       > Could not resolve org.jetbrains.kotlinx:kotlinx-html-jvm.
         Required by:
             project :myproject > io.gitlab.arturbosch.detekt:detekt-cli:1.14.1 > io.gitlab.arturbosch.detekt:detekt-core:1.14.1 > io.gitlab.arturbosch.detekt:detekt-report-html:1.14.1
          > Cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
              - jvm-api
              - jvm-runtime
              - metadata-api
            All of them match the consumer attributes:
              - Variant 'jvm-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'jvm-runtime' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.libraryelements 'jar' but the consumer didn't ask for it
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'java-runtime' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'jvm' but the consumer didn't ask for it
              - Variant 'metadata-api' capability org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2:
                  - Unmatched attributes:
                      - Provides org.gradle.status 'release' but the consumer didn't ask for it
                      - Provides org.gradle.usage 'kotlin-api' but the consumer didn't ask for it
                      - Provides org.jetbrains.kotlin.platform.type 'common' but the consumer didn't ask for it
    b
    • 2
    • 5
  • j

    Jiddles

    10/09/2020, 10:11 AM
    Hey! Not sure if this is the best place to ask but does anyone know what happened to the Klones project/repo? (This one btw https://github.com/detekt/klones)
    s
    • 2
    • 3
  • f

    fo2rist

    10/14/2020, 10:30 PM
    Does anyone know if it's possible to set Detekt threshold in gradle file and keep the configuration in .yml? Use case: I have three projects in one repo and I want to share the config, but the threshold for each project is independent.
    g
    b
    t
    • 4
    • 6
  • s

    sanogueralorenzo

    10/28/2020, 11:27 AM
    Hello 👋 have a usecase where I want to ignore LongMethod if the method has a specific name. Is that possible?
    g
    t
    • 3
    • 10
  • m

    mjthornton

    10/30/2020, 7:05 PM
    Is there a way to only enable a few rules without setting each unwanted .yml rule with: active: false?
    g
    • 2
    • 1
  • l

    Lilly

    11/02/2020, 1:45 PM
    Hi, I have registered the following task in my root build.gradle.kts:
    tasks.register<Detekt>("detektAll") {
            setSource(projectDir)
            buildUponDefaultConfig = true
            config.setFrom(configFile)
            parallel = true
            debug = true
            reports {
                xml.enabled = false
                html.enabled = false
                txt.enabled = false
            }
            include("**/*.kt")
            include("**/*.kts")
            exclude("resources/")
            exclude("build/")
        }
    I run the task with
    gradlew detektAll
    . Why does it log the output to console in first run but not in second run? Edit: ok got it. I had set the maxIssues to 30, now it's 0 again. Same code different question: my task does not show the
    formatting
    rule set from the
    formatting
    plugin while
    detekt
    does. Did I miss something. Edit2: ok got second issue too. I had to add
    dependencies {
        detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.14.2")
    }
    to my root build.gradle.kts, not to my sub projects build script. Edit3: correction: I have to add it to root build script and sub projects build script aswell
    g
    • 2
    • 3
  • l

    Lilly

    11/02/2020, 3:31 PM
    When running
    detekt
    task, it complains about
    SpreadOperator
    . The docs state:
    When type resolution is enabled in detekt this case will not be flagged by the rule since it doesn’t suffer the performance penalty of an array copy.
    Does it mean
    detekt
    shouldn't detect that issue?
    g
    • 2
    • 2
  • m

    mjthornton

    11/05/2020, 5:39 PM
    I'm currently writing unit tests for my custom rules. Is there a way to supply .lint() an entire file instead or strings? This works for me, but for longer strings, it gets very messy
    @Test
    fun `TOFUBRuleTest() Test`(){
        TOFUBRule().lint("$kDOCTestString")
    }
    g
    • 2
    • 2
  • s

    spand

    11/16/2020, 10:35 AM
    Can I use detekt to ban usages of certain classes/methods in external modules ? ie. a method from the stdlib ? (And if not does such a tool exists?)
    g
    • 2
    • 2
  • j

    Jakub Chrzanowski

    11/22/2020, 10:38 PM
    Hi folks! How is that if I run
    detekt
    Gradle task directly, it prints output with proper colors, but when run via
    check
    task, I get something like:
    > Task :detekt FAILED
    formatting - 5min debt
    	[33mNoConsecutiveBlankLines - [] at /Users/hsz/Projects/JetBrains/intellij-plugin-template/src/main/kotlin/org/jetbrains/plugins/template/services/MyProjectService.kt:3:1[0m
    Overall debt: 5min
    g
    • 2
    • 6
  • s

    Sourabh Rawat

    11/25/2020, 9:15 AM
    I was trying to use precompiled gradle plugins in buildSrc but it is giving me following error with v1.2.2
    Caused by: org.gradle.api.GradleException: Error resolving plugin [id: 'org.jetbrains.kotlin.jvm', version: '1.3.61']
    	at org.gradle.plugin.use.internal.DefaultPluginRequestApplicator.resolveToFoundResult(DefaultPluginRequestApplicator.java:207)
    	... 155 more
    Caused by: org.gradle.plugin.management.internal.InvalidPluginRequestException: Plugin request for plugin already on the classpath must not include a version
    It works if I upgrade detekt to latest one. But I want to know why it is failing in older version, since upgrading the plugin will require more than a few changes and this is a production project Seems like it is failing on latest one as well
    z
    b
    • 3
    • 5
  • j

    Javier

    12/02/2020, 11:31 AM
    Has Detekt, in general or the intellij plugin, a strict mode which force the refactor like Dart/Flutter plugin has? For example, if I have a
    data class
    in a single line which ends with a trailing comma, using the detekt plugin to format it, the format keeps. But it should be changing to multiline (or at least delete the trailing comma, but with a strict mode I think it should be converted to multiline). Another example is can be:
    fun something() = "something"
    fun something() = 
        "something"
    The second one clearly should be reformated to the first one because it fits de space, but like both approach are valid, it doesn't get reformat I love a lot how the reformat works in Dart/Flutter because it forces A LOT how the code should look. Overall about spacing and playing with trailing comma to reformat from single line (or a "broken multiline") to multiline that looks good
    j
    g
    b
    • 4
    • 14
  • s

    Sebastian Schuberth

    12/07/2020, 5:03 PM
    Hi, since the upgrade of my project to Kotlin 1.4.20 I'm getting very weird excpetions from detekt, like "Collection is empty", "configUrl must not be null", or "io/github/detekt/tooling/api/InvalidConfig". Has anyone else seen these?
    g
    • 2
    • 7
  • t

    themishkun

    12/17/2020, 11:06 AM
    Hello there. I am having a trouble enabling type resolutions in my projects with detekt 14.2 version. When running
    detektMain
    command, I keep getting the same error about detekt not being able to choose kotlinx-html dependency. Like that
    Cannot choose between the following variants of org.jetbrains.kotlinx:kotlinx-html-jvm:0.7.2
    Any tips on this? Full exception message can be found here https://pastebin.com/uPHFNVtB Thank in advance
    g
    • 2
    • 7
  • t

    themishkun

    12/17/2020, 3:02 PM
    Is there any configuration for disabling type-resolution for
    UnusedImport
    rule? Since type resolution does not work with kotlin synthetics, and our project is full of them, this rule give me 1k+ false-positives
    g
    • 2
    • 3
  • b

    Brais Gabin

    12/24/2020, 9:26 AM
    Do you think that an issue for this would be useful? https://twitter.com/Piwai/status/1341695742486953987
    :yes: 2
    c
    • 2
    • 1
  • s

    Sebastian Schuberth

    01/05/2021, 1:52 PM
    Is there an easy way to get the relative path to a file WRT the Gradle root project in a `Rule`'s
    visitPackageDirective
    function?
    b
    c
    • 3
    • 4
  • t

    taso

    01/08/2021, 5:20 PM
    Does anyone use "Deprecation" rule under "potential-bugs"? I just enabled it but it did not give me any new error. We have a lot of deprecated usages actually
    g
    s
    • 3
    • 7
  • m

    Marcelo Hernandez

    02/04/2021, 12:03 AM
    Hello. If I recall correctly, there used to be documentation in the Detekt GitHub repo containing the steps to run for those authoring pull requests. Not sure if it was removed or am I just not seeing it? 🤔
    g
    • 2
    • 16
  • b

    Big Chungus

    02/07/2021, 6:44 PM
    Is it possible tu use detekt as formatter instead of ktlint?
    c
    • 2
    • 8
  • j

    Javier

    02/08/2021, 9:26 AM
    I am trying to ignore failures via
    ignoreFailures = true
    and I tried
    isIgnoreFailures = true
    too. Nothing works. This was working for me some months ago.
    • 1
    • 2
  • s

    Sebastian Schuberth

    02/09/2021, 1:28 PM
    Hi there, is there a rule in detekt that generally checks that operators instead of function calls are used? I.e.
    +=
    instead of
    .add()
    ,
    in
    instead of
    .contains()
    etc? So far I wasn't able to find one.
    b
    • 2
    • 3
  • g

    gammax

    02/09/2021, 7:35 PM
    x-posting from #multiplatform here: https://kotlinlang.slack.com/archives/C3PQML5NU/p1612899305397200
    ❤️ 3
    c
    b
    s
    • 4
    • 13
Powered by Linen
Title
g

gammax

02/09/2021, 7:35 PM
x-posting from #multiplatform here: https://kotlinlang.slack.com/archives/C3PQML5NU/p1612899305397200
❤️ 3
c

chao

02/09/2021, 8:01 PM
Was
<https://github.com/Kotlin/kmm-sample>
used to evaluate the PR? I can try with the official sample first
g

gammax

02/09/2021, 8:01 PM
Oh that would be great 👍
I created a sample using the IntelliJ Project Template
c

chao

02/09/2021, 8:02 PM
We can even try adding detekt to the sample project :)
I recently found that Detekt is applied in the IntelliJ Plugin sample project
:kotlin-intensifies: 2
g

gammax

02/09/2021, 8:03 PM
Oh really?
c

chao

02/09/2021, 8:03 PM
https://github.com/JetBrains/intellij-platform-plugin-template/blob/main/detekt-config.yml
b

Brais Gabin

02/09/2021, 8:07 PM
Nice!!
s

seb

02/10/2021, 8:40 AM
Maybe @Sebastian Aigner can help with at least some of this 🙂
g

gammax

02/10/2021, 8:41 AM
That would be great 🙏
c

chao

02/11/2021, 11:16 PM
It looks like Kotlin official documentation got an upgrade https://kotlinlang.org/docs/mpp-share-on-platforms.html
g

gammax

02/11/2021, 11:18 PM
You mean #docs-revamped?
c

chao

02/11/2021, 11:23 PM
Indeed! Didn’t know there was an announcement in that channel
View count: 3