Skip to content

Commit a84adf7

Browse files
Remove brakeman from pre-commit and fail on changed files (#3465)
- Adding a custom check to ensure we do not initiate commit when running linters in fix mode - Removing brakeman as it runs on all files and takes too long as a pre-commit step
2 parents 54feba8 + d08b904 commit a84adf7

File tree

2 files changed

+51
-31
lines changed

2 files changed

+51
-31
lines changed

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ awscli 2.13.31
55
terraform 1.10.5
66
tflint 0.55.1
77
pkl 0.28.1
8-
hk 0.8.5
8+
hk 1.0.0

hk.pkl

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,69 @@
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"
33

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+
}
811

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+
}
1317

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+
}
1924

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+
}
2627

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()
3347
}
3448
}
3549

3650
hooks {
3751
["pre-commit"] {
3852
fix = true
3953
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+
}
4161
}
4262
["fix"] {
4363
fix = true
44-
steps = linters
64+
steps = linters["all"].steps
4565
}
4666
["check"] {
47-
steps = linters
67+
steps = linters["all"].steps
4868
}
4969
}

0 commit comments

Comments
 (0)