https://kotlinlang.org logo
Title
m

Matt Groth

04/27/2023, 2:27 AM
Hi everyone, is there a rule that can detect errors like the following? Say I have a DSL that involves using unary plus operators on strings. Like:
createReport {
     + "Some text"
     + "Some more text"
     "More text" // this will not be included because the unary plus operator was accidentally left out
}
Note this code compiles without errors or warnings and there is no IDE warning. Yet, there is a bug because “More text” was not properly included. Is there any rule that can detect things like this, where the unary plus operator is accidentally forgotten?
a

Atul Gupta

05/09/2023, 9:00 PM
You can create an issue for new rule proposal in detekt github
m

Matt Groth

05/10/2023, 1:22 AM
Why detekt and not ktlint?
a

Atul Gupta

05/10/2023, 9:50 AM
From ktlint point of view this seems to be a fine code(if you consider only styling) but
detekt
checks covers code smell, potential bugs etc etc. But you can create an issue in
ktlint
as well
m

Matt Groth

05/10/2023, 2:19 PM
Ah I see, so ktlint is mainly for style bug detekt’s scope includes bugs and code smell as well? interesting
a

Atul Gupta

05/10/2023, 2:21 PM
Kind of true. Ktlint mostly focuses on issue which doesn't require semantics of code only dealing with the PSI structure while detekt has semantics information as well
But there are few rules in Ktlint as well which does more than styling
m

Matt Groth

05/10/2023, 2:21 PM
I see. Thank you for the context