Hey idk if y'all are familiar with this static ana...
# ktlint
a
Hey idk if y'all are familiar with this static analysis plugin but I'm using it as a wrapper to run KtLint and detekt: https://github.com/novoda/gradle-static-analysis-plugin I noticed that when I use this Detekt outputs with a specific color for the error making it is easy to find in our logs but KtLint does not. Is there any flag or configuration I can set to do this? I mentioned that plugin because it might not be easy if I'm not calling KtLint directly.
a
Thanks! It looks like the gradle plugin I use for KtLint has that as `coloredOutput`: https://github.com/JLLeitschuh/ktlint-gradle/blob/master/plugin/src/main/kotlin/org/jlleitschuh/gradle/ktlint/BaseKtlintCheckTask.kt#L141 So I just had to do this:
Copy code
staticAnalysis {
    ktlint {
        // ...
        outputToConsole = true
        coloredOutput = true
    }
}
That should be true by default so I don't know why I'm not seeing it but I think I will have to take it up with that plugin. Thanks for getting me this far, though!
though will add such info to extension property description, as it could be misleading ๐Ÿ‘
a
They do have that somewhere one sec
er yes the link you sent is something I found.
Wouldn't I see that printed in the console though? Not sure where that info log goes to. I don't think the console type is plain, because Detekt is able to print its errors in colored output...
t
on info level it would be visible (you need to add
--info
to gradle run)
From https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_customizing_log_format:
Set to plain to generate plain text only. This option disables all color and other rich output in the console output. This is the default when Gradle is not attached to a terminal.
That is why colored output is disabled
a
Hmm even with
info
passed through, I don't see that error printed anywhere. I'm able to recreate on a separate project from work so I'm going to submit an issue to them and see if I learn anything. Will link it here when I do if you want to follow along.
t
actually I am a developer for this plugin, so submitting an issue would be enough ๐Ÿ™‚
a
oh ๐Ÿ˜‚
So sorry
t
no problem ๐Ÿ™‚
a
hmm you know what I think I'm at fault here. My sample project and my work project weren't configured correctly. One indeed was using a plain Reporter. I'm so sorry to have wasted your time lol
t
no problem, was happy to help ๐Ÿ‘
a
The other project is colored, but it's like a gray ish color and that makes it not noticeable to me, unlike Detekt which gives me more of a yellow output. I suppose that isn't customizable?
t
nope, coloring itself is done by ktlint
yellow output, I would say it should not be like this on plain console
a
Here's a detekt error in my console
This is how I get it from KtLint lol
t
I would say Detekt behaves wrong in this case
a
Why is that? The contrast is much better, so as I'm scrolling through logs it makes it very easy for me to find what I did wrong.
t
it is dark yellow color :)
This option disables all color and other rich output in the console output.
With
rich
console - showing colors are ok
a
Hmm I think I need to keep digging because then I'm not sure I have the right problem here after all. I'm guessing that this is working right, since Detekt and a few other things do print colors in this console. Perhaps it is just the color from KtLint that I don't like, and I never realized this darker gray was actually being colored.
t
try to run the build with
--console=rich
option and check ktlint coloring
a
yep it's the same
you could write your own reporter with nice coloring ๐Ÿ™‚
a
Yeah I'm gonna check to see if anyone else has complained about this in an issue and if not I may have to go that route. Sorry for all this I really did go down the wrong rabbit hole sorry to bring you with me hahaha
Thanks so much for your help! I still learned a lot of good things that will help me debug in the future. ๐Ÿ™‚
I've made a PR to support this! https://github.com/pinterest/ktlint/pull/585
๐Ÿ‘ 1