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

Javier

12/02/2020, 11:31 AM
Has Detekt, in general or the intellij plugin, a strict mode which force the refactor like Dart/Flutter plugin has? For example, if I have a
data class
in a single line which ends with a trailing comma, using the detekt plugin to format it, the format keeps. But it should be changing to multiline (or at least delete the trailing comma, but with a strict mode I think it should be converted to multiline). Another example is can be:
Copy code
fun something() = "something"
fun something() = 
    "something"
The second one clearly should be reformated to the first one because it fits de space, but like both approach are valid, it doesn't get reformat I love a lot how the reformat works in Dart/Flutter because it forces A LOT how the code should look. Overall about spacing and playing with trailing comma to reformat from single line (or a "broken multiline") to multiline that looks good
j

Jon Michael Aanes

12/02/2020, 12:40 PM
IIRC detekt had some sort of autocorrect mode, but I think you might be more interested in ktlint? (https://github.com/pinterest/ktlint) It has a formatter at least.
j

Javier

12/02/2020, 1:15 PM
Detekt includes ktlint
And Detekt can be used to auto-format (via gradle command or with an IntelliJ Plugin + add a hotkey). Both, "native" IntelliJ autoformat + Detekt plugin autoformat, haven't the option to be more strict in the terms I mentioned before.
g

gammax

12/02/2020, 3:11 PM
Detekt’s auto-format feature is restricted to ktlint. So this issue should effectively be raised upon ktlint.
j

Javier

12/02/2020, 4:20 PM
I didn't know that Nicola, then Jon has reason too, thanks 😄
b

Brais Gabin

12/02/2020, 5:15 PM
And ktlint is not very restrictive. If you want your code formatted in a much more "predictable" way you should check ktfmt from Facebook. It's much more strict than ktlint. I never used, I like what ktlint does.
👍 1
j

Javier

12/02/2020, 5:46 PM
I will check it too, thank you 🙂
@Brais Gabin I tried ktfmt and I liked it. Is it planned to add it to Detekt as alternative to ktlint formatting?
g

gammax

12/24/2020, 3:46 PM
(For future reference, we’re talking about it in the #ktfmt channel)
j

Javier

12/24/2020, 4:04 PM
Yeah, I searched the channel after I did this question 😂
😅 1
b

Brais Gabin

12/24/2020, 7:54 PM
There is not plan to add ktfmt in detekt. I have no idea if they would be compatible. I think that ktfmt just rewrite the file instead of find specific issues. But, if it is compatible it would be a great third party plugin, I think.
For curiosity, how could detekt give more value to ktfmt? I mean, what are you missing from ktfmt that detekt could bring?
j

Javier

12/24/2020, 8:59 PM
What you said in this thread, ktfmt is more strict when it formats the code compared to ktlint
g

gammax

12/24/2020, 8:59 PM
But, if it is compatible it would be a great third party plugin, I think.
☝️ This should probably be the way to go. As far as I’ve seen when developing the ktfmt Gradle plugin, we could have a generic
InvalidFormatting
rule that wrap a ktfmt call for a single file.
28 Views