https://kotlinlang.org logo
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
  • z

    Zac Sweers

    12/01/2022, 9:26 PM
    are there ways to diagnose how long detekt checks take? When running detekt with type resolution, we’ve been surprised to find it runs even slower than android lint (!!)
    e
    g
    +2
    • 5
    • 42
  • d

    dimsuz

    12/06/2022, 5:55 PM
    I'm trying to convert my rule to using type resolution: • Added
    @RequiresTypeResolution
    to the rule class • In my test (using
    KoTest
    ) I have called
    createEnvironment()
    • Then I switched to
    MyRule().compileAndLintWithContext(env, code)
    All existing tests keep passing (so no errors in test/env setup). But the following code:
    fun visitNamedFunction(function: KtNamedFunction) {
      println(bindingContext.getType(function))
    }
    prints "*null*". I have also checked that
    bindingContext == BindingContext.EMPTY
    returns false. Did I miss someting?
    b
    • 2
    • 4
  • f

    fred

    12/07/2022, 9:17 AM
    how are you using Detekt on multiplatform projects these days? I was hoping to find a single task that would sweep my entire project but from what I see this doesn’t exist and is being tracked here, so the options I see are: • create this task myself (any directions on how I could do that?) • do something like this, it seems to work great (basically setting the module root to be the source so all source sets are considered) • run multiple tasks: ◦
    detektMain
    to sweep non-multiplatform stuff with type resolution ◦
    detektMetadataMain
    to sweep
    commonMain
    on all modules (found this one here) ◦
    detektAndroidDebug
    and
    detektAndroidRelease
    to sweep Android code in multiplatform modules ◦ …and how do I sweep iOS code in multiplatform modules? I’ve tried
    detektMetadataIosMain
    ,
    detektIosX64Main
    ,
    detektIosArm64Main
    and
    detektIosSimulatorArm64Main
    but they all seem to fail to find issues on code inside
    iosMain
    — should I file an issue or am I missing something? I have a minimum reproducible example here: https://github.com/tfcporciuncula/detekt-kmm-issue (this commit summarizes everything) • any other option?
    m
    g
    e
    • 4
    • 6
  • m

    Marek Czerwinski

    12/08/2022, 10:49 AM
    Hey everyone 👋 Can I use
    excludes
    for every rule in a config? Sample below:
    LargeClass:
      active: true
      threshold: 150
      excludes: ['**/test/**', '**/*Test.kt', '**/*Spec.kt']
    s
    • 2
    • 1
  • e

    eygraber

    12/09/2022, 8:12 PM
    If I'm running the following tasks, do I also need to run the
    detekt
    task, or is that covered by the others?
    ./gradlew detektJvmMain detektDebug detektJsMain detektMetadataMain
    g
    • 2
    • 3
  • r

    rocketraman

    12/13/2022, 2:02 PM
    Is anyone at JetBrains aware of the problem where IDEA blames pretty much every bug on Detekt in the Internal Errors reporting system (https://github.com/detekt/detekt-intellij-plugin/issues/271)? I'm pretty zealous about reporting issues, but since everything is being blamed on Detekt, I can't.
    g
    • 2
    • 2
  • e

    eygraber

    12/15/2022, 4:55 AM
    Is there any way to have detekt print out the ktlint config that it uses?
    g
    • 2
    • 4
  • d

    dimsuz

    12/19/2022, 11:48 AM
    I am trying to setup running tests with type resolution on detekt-rules-compose and looks like I'm stuck, need some ideas on what to try next. The process so far: 1. I need Compose to be in the classpath, so that test snippets can be correctly compiled by
    compileAndLintWithContext
    2. Using "native" android artifacts is not possible, because it required Android Gradle Plugin which I don't want to add (or should I try?) 3. Instead I started to use artifacts by Jetbrains's Compose Desktop, they do not require AGP 4. Now imports can be used, but if I compile a test snippet (see in thread), it fails with the "cannot inline "Box" method error" (see in thread) 5. If I a) add JB plugin to "plugins" block and b) write the same compose-code in the "Test.kt" file (not as snippet!) it compiles (without a) it gives the same "cannot-inline" error) So from 5 I can see that compiling compose code as part of the test project works, but compiling with
    compileAndLintWithContext
    doesn't work, it seems that compiler plugin gets applied in the first case and doesn't in second. Is there a way to make test rule aware of compiler plugins?
    b
    • 2
    • 9
  • y

    Yusuf.I

    12/19/2022, 8:14 PM
    Hello, quick question. Is there is any way where i can check if a function has javadoc or not
    b
    • 2
    • 5
  • l

    Landry Norris

    12/20/2022, 6:38 PM
    Is the detekt IDE plugin supposed to use the config/detekt/detekt.yaml file? I see warnings in my IDE for things I have disabled in the yaml. Running the gradle task works fine.
    m
    • 2
    • 2
  • e

    eygraber

    12/25/2022, 2:13 PM
    Is there an API in the detekt gradle plugin for loading a config from a jar (e.g. from maven central)? Or would I have to use Gradle APIs to extract the config file from the jar?
    b
    b
    • 3
    • 18
  • b

    Bilgehan KALKAN

    01/11/2023, 8:02 AM
    Hi, I’m trying to configure Android project that uses Detekt and also has custom rules. For that reason application uses
    detektDebug
    But recently I’m trying to validate “.kts” files too. But when I configure
    DetektExtension
    with that paths(for root
    settings.gradle.kts
    files too),
    detektDebug
    task does not validates that files. It only validates default paths. On CI environment application is validated only with
    detektDebug
    task because of baseline files. Is there any way to configure
    detektDebug
    task inputs via Extensions? When I tried to reach the task via
    tasks.named<Detekt>("detektDebug")
    call it was tricky, I had to do this call on
    doAfter
    block. Also project uses published plugins to apply all required plugins, so ı didn’t want to add confusing tricks on there. Also I tried to configure
    detektDebug
    task to depend on
    detekt
    task and configured
    DetektExtension
    to only check “.kts” files but when I do that
    --continue
    option become useless. (CI environment uses
    --continue
    option and we would like to provide complete reports to developers so that they can fix all issues at once instead of waiting results for each validation errors commit by commit.)
    e
    • 2
    • 8
  • s

    Sebastian Schuberth

    01/17/2023, 10:31 AM
    Does anyone have an example of applying detekt inside a precompiled convention plugin for Gradle? When I try to follow https://docs.gradle.org/current/samples/sample_convention_plugins.html#compiling_convention_plugins, I'm getting
    Unable to load class 'org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension'.
    
    This is an unexpected error. Please file a bug containing the idea.log file.
    b
    e
    • 3
    • 10
  • s

    Sebastian Schuberth

    01/25/2023, 9:27 AM
    Is there a detekt / ktlint rule to enforce formatting of non-one-liner function-expressions to be
    fun addResult(projectAnalyzerResult: ProjectAnalyzerResult) = apply {
        // ...
    }
    instead of
    fun addResult(projectAnalyzerResult: ProjectAnalyzerResult) =
        apply {
            // ...
        }
    ?
  • e

    eygraber

    01/26/2023, 2:42 AM
    Are the limitations mentioned in the compiler plugin README temporary (i.e. haven't been implemented yet) or permanent (i.e. can't be implemented in the compiler plugin)?
    g
    • 2
    • 1
  • m

    Matt Russell

    01/30/2023, 7:17 PM
    ℹ️ I've submitted the detekt CLI as a Nix package (currently it's made it only into the unstable channel):
    $ nix-shell -p detekt -I nixpkgs=<https://github.com/NixOS/nixpkgs/archive/f80ac848e3d6f0c12c52758c0f25c10c97ca3b62.tar.gz> --command 'detekt --version'
    1.22.0
    s
    • 2
    • 1
  • y

    Yoni Obia

    02/05/2023, 1:24 PM
    Hello ! Just a simple question, I can't find the doc concerning this config:
    formatting:
      active: boolean
      android: boolean
      autoCorrect: boolean
    what does the android argument mean ?
  • g

    gammax

    02/05/2023, 2:00 PM
    Those are coming from ktlint
  • y

    Yoni Obia

    02/05/2023, 2:53 PM
    Oooh ok thanks
  • m

    Michael Marshall

    02/11/2023, 7:27 AM
    Hi! I’m trying to use
    ForbiddenMethodCall
    on a function annotated with
    @JvmStatic
    and it doesn’t appear in my Detekt warnings (I am running it with type resolution via
    detektMain
    ). Is that a limitation or am I doing something wrong? detekt.yml
    ForbiddenMethodCall:
        active: true
        methods: [
          ... // Other method definitions which are working properly
          'com.bluelinelabs.conductor.RouterTransaction.with', // Not working
        ]
    Function definition (from a 3rd party lib)
    package com.bluelinelabs.conductor
    
    RouterTransaction {
    ...
      companion object {
        @JvmStatic
        fun with(controller: Controller): RouterTransaction = RouterTransaction(controller)
      }
    }
    Callsite
    RouterTransaction.with(MyController())
    b
    • 2
    • 4
  • t

    Thomas Hormes

    02/13/2023, 7:58 AM
    How is Detekt supposed to be applied to multi-module Android projects, like for example the Now in Android App ? When I apply it to the project level build.gradle file, I do not get any Type Resolution tasks and when I execute the
    detekt
    Task nothing happens. Do I need to apply the Detekt plugin to each module individually? Edit: Adding the
    detektAll
    task, which is sometimes recommended does not help either
    a
    • 2
    • 1
  • k

    Kevin

    02/15/2023, 1:11 PM
    Hi all, I have a question: I'm running the detekt gradle plugin (version 1.22.0) and the
    detekt
    task is using different rules than
    detektMain
    . It's not skipping over any files, but it is applying different rules in the same file. My detekt config in gradle looks like this:
    detekt {
        config = files("../detekt.yml")
        buildUponDefaultConfig = true
        source = files("src")
    }
    And detekt.yml looks like this:
    complexity:
      active: true
      CognitiveComplexMethod:
        active: true
        threshold: 5
    
    naming:
      InvalidPackageDeclaration:
        active: false
    I'm using gradle 7.5.1 and targeting jdk 11. Namely,
    detektMain
    includes
    UnnecessaryFilter
    and
    VarCouldBeVal
    while
    detekt
    does not. Is this expected? I didn't find anything on google or in the github issues.
    s
    • 2
    • 3
  • p

    Peter Mandeljc

    02/15/2023, 3:01 PM
    I'm wondering, is this a false positive for
    UnnecessaryLet
    ?
    val x = getJavaDuration()
        .toHours()
        .let { ceil(it / 24.0) }
        .roundToLong()
    m
    • 2
    • 1
  • k

    kenkyee

    02/16/2023, 3:39 PM
    for ktlint embedded in detekt, is there any way to use a custom ktlint ruleset? I couldn't find anything in the detekt docs or issues mentioning how to do this...
    b
    • 2
    • 1
  • l

    Luca Nicoletti

    02/21/2023, 9:58 AM
    I’m running
    detekt
    and updating a rule (custom), but the rule code is not the latest I have in the file. Any why I can force re-loading the rule when I run
    ./gradlew detekt
    ?
    b
    m
    s
    • 4
    • 12
  • c

    Colton Idle

    02/23/2023, 7:39 PM
    Where can I view the output of detekt. i just added it to a project. i ran the detekt gradle task... but i can't find the output in any of the build folders... 🤔
    l
    e
    • 3
    • 5
  • l

    Luca Nicoletti

    02/24/2023, 2:32 PM
    Has anyone made a custom rule/does a default one exists that check for
    when
    statement orders? I’m looking to have all
    objects
    of a sealed class/interface coming first, then the data classes, so my when(s) would look like:
    when (a) {
       object1 -> {}
       object2 -> {}
       object3 -> {}
       is dc1 -> {}
       is dc2 -> {}
    }
    And not with
    is
    mixed between all the statements
    c
    b
    • 3
    • 15
  • f

    Francis Mariano

    02/28/2023, 2:23 PM
    hello everyone. I am following some instrctions to execute detekt in entire project, so now I have the task :
    tasks.register("detektAll") {
        allprojects {
            this@register.dependsOn(tasks.withType<io.gitlab.arturbosch.detekt.Detekt>())
        }
    }
    I would like to run the detektAll in each build, but I unable configure that. Do you know a better approach to run detekt in entire project ???
    s
    j
    m
    • 4
    • 9
  • n

    Nikolay Puliaev

    03/01/2023, 3:17 PM
    Hi everyone. I’m using CLI in Github Actions with help of setup detekt action. I just migrated from 1.21.0 to 1.22.0 and added to
    detekt.yml
    new
    libraries
    and
    formatting
    sections, now build doesn’t work because apparently I need to connect plugins to CLI. Part of the action to execute detekt:
    jobs:
      detekt:
        runs-on: buildjet-4vcpu-ubuntu-2004
        steps:
          - uses: actions/checkout@v3
          - name: Setup detekt
            uses: peter-murray/setup-detekt@v2
            with:
              detekt_version: 1.22.0
          - name: Run detekt
            run: detekt-cli \
              --config plugins/detekt/detekt.yml \
              --build-upon-default-config \
              --excludes '**/androidTest/**','**/build.gradle.kts'
    How can I connect both
    formatting
    and
    libraries
    plugins? I’ve read the documentation, but there’s no actual example how to add the plugins.
    b
    • 2
    • 5
  • t

    tokuhirom

    03/03/2023, 6:53 AM
    I got an error with detekt 1.22.0+kotlin 1.8. is there any plan to release new detekt version with kotlin 1.8 support?
    b
    • 2
    • 2
Powered by Linen
Title
t

tokuhirom

03/03/2023, 6:53 AM
I got an error with detekt 1.22.0+kotlin 1.8. is there any plan to release new detekt version with kotlin 1.8 support?
b

Brais Gabin

03/03/2023, 9:52 AM
detekt supports kotlin 1.8. Its probably an error in your setup.
t

tokuhirom

03/03/2023, 10:39 AM
ok, thanks!
View count: 21