Closed tdurk93 closed 7 months ago
The easiest solution would be to add https://github.com/macisamuele/language-formatters-pre-commit-hooks as another repo to the kotlin-pre-commit.yaml
:
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
rev: v2.12.0
hooks:
- id: pretty-format-kotlin
args: [--autofix]
This could also be used for other language linting down the road.
Adding ktlint
as a plugin for detekt
doesn't seem to be a great option as we will also need to write some script to download the ktlint
jar if it is not installed. It seems that using both rather than using ktlint as. plugin is standard practice.
One other option that may be cleaner, as mentioned about is to "roll our own pre-commit hook" that can handle both ktlint
and detekt
like we did with https://github.com/slalombuild/pre-commit-mirror-checkstyle.
Updated from spike -> story and will used this card to submit PR and implement easy solution noted above.
In #363 we add a pre-commit hook for kotlin that provides static analysis/code quality scanning, but not linting.
It looks like there's another tool called ktlint that provides linting. I found a pre-commit hook for it, but it appears to not be maintained, and I don't love how it hard-codes the version number of
ktlint
to download.An alternative solution is to either roll our own pre-commit hook to add
ktlint
, or I found thatktlint
is supported as a plugin for detekt. We would just need to figure out how best to download the plugin as part of the hook execution and how to check for updates.This ticket is to figure out how best to implement linting support for Kotlin.