mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Rust: add linting pre-commit hook
This commit is contained in:
@@ -76,3 +76,10 @@ repos:
|
||||
language: system
|
||||
entry: bazel run //rust/codegen -- --quiet
|
||||
pass_filenames: false
|
||||
|
||||
- id: rust-lint
|
||||
name: Run fmt and clippy on Rust code
|
||||
files: ^rust/extractor/(.*rs|Cargo.toml)$
|
||||
language: system
|
||||
entry: python3 rust/lint.py
|
||||
pass_filenames: false
|
||||
|
||||
16
rust/lint.py
Executable file
16
rust/lint.py
Executable file
@@ -0,0 +1,16 @@
|
||||
#!/bin/env python3
|
||||
|
||||
import subprocess
|
||||
import pathlib
|
||||
import shutil
|
||||
import sys
|
||||
|
||||
extractor_dir = pathlib.Path(__file__).resolve().parent / "extractor"
|
||||
|
||||
cargo = shutil.which("cargo")
|
||||
assert cargo, "no cargo binary found on `PATH`"
|
||||
|
||||
fmt = subprocess.run([cargo, "fmt", "--quiet"], cwd=extractor_dir)
|
||||
clippy = subprocess.run([cargo, "clippy", "--fix", "--allow-dirty", "--allow-staged", "--quiet"],
|
||||
cwd=extractor_dir)
|
||||
sys.exit(fmt.returncode or clippy.returncode)
|
||||
Reference in New Issue
Block a user