Cosium/git-code-format-maven-plugin

Add support for .kt files using ktlint-core

mehiel opened this issue · 4 comments

I'm interested to write a KtlintCodeFormatter capable to handle kotlin .kt files (maybe .kts as well). An example of a ktlint code formatter using the ktlint-core API can be seen here pinterest/ktlint#645 (comment)

Would this be of interest? Is there any initial though that I should also consider?

Hi @mehiel,
When writing this plugin I tried to make sure adding an alternative formatter was possible.
Even if I never used Kotlin, your contribution would be welcome !
But, since I am not a Kotlin user, your contribution would need to be written in java ^^

An alternative would be to extract a formatter SPI project that you would implement. This implementation would be activable via a maven configuration.
I think it is the best way to do it.
Among modularity and flexibility advantage, this would allow you to use any jvm langage for your implementation.

Hi @reda-alaoui,

yes I saw the code structure before putting that comment. The Formatter interface is enough for me at the moment.

I actually already have the initial implementation in place. It is in Java indeed as the rest of the project but I find the externalized SPI idea pretty interesting as well.

I'm trying to find some time to create sample "bad" Kotlin files on the test projects and make sure everything works as expected and all tests pass.

Then I'll open the PR and we can discuss more about it there. Hopefully, by the end of the week.

Hi @mehiel ,

Since version 4, you can easily plug your own code formatter.

You can either create the code formatter in a project of your own or open a pull request to add a module in this project.

I am closing this issue for now.