kotlinter-gradle icon indicating copy to clipboard operation
kotlinter-gradle copied to clipboard

Integration with pre-commit(.com)

Open 1Mark opened this issue 2 years ago • 4 comments

Hi there,

I was trying to write a simple pre-commit-config.yaml like so

repos:
- repo: local
  hooks:
  - id: formatKotlin
    name: formatting files using kolinter
    entry: ./gradlew formatKotlin
    language: system

However, since pre-commit.com passes the changed files to ./gradlew formatKotlin it fails with

Task src/blah/file.kt not found in root project 'blahblah'.

I have seen #207 and #155 but I was still unsure how to resolve. I considered using https://github.com/macisamuele/language-formatters-pre-commit-hooks/blob/f5149294026e063cf1b9e28670e43ee5c624d2f9/.pre-commit-hooks.yaml#L25-L30 but was worried that klint would fall out of sync with kolinter.

Please advise

1Mark avatar May 31 '23 16:05 1Mark

Generally I think the ktlint cli tool is better suited to running git hooks since it's designed to target a list of files rather than sourceSets which are out of date to Gradle.

I understand some people have concerns that if they have both ktlint and the gradle plugin in their dev environment they will drift to different versions. Would it makes sense if kotlinter-gradle just packaged the CLI Main class within the plugin and people could write a JavaExec task to invoke it?

jeremymailen avatar Jun 04 '23 04:06 jeremymailen

Works for me.

1Mark avatar Jun 04 '23 06:06 1Mark

Any update on this pls?

1Mark avatar Sep 07 '23 13:09 1Mark

Not yet I'm afraid, but open to contributions.

jeremymailen avatar Sep 11 '23 05:09 jeremymailen