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

    gammax

    09/02/2019, 9:37 AM
    Don’t you mind opening an issue @Czar? Apparently there is a test case for that scenario and is green at the moment: https://github.com/arturbosch/detekt/blob/daf3b2a9151a8c98ac99df58c5dfc51a5fc9a5be/detekt-rules/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/style/WildcardImportSpec.kt#L48-L53
    c
    s
    • 3
    • 24
  • a

    Anthony f

    09/05/2019, 9:07 AM
    Does anyone knows where I can find the list of correctable rules ?
    a
    • 2
    • 1
  • a

    Anthony f

    09/06/2019, 7:21 AM
    @gammax yes
    g
    • 2
    • 2
  • x

    xenomachina

    09/12/2019, 12:37 AM
    Is there a way to use detekt to find unused
    internal
    (rather than
    private
    ) properties?
    m
    • 2
    • 3
  • s

    Suraj Bokey

    09/13/2019, 10:03 AM
    Does anyone tries to change the indentation to 2. I have tried in config file but looks like detekt is not considering anything from “Formatting Block”
    formatting:
      active: true
      android: false
      autoCorrect: true
      ImportOrdering:
        active: false
        autoCorrect: true
      Indentation:
        active: true
        autoCorrect: true
        indentSize: 2
        continuationIndentSize: 2
    a
    • 2
    • 1
  • d

    dr.dreigh

    09/16/2019, 1:58 PM
    when I see something like this online

    https://gauthamprabhuk.files.wordpress.com/2014/12/cyclomatic-complexity-numbers.png▾

    it's making me think I need to do a lot of refactoring
    a
    • 2
    • 1
  • d

    dr.dreigh

    09/16/2019, 1:59 PM
    But I guess that is the score for a method? What is the project score I got of
    68
    in relation to?
    a
    • 2
    • 1
  • d

    dr.dreigh

    09/17/2019, 8:03 AM
    Thanks for the replies Artur. This makes sense, I had a look at the
    AbstractProcessor.kt
    and thought it may add up the complexity of all the methods of all the files. Our score of 68 is only over 39 functions, so it seems low enough - it's a new service, so fairly small. What do you think about reporting on average McCabe complexity per method in the detekt report? As the sum is only relevant to the project, but an average would be comparable to other applications.
    s
    • 2
    • 1
  • c

    cmgurba

    10/04/2019, 3:11 PM
    apologies if this has been asked before: couldn't find in search. Is there a setting for enforcing explicit return type declaration on all functions? I think this would help my team's readability. Specifically this often gets omitted in Single Expression Functions
    fun myFun(a,b) = logic()
    . Rather than police improper usage of single expression i thought it'd just be easier to enforce return types across the board.
    👍 2
    m
    s
    • 3
    • 2
  • b

    Brais Gabin

    10/12/2019, 11:58 AM
    Hi there! Do you know any project with A LOT of detekt warnings? I need one to test some things.
    s
    s
    • 3
    • 3
  • e

    Ellen Spertus

    10/18/2019, 8:20 PM
    Also, why doesn’t detekt like my constant names? According to the style guide (https://kotlinlang.org/docs/reference/coding-conventions.html#naming-rules) constant property names should be UPPER_SNAKE_CASE.
    a
    b
    • 3
    • 4
  • a

    adam-mcneilly

    10/20/2019, 1:47 AM
    In one of my sample apps, I'm trying to move all of my static analysis checks into the root project, where previously I had them in each of two modules. I put this off because I keep facing some issue that when I put the static analysis plugin inside it's own gradle file, detekt never seems to be able to find my config file and I believe that causes it to fall back on detekt's default config file. I have a PR up on the sample app highlighting the code change, if anyone could help take a look some time, but this isn't urgent. https://github.com/AdamMc331/PokeDex/pull/54/files#r336759846
    t
    • 2
    • 5
  • e

    Ellen Spertus

    10/29/2019, 8:32 PM
    I’m wondering what’s wrong with an empty function block. I have a class with a
    stop()
    method that currently doesn’t do anything. I want the API to say that the
    stop()
    method should be called when it is no longer needed. It’s not the caller’s business whether any instructions are there or not. There may be in the future. Or is this a case of YAGNI?
    m
    b
    • 3
    • 7
  • s

    sanogueralorenzo

    11/06/2019, 9:39 PM
    Hello people, aiming to update to detekt 1.1.1 today + change the detekt level to be a unique top level task (gradle cache is nice but on clean but on CI we jumped from 30 seconds to 2:30 due to an increase amount of modules). Is the best way still to do this https://github.com/arturbosch/detekt/issues/1295#issuecomment-516015993 or the detektAll task from detekt project itself? Asked a while back and got it to work (only if you didn't have any baseline) so asking to see if there is any updates or someone can share some experience trying this out https://kotlinlang.slack.com/archives/C88E12QH4/p1566002344009600
    m
    • 2
    • 3
  • k

    Konstantin Petrukhnov

    11/07/2019, 3:20 PM
    any configuration example for MPP?
    s
    • 2
    • 1
  • s

    sanogueralorenzo

    11/09/2019, 12:50 AM
    Question, what is the difference in detekt between filters and excludes?
    filters = ".*build.*,.*/resources/"
    excludes = ["**/build/**", "**/resources/**"]
    s
    • 2
    • 2
  • s

    sanogueralorenzo

    11/09/2019, 1:24 AM
    Managed to do the top level task that runs in around 20 seconds compared per module where it was taking 2 to 3 minutes. In my top level build gradle I ended up having
    plugins {
        id "io.gitlab.arturbosch.detekt" version "1.1.1"
    }
    
    dependencies {
        detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:1.1.1"
    }
    
    task detektAll(type: io.gitlab.arturbosch.detekt.Detekt) {
        description = "Runs detekt for the entire project."
    
        input = files("$projectDir")
        config = files("$rootDir/config/detekt/detekt.yml")
        parallel = false
        includes = ["**/*.kt", "**/*.kts"]
        excludes = ["**/resources/**", "**/build/**", "**/buildSrc/**", "**/test/**/*.kt"]
        baseline = file("$rootDir/config/detekt/baseline.xml")
        reports {
            xml { enabled = false }
            html { enabled = false }
            txt { enabled = false }
        }
    }
    The detektFormat has
    disableDefaultRuleSets
    &
    buildUponDefaultConfig
    which I'm not sure if I should apply. Also noticed that there is no need for a detekt format task if you just set
    autoCorrect
    to true in the detektAll Only thing I find a bit confusing is that if it can fix all the issues it will fix them but still fail. While on ktlintFormat it would only fail if it is not able to fix any of the issues. The reason I say it is confusing is because I can have 5 issues that only 3 have been fixed but all will be marked as failure. Which leaves the developer in the situation to not know for which ones to look because some of them might have already been fixed. On the other hand for CI this is great because even if it is able to fix them it will fail and sends a clear message of: you have detektIssues run it locally, commit & push
    👍 1
    f
    m
    • 3
    • 5
  • s

    sanogueralorenzo

    11/18/2019, 6:04 PM
    Hello team, is it expected that even after autocorrecting something the task still fails? If after correcting the only issue (which has autoCorrect true) wouldn't it make sense to not have a build failure?
    s
    • 2
    • 7
  • m

    marschwar

    11/18/2019, 8:48 PM
    Hi guys, are any of the maintainers going to be at KotlinConf?
    s
    • 2
    • 2
  • a

    adam-mcneilly

    11/21/2019, 4:01 PM
    High level question: is there any way to have detekt enforce that you use named arguments? Specifically, I was thinking this would be helpful for methods or constructors that have say at least 3 arguments. I haven't found anything in the detekt config that relates to this, but I'm also not sure if it's possible - how would static analysis know if the method I'm calling supports named arguments - it might not if it's a java interrop, right?
    s
    • 2
    • 4
  • t

    thuytrinh

    11/22/2019, 10:23 AM
    Hi folks. I’m trying to use
    Duration
    type https://okkotlin.com/duration/ but it got flagged by the
    MagicNumber
    rule. Just wondering whether anyone knows how to configure the
    MagicNumber
    to exclude if I extract the whole
    Duration
    into a constant like below?
    @ExperimentalTime
    class Operation {
        companion object {
            val DEFAULT_TIMEOUT = 3.seconds
        }
    
        @ExperimentalTime
        fun read(timeout: Duration = DEFAULT_TIMEOUT) {
        }
    }
    So w/ that example, detekt still complains that
    3
    should be constant.
    s
    • 2
    • 1
  • j

    Jukka Siivonen

    11/26/2019, 10:45 AM
    This is somehow related to Kotlin update 1.3.50 -> 1.3.60 because I get this also using 1.3.60 and Detekt 1.0.1
    b
    • 2
    • 4
  • c

    Czar

    11/28/2019, 5:04 AM
    detekt 1.2.0 Spring Boot 2.2.1 Kotlin 1.3.60 I have
    kotlin.spring
    plugin applied and a class annotated with
    @Configuration
    , but
    ProtectedMemberInFinalClass
    is still triggered. The class is effectively open due to `kotlin.spring`plugin and this worked before on detekt 1.0.1, Boot 2.2.0.RC1, Kotlin 1.3.50. Should I try to downgrade them one by one to find which version upgrade caused this or is it a known issue?
    s
    m
    b
    • 4
    • 8
  • r

    robstoll

    12/02/2019, 7:34 AM
    got a regression updating from 1.2.0 to 1.2.1
    Could not set unknown property 'filters' for object of type io.gitlab.arturbosch.detekt.extensions.DetektExtension.
    is this on purpose?
    👆 1
    j
    • 2
    • 3
  • s

    sanogueralorenzo

    12/03/2019, 1:22 AM
    Hello people, after updating from 1.1.1 to 1.2.1 when running
    detektAll
    a centric baseline is ignored. I switched to
    build.gradle.kts
    to ensure that wasn't the issue and was checking detekt project and it is set the same way (and also have the same path)
    baseline.set(file("$rootDir/config/detekt/baseline.xml"))
    Was there any change regarding baseline? I don't seem to find it looking through 1.2.0 and 1.2.1
    s
    • 2
    • 4
  • c

    Czar

    12/08/2019, 11:39 AM
    Can I disable a rule only in IntelliJ, without affecting gradle build and committing anything? So far I've thought of following options (both of which I don't like): 1. copy-paste my detekt.yml from the project to a place outside project, make the change I want, configure plugin with that file while leaving gradle config intact. Negative here is that I have to be on lookout for additional changes to detekt.yml from the repo and not forget to update my local file 2. change the file in the project and move it to a separate "local only" changelist to avoid commiting it. Downside: bit risky, at some point can still commit it unintentionally, e.g. from command line. I need this to suppress ForbiddenComments for
    todo:
    , but only in IntelliJ, because I use
    todo:
    comments when working on a changeset. Showing those as errors kinda messes with the flow. On the other hand I wouldn't want to commit them, so I need them to be reported when I run gradle check
    p
    m
    • 3
    • 3
  • c

    Czar

    12/09/2019, 7:12 AM
    In a simple entity update situation, where there's an entity
    class MyEntity {
      val id: Long? = null
      var prop1: String? = null
      var prop2: String? = null
    // ...
      var propN: String? = null
    }
    and an update command:
    class UpdateEntityCommand {
      val myEntityId: Long
      var prop1: String? = null
      var prop2: String? = null
    // ...
      var propN: String? = null
    }
    the handler should only change property of the entity if corresponding property of the command is not
    null
    :
    class MyHandler(private val repo: MyEntityRepository) {
      fun handle(command: UpdateEntityCommand) {
        with(repository.getOne(command.myEntityId)) {
          // (1)
          if (command.prop1 != null) prop1 = command.prop1
          // (2)
          command.prop2?.let { prop2 = it }
          // (3)
          ifNotNull(command.propN) { propN = it }
        }
      }
    }
    If all the properties are set using method (1) or (3), detekt is happy, if method (2) is used, detekt is complaining about
    "ComplexMethod"
    Should I report this to the issue tracker, or is it as it should be? If the latter, I wonder why?
    b
    • 2
    • 2
  • e

    Eugen Martynov

    12/11/2019, 2:54 PM
    abstract class MemoryCache<T> {
    
        private val cachedValue = AtomicReference<T>()
    
        fun getOrEmpty(): Maybe<T> = Maybe.fromCallable { cachedValue.get() }
    
        fun set(value: T) {
            this.cachedValue.set(value)
        }
    
        fun invalidate() {
            cachedValue.set(null)
        }
    }
    This class has concrete methods
    m
    y
    • 3
    • 7
  • e

    Eugen Martynov

    12/16/2019, 1:06 PM
    can you share also value of detekt findings in your project?
    m
    t
    +2
    • 5
    • 12
  • o

    oleg_osipenko

    12/28/2019, 2:40 PM
    As I see in v1.2.0 was added validation of config files. So after updating Detekt I receive validation error because of my custom rules:
    Property 'custom-rules' is misspelled or does not exist
    where 'custom-rules' is my custom ruleset's id. How is it possible to fix this and enable my custom rules again?
    s
    a
    • 3
    • 4
Powered by Linen
Title
o

oleg_osipenko

12/28/2019, 2:40 PM
As I see in v1.2.0 was added validation of config files. So after updating Detekt I receive validation error because of my custom rules:
Property 'custom-rules' is misspelled or does not exist
where 'custom-rules' is my custom ruleset's id. How is it possible to fix this and enable my custom rules again?
s

schalkms

12/30/2019, 4:42 PM
Can you please create an issue on GitHub for that? I suspect that the following commit doesn't consider custom rules and thus breaks this functionality. https://github.com/arturbosch/detekt/commit/6c3795554f24377920664bb08833202679c8a3d4
a

Artur Bosch

01/01/2020, 2:22 PM
You can make detekt "know" about your rule set in the config:
config:
  validation: true
  excludes: "sample-rules.*"
s

schalkms

01/01/2020, 8:52 PM
It's unfortunately a bit hidden in the docs. https://arturbosch.github.io/detekt/extensions.html Note: As of version 1.2.0 detekt now verifies if all configured properties actually exist in a configuration created by 
--generate-config
. This means that by default detekt does not know about your new properties. Therefore we need to mention them in the configuration under `config>excludes`:
o

oleg_osipenko

01/01/2020, 9:48 PM
Thanks all! Happy New year!
View count: 4