Skip to content

Commit 60f4461

Browse files
authored
feat: introduce lint.sh and pre-commit hooks for Rust and Python (#81)
* feat: introduce lint.sh and pre-commit hooks for Rust and Python * fix: hooks, README * makeuse: lint.sh in CI * remove: lint.sh redirect to /dev/null
1 parent d2c50f1 commit 60f4461

3 files changed

Lines changed: 37 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
branches: [main]
99

1010
jobs:
11-
fmt-clippy:
11+
lint:
1212
runs-on: ubuntu-latest
1313
timeout-minutes: 10
1414

@@ -20,11 +20,8 @@ jobs:
2020
with:
2121
components: rustfmt, clippy
2222

23-
- name: Check formatting
24-
run: cargo fmt --all -- --check
25-
26-
- name: Run clippy
27-
run: cargo clippy --all-targets --all-features -- -D warnings
23+
- name: Run lint checks
24+
run: FIX=0 ./scripts/lint.sh
2825

2926
cargo-test:
3027
runs-on: ubuntu-latest

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@ For GitHub Actions, add this step before running foc-devnet:
3131
- run: echo '127.0.0.1 host.docker.internal' | sudo tee -a /etc/hosts
3232
```
3333
34+
**Linting (rust + python)**:
35+
```sh
36+
sudo apt install pipx && pipx ensurepath && pipx install black
37+
./scripts/lint.sh # auto-fix mode (default)
38+
FIX=0 ./scripts/lint.sh # check-only mode (used in CI)
39+
```
40+
41+
**Pre-commit hook** (optional — runs `lint.sh` before each commit):
42+
```sh
43+
./scripts/install_precommit_hooks.sh
44+
```
45+
3446
### Step 1: Initialize
3547

3648
```bash

scripts/install_precommit_hooks.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
# install_precommit_hooks.sh — Optionally installs a pre-commit hook that runs lint.sh
3+
set -euo pipefail
4+
5+
cd "$(cd "$(dirname "$0")/.." && pwd)"
6+
7+
HOOK="$(git rev-parse --git-path hooks)/pre-commit"
8+
9+
mkdir -p "$(dirname "$HOOK")"
10+
11+
if [[ -e "$HOOK" && "${1:-}" != "-f" ]]; then
12+
echo "Hook already exists: $HOOK (use -f to overwrite)"
13+
exit 1
14+
fi
15+
16+
cat > "$HOOK" << 'EOF'
17+
#!/usr/bin/env bash
18+
exec "$(git rev-parse --show-toplevel)/scripts/lint.sh"
19+
EOF
20+
21+
chmod +x "$HOOK"
22+
echo "Installed: $HOOK"

0 commit comments

Comments
 (0)