Skip to content

Commit 38c25f9

Browse files
author
Paolo Tranquilli
committed
Rust: add linting pre-commit hook
1 parent 37afad2 commit 38c25f9

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,10 @@ repos:
7676
language: system
7777
entry: bazel run //rust/codegen -- --quiet
7878
pass_filenames: false
79+
80+
- id: rust-lint
81+
name: Run fmt and clippy on Rust code
82+
files: ^rust/extractor/(.*rs|Cargo.toml)$
83+
language: system
84+
entry: python3 rust/lint.py
85+
pass_filenames: false

rust/lint.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/env python3
2+
3+
import subprocess
4+
import pathlib
5+
import shutil
6+
import sys
7+
8+
extractor_dir = pathlib.Path(__file__).resolve().parent / "extractor"
9+
10+
cargo = shutil.which("cargo")
11+
assert cargo, "no cargo binary found on `PATH`"
12+
13+
fmt = subprocess.run([cargo, "fmt", "--quiet"], cwd=extractor_dir)
14+
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
15+
cwd=extractor_dir)
16+
sys.exit(fmt.returncode or clippy.returncode)

0 commit comments

Comments
 (0)