-
Notifications
You must be signed in to change notification settings - Fork 4
feat: introduce lint.sh and pre-commit hooks for Rust and Python #81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
ea00a5a
feat: introduce lint.sh and pre-commit hooks for Rust and Python
redpanda-f f4882f5
fix: hooks, README
redpanda-f 24b5da2
makeuse: lint.sh in CI
redpanda-f 61257e7
remove: lint.sh redirect to /dev/null
redpanda-f 96a2484
Merge branch 'main' into feat/redpanda/lint-and-precommit-hooks
redpanda-f File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
| # ───────────────────────────────────────────────────────────── | ||
| # install_precommit_hooks.sh — Install pre-commit hooks | ||
| # | ||
| # This script installs a pre-commit hook that runs lint.sh | ||
| # in check mode (FIX=0) before each commit. | ||
| # | ||
| # Usage: | ||
| # ./scripts/install_precommit_hooks.sh | ||
| # ───────────────────────────────────────────────────────────── | ||
| set -euo pipefail | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
|
|
||
| cd "$REPO_ROOT" | ||
|
|
||
| # Get the actual git hooks directory (works for both regular repos and worktrees) | ||
| GIT_HOOKS_DIR="$(git rev-parse --git-path hooks)" | ||
| PRE_COMMIT_HOOK="$GIT_HOOKS_DIR/pre-commit" | ||
|
|
||
| # Ensure hooks directory exists | ||
| mkdir -p "$GIT_HOOKS_DIR" | ||
|
|
||
| # Create the pre-commit hook | ||
| cat > "$PRE_COMMIT_HOOK" << 'EOF' | ||
|
redpanda-f marked this conversation as resolved.
Outdated
|
||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
|
|
||
| FIX="${FIX:-1}" | ||
| REPO_ROOT="$(git rev-parse --show-toplevel)" | ||
|
|
||
| $REPO_ROOT/scripts/lint.sh | ||
|
redpanda-f marked this conversation as resolved.
Outdated
redpanda-f marked this conversation as resolved.
Outdated
|
||
| EOF | ||
|
|
||
| # Make the hook executable | ||
| chmod +x "$PRE_COMMIT_HOOK" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this was already added per #89 and https://github.com/FilOzone/foc-devnet/pull/90/changes#diff-9c4ff682c15ba17afa3ac52ab49323f3077cf2b7148ffc419ad35b5e151d9272R37 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/usr/bin/env bash | ||
| # ───────────────────────────────────────────────────────────── | ||
| # lint.sh — Unified linting script for foc-devnet | ||
| # | ||
| # Runs linters and formatters for Rust and Python code. | ||
| # Designed to work both locally and in CI. | ||
| # | ||
| # Modes: | ||
| # FIX=1 (default) — Auto-fix issues where possible | ||
| # FIX=0 — Check only, fail on issues | ||
| # | ||
| # Usage: | ||
| # ./scripts/lint.sh # Fix mode | ||
| # FIX=0 ./scripts/lint.sh # Check mode (CI) | ||
| # | ||
| # Requirements: | ||
| # Rust: cargo, rustfmt, clippy | ||
| # Python: black, ruff (or pip install black ruff) | ||
|
redpanda-f marked this conversation as resolved.
Outdated
|
||
| # ───────────────────────────────────────────────────────────── | ||
| set -euo pipefail | ||
|
|
||
| FIX="${FIX:-1}" | ||
|
|
||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[0;33m' | ||
| BLUE='\033[0;34m' | ||
| NC='\033[0m' | ||
|
|
||
| FAIL=0 | ||
|
|
||
| pass() { printf "${GREEN}✓${NC} %s\n" "$1"; } | ||
| fail() { printf "${RED}✗${NC} %s\n" "$1"; FAIL=1; } | ||
| skip() { printf "${YELLOW}⊘${NC} %s (skipped — tool not found)\n" "$1"; } | ||
| fixed() { printf "${BLUE}⟳${NC} %s (auto-fixed)\n" "$1"; } | ||
| info() { printf "${BLUE}ℹ${NC} %s\n" "$1"; } | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||
|
|
||
| cd "$REPO_ROOT" | ||
|
|
||
| info "Checking Rust code..." | ||
|
|
||
| if command -v cargo &>/dev/null; then | ||
| # ── cargo fmt ── | ||
| if [[ "$FIX" == "1" ]]; then | ||
| if cargo fmt --all; then | ||
| fixed "cargo fmt" | ||
| else | ||
| fail "cargo fmt failed" | ||
| fi | ||
| else | ||
| if cargo fmt --all -- --check &>/dev/null; then | ||
| pass "cargo fmt" | ||
| else | ||
| fail "cargo fmt — run './scripts/lint.sh' or 'cargo fmt --all' to fix" | ||
| fi | ||
| fi | ||
|
|
||
| # ── cargo clippy ── | ||
| if cargo clippy --all-targets --all-features -- -D warnings &>/dev/null; then | ||
| pass "cargo clippy" | ||
| else | ||
| fail "cargo clippy — fix warnings before committing" | ||
| fi | ||
|
redpanda-f marked this conversation as resolved.
Outdated
|
||
| else | ||
| skip "cargo (Rust checks)" | ||
| fi | ||
|
|
||
| echo "" | ||
|
|
||
| info "Checking Python code in scenarios/..." | ||
|
|
||
| PYTHON_FILES=$(find scenarios -name '*.py' 2>/dev/null || true) | ||
|
|
||
| if [[ -z "$PYTHON_FILES" ]]; then | ||
| skip "Python files (none found in scenarios/)" | ||
| else | ||
| # ── black (formatter) ── | ||
| if command -v black &>/dev/null; then | ||
| if [[ "$FIX" == "1" ]]; then | ||
| if black scenarios/ &>/dev/null; then | ||
| fixed "black (Python formatter)" | ||
| else | ||
| fail "black failed" | ||
| fi | ||
| else | ||
| if black --check scenarios/ &>/dev/null; then | ||
| pass "black (Python formatter)" | ||
| else | ||
| fail "black — run './scripts/lint.sh' or 'black scenarios/' to fix" | ||
| fi | ||
| fi | ||
| else | ||
| skip "black (install with: pip install black)" | ||
| fi | ||
| fi | ||
|
|
||
| echo "" | ||
|
|
||
| echo "════════════════════════════════════════════════════════" | ||
| if [[ $FAIL -ne 0 ]]; then | ||
| printf "${RED}✗ Linting failed.${NC}\n" | ||
| if [[ "$FIX" == "0" ]]; then | ||
| echo " Run './scripts/lint.sh' (FIX=1 mode) to auto-fix issues." | ||
| fi | ||
| exit 1 | ||
| else | ||
| printf "${GREEN}✓ All linting checks passed.${NC}\n" | ||
| fi | ||
| echo "════════════════════════════════════════════════════════" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.