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

Add optional git pre-commit hooks for cljfmt & clj-kondo #32

Merged

Conversation

cap10morgan
Copy link
Contributor

@cap10morgan cap10morgan commented Jan 16, 2024

This uses babashka tasks to run some pre-commit checks via git hooks, but only after you opt in by running bb run git-hooks install. Currently it runs cljfmt and clj-kondo and rejects the commit if either complain. In my testing this runs in tens of milliseconds so hopefully worth the added value to each commit.

Currently it only checks files that are staged, and crucially, it checks the staged version of those files in a separate tmp dir (every example of git hooks I saw online checked the working directory version of the staged files; which are often not the same!). If we find a need to have the other un-staged files in there too, I can add that. I wasn't sure if it made a difference or not.

It is currently depending on a fork of cljfmt because it didn't have a library fn to pass in paths to recursively check. I'm going to PR that upstream and see if I can get it or something similar into an official release.

This is all towards the goal of spending less time fixing bugs that sneak onto main and wasting time cleaning up conflicts that are merely due to inconsistent code formatting. We had been doing far too much of the latter, especially.

@cap10morgan cap10morgan requested a review from a team January 16, 2024 22:58
Copy link
Contributor Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.


### Git hooks

- Run `bb git-hooks install`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I'd need to do for this to work going forwards, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, or perhaps more properly bb run git-hooks install but this should work too.

Copy link
Contributor

@dpetran dpetran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@cap10morgan cap10morgan merged commit 98a2e36 into main Jan 18, 2024
7 checks passed
@cap10morgan cap10morgan deleted the 01-16-Add_optional_git_pre-commit_hooks_for_cljfmt_clj-kondo branch January 18, 2024 20:22
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

Successfully merging this pull request may close these issues.

2 participants