git-code-format-maven-plugin icon indicating copy to clipboard operation
git-code-format-maven-plugin copied to clipboard

Add support for .kt files using ktlint-core

Open mehiel opened this issue 4 years ago • 3 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 https://github.com/pinterest/ktlint/issues/645#issuecomment-628957189

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

mehiel avatar Dec 14 '20 22:12 mehiel

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 ^^

reda-alaoui avatar Dec 16 '20 20:12 reda-alaoui

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.

reda-alaoui avatar Dec 16 '20 20:12 reda-alaoui

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.

mehiel avatar Dec 16 '20 21:12 mehiel

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.

reda-alaoui avatar Dec 18 '22 14:12 reda-alaoui