language-formatters-pre-commit-hooks icon indicating copy to clipboard operation
language-formatters-pre-commit-hooks copied to clipboard

Add support for ktfmt

Open 0x26res opened this issue 7 months ago • 1 comments

At the moment the pretty-format-kotlin hook uses ktlint.

ktfmt is another popular code formatter for koltin. It would be good if there was an extra hook in this repo (eg pretty-format-ktfmt) that would use ktfmt.

I had a look at the code for pretty-format-kotlin and it looks like it should be simple to implement a similar version for ktfmt. It's just a matter of calling java with a jar and the correct arguments: https://github.com/facebook/ktfmt#from-the-command-line

If that makes sense I can have a god at putting an PR together.

PS: so far the only way I found to run ktfmt with pre-commit is to use spotless, with either gradle-spotless or maven-spotless-apply. But these hooks require either maven or gradle installed. Whereas in theory we only need java (and to download and cache the correct jar).

0x26res avatar Nov 29 '23 13:11 0x26res