Skip to content

Commit bc1bd67

Browse files
Merge pull request #1 from tuh8888/main
Add zprint and kaocha hooks
2 parents 0db75d9 + bdbd65b commit bc1bd67

File tree

7 files changed

+68
-4
lines changed

7 files changed

+68
-4
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
repos:
32
- repo: https://github.com/pre-commit/pre-commit-hooks
43
rev: v4.1.0

.pre-commit-hooks.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,19 @@
55
entry: hooks/clj-kondo-pre-commit
66
language: script
77
require_serial: true
8+
args: ["warning"]
9+
- id: zprint
10+
name: format with zprint
11+
description: Format files using zprint
12+
types: [clojure]
13+
entry: hooks/zprint-pre-commit
14+
language: script
15+
require_serial: false
16+
- id: kaocha
17+
name: run tests
18+
description: Run kaocha tests
19+
types: [clojure]
20+
entry: hooks/kaocha-pre-commit
21+
language: script
22+
pass_filenames: false
23+
require_serial: false

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Clojure hooks for pre-commit
22

3-
[Clojure](https://clojure.org/) package for [pre-commit](https://pre-commit.com) hooks. Integrates with popular packages such as [clj-kondo](https://github.com/clj-kondo/clj-kondo).
3+
[Clojure](https://clojure.org/) package for [pre-commit](https://pre-commit.com) hooks. Integrates with popular packages such as [clj-kondo (static linter)](https://github.com/clj-kondo/clj-kondo), [kaocha (unit testing)](https://github.com/lambdaisland/kaocha), and [zprint (file formatting)](https://github.com/kkinnear/zprint).
44

55
## Usage with pre-commit
66

@@ -9,6 +9,9 @@
99
rev: v1.x
1010
hooks:
1111
- id: clj-kondo
12+
- id: zprint
13+
- it: kaocha
14+
1215
```
1316
1417
## Passing arguments to clj-kondo
@@ -17,6 +20,13 @@
1720
- repo: https://github.com/vincentjames501/pre-commit-clojure
1821
rev: v1.x
1922
hooks:
23+
2024
- id: clj-kondo
21-
args: ['--fail-level']
25+
args: ['error']
26+
- id: zprint
27+
- id: kaocha
28+
# Must install pre-push: $ pre-commit install --hook-type pre-push
29+
# https://pre-commit.com/#pre-commit-during-push
30+
stages: [merge-commit, push, manual]
31+
always_run: true
2232
```

hooks.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,18 @@
55
entry: hooks/clj-kondo-pre-commit
66
language: script
77
require_serial: true
8+
- id: zprint
9+
name: format with zprint
10+
description: Format files using zprint
11+
types: [clojure]
12+
entry: hooks/zprint-pre-commit
13+
language: script
14+
require_serial: false
15+
- id: kaocha
16+
name: run tests
17+
description: Run kaocha tests
18+
types: [clojure]
19+
entry: hooks/kaocha-pre-commit
20+
language: script
21+
pass_filenames: false
22+
require_serial: false

hooks/clj-kondo-pre-commit

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ then
66
exit 2
77
fi
88

9-
if !(clj-kondo --lint $@)
9+
array=( $@ )
10+
len=${#array[@]}
11+
_level=${1}
12+
_files=${array[@]:1:$len}
13+
14+
if !(clj-kondo --fail-level $_level --lint $_files)
1015
then
1116
echo
1217
echo "Error: new clj-kondo errors found. Please fix them and retry the commit."

hooks/kaocha-pre-commit

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
clojure -X:deps prep && ./bin/kaocha

hooks/zprint-pre-commit

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
if ! command -v zprint &> /dev/null
4+
then
5+
echo "zprint could not be found. Please follow the installation instructions here https://github.com/kkinnear/zprint/blob/main/doc/using/files.md"
6+
exit 2
7+
fi
8+
9+
result=$(zprint -fw $@ 2>&1)
10+
11+
if [ -z "$result" ]; then
12+
exit 0;
13+
else
14+
echo $result
15+
exit 1;
16+
fi

0 commit comments

Comments
 (0)