jeremymailen / kotlinter-gradle

Painless, fast ktlint plugin for Gradle

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Integration with pre-commit(.com)

1Mark opened this issue · comments

commented

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

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?

commented

Works for me.

Any update on this pls?

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