https://kotlinlang.org logo
#detekt
Title
# detekt
r

rudolf.hladik

11/29/2021, 10:34 AM
Hello there, we use the limit of 60 loc per method as a
Detekt
rule
Copy code
LongMethod:
    active: true
    threshold: 60
but we find it too small for
@Composable
functions. Is there a way to exclude composables from this limit, something like
ignoreAnnotated
in
LongParameterList
?
b

Brais Gabin

11/29/2021, 10:39 AM
If you updates to the last RC (the stable version is near to be released) you can use
ignoreAnnotated
in that rule (or any other rule)
r

rudolf.hladik

11/29/2021, 10:42 AM
thx, I see its already in v1.18.0 🙂 I will upgrade
g

gammax

11/29/2021, 10:52 AM
Just got released btw 🙂
💃 2
l

LeoColman

12/29/2022, 1:43 PM
I don't usually face this issue. My
@Composable
methods are not longer than my non-composable ones
d

diego-gomez-olvera

12/29/2022, 1:44 PM
which threshold do you use? Maybe the configuration that I use is too strict
l

LeoColman

12/29/2022, 1:44 PM
I use the default one
d

diego-gomez-olvera

12/29/2022, 1:45 PM
ah, 60
b

Brais Gabin

12/29/2022, 1:45 PM
Same for me. 60 lines (default value). My composables shouldn't be bigger than other functions. 60 give me a lot of room.
Ideally I would like to have another threshold for for
LongMethod
but I do not know if that's possible
This is a know limition of the current detekt. There is no way to have the same rule with two different confirgurations. We want to fix that for 2.0. As a workaround you can create a new rule copy&pasting the code in
LongMethod
and configure it as you wish
d

diego-gomez-olvera

12/29/2022, 1:51 PM
cool, I will review the current threshold and se how many
@Composable
exceed 60. If it's common to have legitimate occurrences, I will consider as you suggest and have a custom
LongMethod
for
@Composable
method. Thanks!
j

Jan Skrasek

12/31/2022, 7:29 AM
We face similar compose problem but rather with number of parameters. As it is more common to pass them destructed and not wrap to additional objects causing allocations and remember usage. So definitely split setup would be nice 👍
s

Sam Pengilly

01/04/2023, 5:48 AM
Method length is probably a good sign to refactor such a composable into one that accepts “slot” parameters. Separating the concern of layout from the concern of contents, lifting the concern of state up a level, and hopefully reducing the size of the composable functions as well as making them more general.
17 Views