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

    rocketraman

    03/03/2022, 5:57 PM
    Are the indentation rules for multi-line round brackets weird, or am I doing something wrong in my configuration? Code formats like this:
    return (
     foo
      ) as Something
    which looks ugly compared to:
    return (
     foo
    ) as Something
    b
    b
    • 3
    • 4
  • r

    rocketraman

    03/05/2022, 12:30 AM
    This is a bit meta but... is there, or could there be, a detekt rule for reporting on unnecessary rule suppressions? The use case is that a rule was suppressed for some reason, but then the underlying problem is fixed. Detekt would then report on the now-unnecessary suppression so that the rule is not unintentionally broken again later.
    e
    • 2
    • 1
  • e

    eygraber

    03/07/2022, 5:42 AM
    What's the status of KMP support in rules? I'm getting a
    UtilityClassWithPublicConstructor
    violation for:
    expect abstract class PlatformComponent {
      companion object
    }
    But with KMP it makes sense to have it.
    b
    • 2
    • 1
  • e

    Eric

    03/08/2022, 1:45 PM
    do the detekt formatting rules use ktlint under the hood, or just attempt to reproduce ktlint’s behavior? I’m asking because I’m getting different indentation behavior between running detekt w/ auto correct enabled and manually running ktlint. Example:
    fun FooEntity.toWire(): Foo =
        Foo.newBuilder()
           .setLastSeenYearMonth(
                PartialDate.newBuilder()
                    .setMonth(this.lastSeenMonth)
                    .setYear(this.lastSeenYear)
                    .build()
            )
            .build()
    ktlint leaves that block as-is. detekt formats it like this:
    fun FooEntity.toWire(): Foo =
        Foo.newBuilder()
            .setLastSeenYearMonth(
            PartialDate.newBuilder()
                .setMonth(this.lastSeenMonth)
                .setYear(this.lastSeenYear)
                .build()
            )
            .build()
    and then flags the indentation as wrong and increases the debt score.
    g
    • 2
    • 4
  • e

    Eric

    03/08/2022, 10:30 PM
    formatting is completely mangling a few files, seems to be related to Mockk lambdas, maybe. Is there a way to just turn off formatting completely for a file? I tried
    // ktlint-disable
    just after the package declaration, but that didn’t work
    e
    • 2
    • 8
  • t

    tateisu

    03/10/2022, 10:36 PM
    Question. How to set report destination path in build.gradle on detekt 1.19.0 ?
    e
    • 2
    • 2
  • l

    Luke

    03/11/2022, 9:40 PM
    Is there an option to not fail the build when all the issues are autocorrected? Or not print fixed issues in the terminal? Sometimes, I just want to run the autocorrect mid-development and see if there are other issues, but I have to run the task twice to see what was not fixed
    g
    s
    • 3
    • 3
  • e

    Eric

    03/14/2022, 3:43 PM
    is there a way to globally exclude a directory? we have some generated code checked in (yes… we know). And want to exclude that directory from contributing to score and from being formatted automatically.
    e
    t
    c
    • 4
    • 6
  • m

    mkrussel

    03/15/2022, 4:11 PM
    I'm not sure what I'm doing wrong but I cannot get baselines to work with gradle. I ran the
    detektBaseline
    task. It generated a
    detekt-baseline.xml
    file, but when I run
    detekt
    again, all the errors are reported. The warnings are from a custom Rule I created, so it is possible that there is something wrong with how I reported it. It is suppressing some of the warnings but not all. I'm triggering warnings for all
    @property
    tags in class documentation. The baseline includes all the ones found, but it is only suppressing the last one in a given class documentation block. This seems to be a bug.
    g
    • 2
    • 6
  • b

    Brais Gabin

    03/22/2022, 5:23 PM
    Yo talk about the errors than appear with type solving enabled, right?
    j
    • 2
    • 2
  • b

    Brais Gabin

    03/24/2022, 10:32 AM
    Hi! Do you have a KMM project with detekt configured on github? (I mean, open source) I'm starting with KMM and I'm not sure if I'm failing on the gradle part, on the detekt configuration or it is just that the experimental support of detekt for KMM is not working in this case.
    h
    r
    l
    • 4
    • 5
  • t

    Tim Oltjenbruns

    03/26/2022, 12:38 PM
    Trying to write a custom rules module for an android app. • It’s in a separate, kotlin only gradle module. • Depending on it in the app with
    detektPlugins project(":carters-detekt")
    and assembling my module before running detekt • My META-INF seems to be set correctly
    src/main/resources/META-INF/services/io.gitlab.arturbosch.detekt.api.RuleSetProvider
    But I’m getting this error
    io.gitlab.arturbosch.detekt.api.RuleSetProvider: Provider com.carters.retail.detekt.CartersRuleSetProvider not found
    which is the exact The package matches, the folder structure matches, the group matches. What other weirdness should I check that could be wrong?
    g
    • 2
    • 15
  • e

    eygraber

    03/27/2022, 4:49 PM
    Any plans on releasing an RC2? I'd like to test my projects against https://github.com/detekt/detekt/issues/4604
    g
    • 2
    • 1
  • s

    samp

    03/28/2022, 2:26 PM
    do we have a sample project where we could test detekt for Android native application?
    g
    • 2
    • 2
  • b

    Brais Gabin

    03/30/2022, 8:26 PM
    https://twitter.com/mrmans0n/status/1507390768796909571 really good ideas for create a custom and open-source rule set for
    Compose
    if someone is looking for a side project 😛. They have them wrote for
    ktlint
    but they can't open source it now.
    💯 2
    k
    m
    +3
    • 6
    • 10
  • d

    dimsuz

    04/04/2022, 11:05 AM
    Enabled
    UnnecessaryParentheses
    rule and it reported this code
    offset.y.toInt() in item.offset..(item.offset + item.size)
    Sure, technically those can be removed, but wouldn't it look less readable? Do you think this might be an exception or config option? If yes, I can create issue and occasionally a PR.
    g
    e
    b
    • 4
    • 8
  • t

    Tim Oltjenbruns

    04/04/2022, 12:56 PM
    Fairly new to the PSI api, I’ve only used the IR api so far. With type resolution enabled I’m having a pretty hard time getting a function’s return type. I’m resorting to a mishmash of mutliple different BindingContext slices to determine the type, but it seems like there must be a better way. May be a #compiler question, but there they seem to have success with just
    bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, expression)
    So I’m wondering if it may be something specific to how Detekt acquires the BindingContext?
    g
    t
    • 3
    • 7
  • e

    eygraber

    04/04/2022, 6:43 PM
    Were there changes made to
    UnnecessaryLet
    for 1.20? I got a lot of violations in my project after updating to RC2. Most of them are related to using an "out" parameter, but I'm not sure if there's anything detekt can do there, and removing the
    let
    isn't terrible. There are some others, and I got one like this, and I'm not sure why it's unnecessary:
    fun View.postHideKeyboard(shouldClearFocus: Boolean = false) {
      if(shouldClearFocus) {
        clearFocus()
      }
      val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
    
      rootView.windowToken.let { token -> <http://rootView.post|rootView.post> { imm.hideSoftInputFromWindow(token, 0) } }
    }
    m
    • 2
    • 8
  • l

    Landry Norris

    04/05/2022, 5:42 PM
    Are there any plans in the future to have an indicator of whether a file or project follows all of detekt’s rules in the IDE, so I could see tech debt as it happens? I love how detekt keeps my code clean, but I also see a lot of messages in my commit history saying “make detekt happy”.
    m
    g
    • 3
    • 3
  • e

    eygraber

    04/11/2022, 8:52 PM
    Was there an issue with the 1.13.0 artifacts? They don't seem to be in mavenCentral, but the compiler plugin is expecting them. I'm working around it now by explicitly depending on 1.13.1 artifacts. Also, is there a snapshot of the compiler plugin anywhere?
    g
    • 2
    • 1
  • c

    Curtis Kroetsch

    04/12/2022, 6:43 PM
    Is there anyway to change the default severity to error for every check, without needing to explicitly set it for every ruleset?
    s
    c
    • 3
    • 4
  • d

    dix

    04/18/2022, 5:44 PM
    has anyone noticed issues with
    jvmTarget
    when attempting to upgrade to
    1.20.0
    ? when I upgrade the version, now all my detekt tasks fail with
    Invalid value passed to --jvm-target
    I've tried adding
    tasks.withType(Detekt).configureEach {
        jvmTarget = "1.8"
    }
    and that fails with
    Could not get unknown property 'Detekt'
    e
    • 2
    • 6
  • m

    Marcelo Hernandez

    04/22/2022, 5:05 PM
    Anyone successfully using Kotlin's Explicit API Mode with Detekt in an Android project? Did you have to disable the
    RedundantVisibilityModifierRule
    rule?
    e
    e
    • 3
    • 3
  • e

    eygraber

    04/24/2022, 2:40 PM
    Have you had any conversations with anyone at Google or Jetbrains about helping with that? I could contribute towards it, but I only have very basic experience with compiler plugins.
    g
    • 2
    • 1
  • s

    Sam

    04/25/2022, 10:19 AM
    Just spotted that entries in my baseline seem to be different (extra whitespace) depending on whether the function has a doc comment or not. Before I go digging in changelogs and/or file an issue, is this something that's already been spotted/fixed? I think I'm on a slightly old version of detekt.
    m
    • 2
    • 2
  • g

    gammax

    04/25/2022, 8:27 PM
    Just saw question about "running detekt on a single file" on my notifications. I came here to answer, but the message is gone 😅 Anyway, you can use the
    --input
    arg. More on this here https://detekt.dev/docs/gettingstarted/git-pre-commit-hook
    b
    • 2
    • 8
  • e

    eygraber

    04/26/2022, 2:53 AM
    Any plans for a 1.20.1 release for https://github.com/detekt/detekt/pull/4723? It (hopefully) fixes what is blocking me from 1.20.0
    g
    c
    • 3
    • 16
  • a

    An Tran

    04/26/2022, 3:25 AM
    Hello guys, do you know why this url is broken: https://detekt.dev/compose.html
    g
    • 2
    • 1
  • e

    eygraber

    05/01/2022, 6:15 AM
    Not sure if this is a detekt or ksp issue, but when I run
    detektJvmMain
    I get the following warning:
    Execution optimizations have been disabled for task ':samples:kotlin-inject:detektJvmMain' to ensure correctness due to the following reasons:
      - Gradle detected a problem with the following location: '/home/eli/workspace/portal/samples/kotlin-inject/build/generated/ksp/jvm/jvmMain/kotlin'. Reason: Task ':samples:kotlin-inject:detektJvmMain' uses this output of task ':samples:kotlin-inject:kspKotlinJvm' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to <https://docs.gradle.org/7.4.2/userguide/validation_problems.html#implicit_dependency> for more details about this problem.
    warning: classpath entry points to a non-existent location: /home/eli/workspace/portal/samples/kotlin-inject/build/generated/ksp/metadata/jvmMain/kotlin
    I exclude generated ksp files from detekt using:
    tasks.withType<Detekt>().configureEach {
      exclude {
        "/build/generated/ksp" in it.file.absolutePath
      }
    }
    g
    • 2
    • 6
  • d

    dimsuz

    05/04/2022, 5:15 PM
    Hi! Finishing up a small set of detekt rules for Compose (will publish on maven central soon) and I'm trying to use this default config feature. • created a file
    src/main/resources/config/config.yml
    • published to maven local • In a sample project added `detektPlugins("com.example:my-ruleset:1.0.0") • In the
    config/config.yml
    set rules as
    active:true
    • didn't add anything to sample project's
    detekt-config.yml
    Result: rule set is not applied. but if I add in sample's `detekt-config.yml`:
    compose: 
      MyRule:
        active: true
    Then rule gets applied and reports errors. Did I miss something?
    g
    b
    r
    • 4
    • 14
Powered by Linen
Title
d

dimsuz

05/04/2022, 5:15 PM
Hi! Finishing up a small set of detekt rules for Compose (will publish on maven central soon) and I'm trying to use this default config feature. • created a file
src/main/resources/config/config.yml
• published to maven local • In a sample project added `detektPlugins("com.example:my-ruleset:1.0.0") • In the
config/config.yml
set rules as
active:true
• didn't add anything to sample project's
detekt-config.yml
Result: rule set is not applied. but if I add in sample's `detekt-config.yml`:
compose: 
  MyRule:
    active: true
Then rule gets applied and reports errors. Did I miss something?
Does it matter how i pass the config?
class ReusedModifierInstance(config: Config = Config.empty) : Rule(config)
is this ok?
Here's the ruleset repo if you'd like to check out how everything is configured currently: https://github.com/appKODE/detekt-rules-compose
g

gammax

05/04/2022, 5:47 PM
Did I miss something?
That's the expected behavior no? Or are you expecting something different
d

dimsuz

05/04/2022, 5:56 PM
Hmm. I thought that expected behavior is that if I provide
config.yml
in my ruleset and enable rules there, they'll be applied without explicitly specifying them in
detekt-config.yml
. Detekt
1.20.0
changelog seemed to imply that this was done for the
formatting
ruleset.
I forgot to mention that in
config.yml
I've set rules as
active:true
. Edited steps above.
b

Brais Gabin

05/05/2022, 6:59 AM
There's an easy way to check if it is working. Remove your configuration in the project that is using your rule set and execute detektGenerateConfig. You should see your configuration copied to the default configuration.
d

dimsuz

05/05/2022, 10:35 AM
I doesn't get added when I run
detektGeneratedConfig
. By the way, neither is
formatting
. I have added both my and detekt-formatting rulesets to the config
dependencies {
  detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:1.20.0"
  detektPlugins "ru.kode:detekt-rules-compose:1.0.0"
}
then removed
detekt-config.yml
, ran
detektGenerateConfig
and neither my ruleset nor formatting rules are appended.
b

Brais Gabin

05/05/2022, 10:40 AM
I'll take a look
d

dimsuz

05/05/2022, 10:44 AM
I prepared a sample project. Was about to create an issue on github. should I? 🙂
b

Brais Gabin

05/05/2022, 10:45 AM
Go ahead 🙂 that will help a lot
d

dimsuz

05/05/2022, 10:45 AM
but it's really basic though: simply applies a plugin, adds detektPlugins("..formatting") and that's all
Ok, one moment 🙂
❤️ 1
Here it is: https://github.com/detekt/detekt/issues/4812
👍 1
r

rocketraman

05/05/2022, 1:42 PM
I can confirm with 1.20 in my project none of the formatting rules are added with
detectGenerateConfig
.
View count: 59