|
1 |
| -amends "package://github.com/jdx/hk/releases/download/v0.8.5/hk@0.8.5#/Config.pkl" |
2 |
| -import "package://github.com/jdx/hk/releases/download/v0.8.5/hk@0.8.5#/Builtins.pkl" |
| 1 | +amends "package://github.com/jdx/hk/releases/download/v1.0.0/hk@1.0.0#/Config.pkl" |
| 2 | +import "package://github.com/jdx/hk/releases/download/v1.0.0/hk@1.0.0#/Builtins.pkl" |
3 | 3 |
|
4 |
| -local linters = new Mapping<String, Step> { |
5 |
| - ["brakeman"] { |
6 |
| - check = "bin/brakeman --quiet --no-summary --no-pager" |
7 |
| - } |
| 4 | +local linters = new Mapping<String, Group> { |
| 5 | + ["all"] = new Group { |
| 6 | + steps = new Mapping<String, Step> { |
| 7 | + ["prettier"] = new Step { |
| 8 | + check = "bin/prettier --check --ignore-unknown {{ files }}" |
| 9 | + fix = "bin/prettier --write --list-different --ignore-unknown {{ files }}" |
| 10 | + } |
8 | 11 |
|
9 |
| - ["prettier"] { |
10 |
| - check = "bin/prettier --check --ignore-unknown {{ files }}" |
11 |
| - fix = "bin/prettier --write --list-different --ignore-unknown {{ files }}" |
12 |
| - } |
| 12 | + ["rubocop"] = new Step { |
| 13 | + glob = List("**/*.rb") |
| 14 | + check = "bin/rubocop {{ files }}" |
| 15 | + fix = "bin/rubocop --fix {{ files }}" |
| 16 | + } |
13 | 17 |
|
14 |
| - ["rubocop"] { |
15 |
| - glob = List("**/*.rb") |
16 |
| - check = "bin/rubocop {{ files }}" |
17 |
| - fix = "bin/rubocop --fix {{ files }}" |
18 |
| - } |
| 18 | + ["rufo"] = new Step { |
| 19 | + glob = List("**/*.erb") |
| 20 | + exclude = List("**/layouts/*") |
| 21 | + check = "bin/rufo --check {{ files }}" |
| 22 | + fix = "bin/rufo {{ files }}" |
| 23 | + } |
19 | 24 |
|
20 |
| - ["rufo"] { |
21 |
| - glob = List("**/*.erb") |
22 |
| - exclude = List("**/layouts/*") |
23 |
| - check = "bin/rufo --check {{ files }}" |
24 |
| - fix = "bin/rufo {{ files }}" |
25 |
| - } |
| 25 | + ["terraform"] = (Builtins.terraform) { |
| 26 | + } |
26 | 27 |
|
27 |
| - ["terraform"] = Builtins.terraform |
28 |
| - |
29 |
| - ["tf_lint"] { |
30 |
| - glob = List("**/*.tf") |
31 |
| - check = "tflint --chdir=terraform --recursive" |
32 |
| - fix = "tflint --chdir=terraform --recursive --fix" |
| 28 | + ["tf_lint"] = new Step { |
| 29 | + glob = List("**/*.tf") |
| 30 | + check = "tflint --chdir=terraform --recursive" |
| 31 | + fix = "tflint --chdir=terraform --recursive --fix" |
| 32 | + } |
| 33 | + ["brakeman"] = new Step { |
| 34 | + check = "bin/brakeman --quiet --no-summary --no-pager" |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + local steps_with_staged_fixes = (linters["all"].steps) { |
| 39 | + for (key, value in linters["all"].steps) { |
| 40 | + [key] = (value) { |
| 41 | + stage = List("*") |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + ["pre-commit"] = new Group { |
| 46 | + steps = steps_with_staged_fixes.toMap().remove("brakeman").toMapping() |
33 | 47 | }
|
34 | 48 | }
|
35 | 49 |
|
36 | 50 | hooks {
|
37 | 51 | ["pre-commit"] {
|
38 | 52 | fix = true
|
39 | 53 | stash = "patch-file"
|
40 |
| - steps = linters |
| 54 | + steps = new Mapping<String, Step | Group> { |
| 55 | + ["pre-commit"] = linters["pre-commit"] |
| 56 | + ["check_staged"] = new Step { |
| 57 | + check = "if git diff --staged --quiet; then echo 'No staged files aborting commit'; exit 1; fi" |
| 58 | + exclusive = true |
| 59 | + } |
| 60 | + } |
41 | 61 | }
|
42 | 62 | ["fix"] {
|
43 | 63 | fix = true
|
44 |
| - steps = linters |
| 64 | + steps = linters["all"].steps |
45 | 65 | }
|
46 | 66 | ["check"] {
|
47 |
| - steps = linters |
| 67 | + steps = linters["all"].steps |
48 | 68 | }
|
49 | 69 | }
|
0 commit comments