slalombuild / secureli

seCureLI is a tool that enables you to experience the delight of building products by helping you get ideas from your head into working software as frictionlessly as possible, in a reliable, secure, scalable, and observable way.
Apache License 2.0
28 stars 3 forks source link

Add linting support for Kotlin #392

Closed tdurk93 closed 7 months ago

tdurk93 commented 8 months ago

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 that ktlint 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.

isaac-heist-slalom commented 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.

isaac-heist-slalom commented 7 months ago

Updated from spike -> story and will used this card to submit PR and implement easy solution noted above.