Skip to content

Commit 58ad9e9

Browse files
committed
docs: clarify LinterStep
Fixes #60
1 parent 3c7065b commit 58ad9e9

5 files changed

Lines changed: 42 additions & 32 deletions

File tree

docs/configuration.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ Here's a basic `hk.pkl` file:
1414
amends "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/Config.pkl"
1515
import "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/builtins.pkl"
1616
17-
local linters = new {
17+
local linters = new Mapping<String, Step> {
1818
// linters can be manually defined
19-
["eslint"] {
19+
["eslint"] = new LinterStep {
2020
// the files to run the linter on, if no files are matched, the linter will be skipped
2121
// this will filter the staged files and return the subset matching these globs
2222
glob = List("*.js", "*.ts")
@@ -100,7 +100,7 @@ A command to run that modifies files. This typically is a "fix" command like `es
100100

101101
```pkl
102102
local linters = new Mapping<String, Step> {
103-
["prettier"] {
103+
["prettier"] = new LinterStep {
104104
fix = "prettier --write {{files}}"
105105
}
106106
}
@@ -122,7 +122,7 @@ If true, hk will run the linter on batches of files instead of all files at once
122122

123123
```pkl
124124
local linters = new Mapping<String, Step> {
125-
["eslint"] {
125+
["eslint"] = new LinterStep {
126126
batch = true
127127
}
128128
}
@@ -140,7 +140,7 @@ If set, run the linter on workspaces only which are parent directories containin
140140

141141
```pkl
142142
local linters = new Mapping<String, Step> {
143-
["cargo-clippy"] {
143+
["cargo-clippy"] = new LinterStep {
144144
workspace_indicator = "Cargo.toml"
145145
}
146146
}
@@ -152,7 +152,7 @@ If set, run the linter scripts with this prefix, e.g.: "mise exec --" or "npm ru
152152

153153
```pkl
154154
local linters = new Mapping<String, Step> {
155-
["eslint"] {
155+
["eslint"] = new LinterStep {
156156
prefix = "npm run"
157157
}
158158
}
@@ -199,8 +199,10 @@ A list of steps that must finish before this step can run.
199199
```pkl
200200
hooks {
201201
["pre-commit"] {
202-
["prettier"] {
203-
depends = List("eslint")
202+
steps = new Mapping<String, Step> {
203+
["prettier"] = new LinterStep {
204+
depends = List("eslint")
205+
}
204206
}
205207
}
206208
}
@@ -225,8 +227,10 @@ A list of steps that must finish before this step can run.
225227
```pkl
226228
hooks {
227229
["pre-commit"] {
228-
["prettier"] {
229-
depends = List("eslint")
230+
steps = new Mapping<String, Step> {
231+
["prettier"] = new LinterStep {
232+
depends = List("eslint")
233+
}
230234
}
231235
}
232236
}
@@ -239,8 +243,10 @@ A list of globs of files to add to the git index after running a fix step.
239243
```pkl
240244
hooks {
241245
["pre-commit"] {
242-
["prettier"] {
243-
stage = List("*.js", "*.ts")
246+
steps = new Mapping<String, Step> {
247+
["prettier"] {
248+
stage = List("*.js", "*.ts")
249+
}
244250
}
245251
}
246252
}
@@ -257,14 +263,16 @@ If true, this step will wait for any previous steps to finish before running. No
257263
```pkl
258264
hooks {
259265
["pre-commit"] {
260-
["prelint"] {
261-
exclusive = true // blocks other steps from starting until this one finishes
262-
run = "mise run prelint"
263-
}
264-
// ... other steps will run in parallel ...
265-
["postlint"] {
266-
exclusive = true // wait for all previous steps to finish before starting
267-
run = "mise run postlint"
266+
steps = new Mapping<String, Step> {
267+
["prelint"] {
268+
exclusive = true // blocks other steps from starting until this one finishes
269+
run = "mise run prelint"
270+
}
271+
// ... other steps will run in parallel ...
272+
["postlint"] {
273+
exclusive = true // wait for all previous steps to finish before starting
274+
run = "mise run postlint"
275+
}
268276
}
269277
}
270278
}

docs/getting_started.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/builtins.
5050
5151
local linters = new Mapping<String, Step> {
5252
// linters can be manually defined
53-
["eslint"] {
53+
["eslint"] = new LinterStep {
5454
// the files to run the linter on, if no files are matched, the linter will be skipped
5555
// this will filter the staged files and return the subset matching these globs
5656
glob = new { "*.js"; "*.ts" }
@@ -67,7 +67,9 @@ local linters = new Mapping<String, Step> {
6767
6868
hooks {
6969
["pre-commit"] {
70-
["fix"] = new Fix {}
70+
steps = new Mapping<String, Step> {
71+
["fix"] = new Fix {}
72+
}
7173
}
7274
}
7375
```

hk-example.pkl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
amends "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/Config.pkl"
22
import "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/builtins.pkl"
33

4-
local linters = {
4+
local linters = new Mapping<String, Step> {
55
// some linters are built into hk
6-
["actionlint"] = new actionlint.Actionlint {}
6+
["actionlint"] = builtins.actionlint
77
// linters can be manually defined
8-
["eslint"] {
8+
["eslint"] = new LinterStep {
99
// the files to run the hook on, if no files are matched, the hook will be skipped
1010
// this will filter the staged files and return the subset matching these globs
1111
glob = List("*.js", "*.ts")
@@ -25,19 +25,19 @@ local linters = {
2525
batch = true
2626
}
2727
// linters can start from a builtin linter and be customized
28-
["prettier"] = new prettier.Prettier {
28+
["prettier"] = (builtins.prettier) {
2929
// providing a "check_list_files" command will be used to help the "check_first" method work more efficiently
3030
// rather than running fix against all the files that were checked, it only runs fix against the files returned by this command
3131
check_list_files = "prettier --list-different {{files}}"
3232
}
33-
["clippy"] {
33+
["clippy"] = new LinterStep {
3434
// this linter works on directories instead of individual files.
3535
// This tells hk what filename to look for to know if a directory is a workspace.
3636
workspace_indicator = "Cargo.toml"
3737
check = "cargo clippy --manifest-path {{workspace_indicator}}"
3838
fix = "cargo clippy --manifest-path {{workspace_indicator}} --fix --allow-dirty --allow-staged"
3939
}
40-
["gomod_tidy"] {
40+
["gomod_tidy"] = new LinterStep {
4141
workspace_indicator = "go.mod"
4242
// assists "check_first" method because this will return a patch to stdout that hk can simply apply
4343
// without needing to actually run a "fix" step

hk.pkl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ amends "pkl/Config.pkl"
33
import "pkl/builtins.pkl"
44

55
// defines what happens during git pre-commit hook
6-
local linters = new Mapping<String, LinterStep> {
6+
local linters = new Mapping<String, Step> {
77
["actionlint"] = builtins.actionlint
88
// TODO: fails on releases with hk-example.pkl
99
//["pkl"] {
@@ -16,7 +16,7 @@ local linters = new Mapping<String, LinterStep> {
1616
check = "cargo clippy --manifest-path {{workspace_indicator}} -- -D warnings"
1717
}
1818
["cargo-fmt"] = builtins.cargo_fmt
19-
["dbg"] {
19+
["dbg"] = new LinterStep {
2020
// ensure no dbg! macros are used
2121
glob = List("**/*.rs")
2222
check = "sleep 1.5; ! rg -e 'dbg!' {{files}}"

src/cli/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ impl Init {
2323
amends "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/Config.pkl"
2424
import "package://github.com/jdx/hk/releases/download/v0.7.0/hk@0.7.0#/builtins.pkl"
2525
26-
local linters = new Mapping<String, LinterStep> {
26+
local linters = new Mapping<String, Step> {
2727
// uses builtin prettier linter config
2828
["prettier"] = builtins.prettier
2929
3030
// uses custom pkl linter config
31-
["pkl"] {
31+
["pkl"] = new LinterStep {
3232
glob = List("*.pkl")
3333
check = "pkl eval {{files}} >/dev/null"
3434
}

0 commit comments

Comments
 (0)