Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: IDEA: trigger ktfmt check on attempted commit #255

Closed
isXander opened this issue Nov 7, 2021 · 5 comments
Closed

Feature: IDEA: trigger ktfmt check on attempted commit #255

isXander opened this issue Nov 7, 2021 · 5 comments

Comments

@isXander
Copy link

isXander commented Nov 7, 2021

It would be cool if ktfmt executed a check when a user attempts to commit to VCS (maybe as a warning).

Or even better, runs the formatter itself when you attempt to commit.

I have countless times committed my code to then fail on CI because I forget to run ktfmt.

@ColtonIdle
Copy link

You can write a git precommit hook to just run ktfmt before you can even commit locally.

You could probably copy it fromt this ktlin gradle plugin repo: https://github.com/JLLeitschuh/ktlint-gradle#additional-helper-tasks

@cortinico
Copy link
Contributor

If you use ktfmt-gradle there is a section about using ktfmt as a pre-commit hook here:https://github.com/cortinico/ktfmt-gradle#using-with-a-pre-commit-hook-

@JavierSegoviaCordoba
Copy link
Contributor

If you are using the IDEA plugin it will reformat the code of all changed files if you have the checkbox selected.

@0x26res
Copy link

0x26res commented Feb 22, 2024

For pre-commit users, I've recently added support for ktfmt in the language-formatter-pre-commit-hooks. It doesn't require gradle, you just need python and java installed in your dev environment.

See the MR: macisamuele/language-formatters-pre-commit-hooks#196

Here's a sample .pre-commit-config.yaml

repos:
  - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
    rev: v2.12.0
    hooks:
      - id: pretty-format-kotlin
        files: "^.*.(kts|kt)$"
        name: ktfmt
        args: [--ktfmt, --ktfmt-style=google, --autofix]

Thanks @macisamuele for helping setting it up.

@hick209
Copy link
Contributor

hick209 commented Mar 26, 2024

Closing as this is a solved issue

@hick209 hick209 closed this as completed Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants