-
Notifications
You must be signed in to change notification settings - Fork 3
/
Justfile
executable file
·131 lines (105 loc) · 3.28 KB
/
Justfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env -S just --justfile
# Useful resources:
# - Justfile syntax cheatsheet: https://cheatography.com/linux-china/cheat-sheets/justfile/
set windows-shell := ["powershell"]
set shell := ["bash", "-cu"]
alias b := build
alias c := check
alias ck := check
alias f := fmt
alias l := lint
alias r := run
alias t := test
alias w := watch
alias cov := coverage
_default:
@just --list -u
# Install necessary dev tools
init:
./tasks/init.sh
install:
cp zig-out/bin/zlint ~/.bin/zlint
# Run CI checks locally. Run this before making a PR.
ready:
git diff --name-only --exit-code
just fmt
zig build check
zig build
just docs
zig build test
zig build test-e2e
git status
# Build and run the linter
run *ARGS:
zig build run {{ARGS}}
# Build in debug mode
build *ARGS:
zig build --summary all {{ARGS}}
# Check for syntax and semantic errors
check:
zig build check
check-ast:
@for file in `git ls-files | grep '.zig$' | grep --invert-match 'fail'`; do zig ast-check "$file"; done
# Run a command in watch mode. Re-runs whenever a source file changes
watch cmd="check":
git ls-files | entr -rc just clear-run {{cmd}}
# Run unit tests
test:
zig build test --summary all
# Run end-to-end tests
e2e *ARGS:
zig build test-e2e {{ARGS}}
# Run and collect coverage for all tests
coverage:
zig build
mkdir -p ./.coverage
kcov --include-path=src,test ./.coverage/test zig-out/bin/test
kcov --include-path=src,test ./.coverage/test-e2e zig-out/bin/test-e2e
kcov --include-path=src,test ./.coverage/test-zlint zig-out/bin/zlint || true
kcov --merge ./.coverage/all ./.coverage/test ./.coverage/test-e2e ./.coverage/test-zlint
# Run benchmarks. Optionally specify a `--release` mode.
bench mode="safe":
@mkdir -p tmp
zig build --release={{mode}}
hyperfine --shell=none --warmup 2 --export-csv tmp/bench.csv 'zig-out/bin/zlint'
# Format the codebase, writing changes to disk
fmt:
zig fmt src test/harness build.zig build.zig.zon
typos -w
# Like `fmt`, but exits when problems are found without modifying files
lint:
zig fmt --check src test/harness build.zig build.zig.zon
typos
bunx oxlint@latest --format github -D correctness -D suspicious -D perf
docs:
zig build docs
# Remove build and test artifacts
clean:
rm -rf .zig-cache \
zig-out/bin zig-out/lib \
.coverage
# Generate boilerplate code for a new rule
new-rule name:
@if which bun > /dev/null; then \
bun tasks/new-rule.ts {{name}}; \
else \
echo "Please install bun to use this command."; \
fi
zig fmt src/linter
# Clear the screen, then run `zig build {{cmd}}`. Used by `just watch`.
clear-run cmd:
@clear
@zig build {{cmd}}
# temporary scripts for testing. Will be removed later
print-ast source filename="ast.json":
@mkdir -p tmp
rm -f ./tmp/{{filename}}
zig build run -Dsingle-threaded -- --print-ast {{source}} > ./tmp/{{filename}}
prettier --ignore-path=.prettierignore --write ./tmp/{{filename}}
# Clone or update submodules
submodules:
./tasks/submodules.sh
clone-submodule dir url sha:
cd {{dir}} || git init {{dir}}
cd {{dir}} && git remote add origin {{url}} || true
cd {{dir}} && git fetch --depth=1 origin {{sha}} && git reset --hard {{sha}}