Gradle Inc seem to be recommending ktlint.
- @mikehearn - Does Corda use a code style tool for Kotlin?
- @yole - What code style tool are JetBrains using for Kotlin?
- @JakeWharton - Does Square Inc use a code style tool for Kotlin?
- @sdeleuze - Does Pivotal use a code style tool for Kotlin?
Would be interesting to know what code style tool Google are using for Kotlin.
Actually this question doesn’t make sense without clarifying what you need a static analysis tool for. Are you looking to avoid unnecessarily verbose code, enforce consistent code formatting, avoid security defects, check your code metrics, or what? All these tasks are solved with static analysis tools, and each of these tasks is handled by a different tool in the Java world.
At JetBrains, we don’t use any tools other than IntelliJ IDEA’s built-in inspections.
Really meant a code style tool. One where the user sets up some code style rules/guidelines, or uses the defaults which are applied to a Kotlin project. IntelliJ has a similar facility for Kotlin however it is very limited compared to the Java version.
Kotlin Code Style Settings
Java Code Style Settings
The difference in code style settings is intentional to a degree. We prefer to see Kotlin code using consistent coding styles (similar to how it happens in the Go community, or in Python with PEP8), and not to support infinite configuration possibilities.
If your using intellij as an IDE then maybe you want to check out the format.sh script inside the bin file which runs intellij headless and formats your code. Additionally you can run detekt to check if your methods are not too complex. (Note: I’m the maintainer of detekt.)
@napperley you might also want to take a look at Linting your Kotlin Builds - IntelliJ IDEA Inspections by Hadi Hariri from JetBrains team.
The 1.1.50+ IntelliJ IDEA plugin supports checking the Kotlin code style against the settings configured for the project.
Currently this is only an IDE feature, but there’s a work-in-progress Gradle plugin with the same functionality (not available yet).
Is that work-in-progress Gradle plugin released yet?