https://kotlinlang.org logo
Title
c

Colton Idle

03/15/2020, 2:00 AM
Does anyone have any tips on getting consistency between code style for developers? It seems like IntelliJ codestyle is a little different between intellij/kotlin style, and then there's also https://developer.android.com/kotlin/style-guide. Seems like a lot of options, but I'm looking for something turnkey that works in static code analysis and works easily to import into intellij so the IDE formatting matches the actually analyzer. Not the biggest nitpicker on style, and using something out of the box from square or another trusted company would be cool. Curious to hear what everyone is using!
n

Nicholas Doglio

03/15/2020, 1:44 PM
I think ktlint is probably what you're looking for. https://github.com/pinterest/ktlint
c

Colton Idle

03/16/2020, 3:19 AM
Thanks. I'll be giving this a try.
v

voben

03/16/2020, 11:58 AM
Take a look it detekt. It also provides a wrapper around ktlint and comes with an IDE plugin so the styles are enforeced at code-time
c

Colton Idle

03/17/2020, 1:43 PM
Whoah. Now I'm definitely confused. It doesn't explicitly say that it's a wrapper around ktlint? Also, ktlint and detekt seem to provide the exact same things (linter + plugin/formatter). Any idea on what to use?
n

Nicholas Doglio

03/17/2020, 1:48 PM
ktlint to me seems more like a styler/formatter where as detekt is better for code smells and preventing silly mistakes. I use both for personal projects as part of the linting. You can use the ktlint command
./ktlint --android applyToIDEA
in Terminal to apply the style to your IDE and enforce it and also use detekt to lint against any code smells and easy mistakes. But here's where detekt mentions it also wraps over ktlint: https://github.com/arturbosch/detekt#adding-more-rule-sets
c

Colton Idle

03/17/2020, 1:50 PM
@Nicholas Doglio "I use both for personal projects as part of the linting." Both in the same project?
n

Nicholas Doglio

03/17/2020, 1:50 PM
Correct.
I think of ktlint as more of code formatter style guide and detekt as a way to prevent code smells, I don't really think they do the same thing
c

Colton Idle

03/17/2020, 1:53 PM
Cool. Appreciate your experience on these.
👍 1