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

Tim Oltjenbruns

01/19/2022, 9:04 PM
Is there a way to customize the order that the ClassOrdering rule enforces? We use companion objects almost exclusively for factory methods, and we want those near the top of our classes next to the constructors. Checking for that order, or at least disabling the ordering rule specifically for companion objects, would be super helpful.
m

marschwar

01/19/2022, 10:04 PM
No, there is no such option. The
ClassOrdering
rule verifies that the class layout conforms to the conventions from https://kotlinlang.org/docs/coding-conventions.html#class-layout
t

Tim Oltjenbruns

01/19/2022, 10:09 PM
Yeah, I've seen the doc about that being conventional. We still want to break it, uniformly if possible. Or at least, not at the cost of losing consistency for the other member's order.
g

gammax

01/20/2022, 10:46 AM
I think you’ll have to make a custom rule that either subclass
ClassOrdering
or you just copy over the body (far from ideal I know).
👍 1
t

Tim Oltjenbruns

01/24/2022, 4:35 PM
Thanks Nicola, I was thinking that would be the road I could go down!
👍 1
11 Views