diff --git a/.husky/pre-push b/.husky/pre-push index 8f85b36dca..5e49fe1908 100755 --- a/.husky/pre-push +++ b/.husky/pre-push @@ -1 +1 @@ -pnpm run compile-only && pnpm run lint --quiet +pnpm run compile-only && pnpm run lint --quiet && bash pacquet/scripts/pre-push-rust.sh diff --git a/justfile b/justfile index 8767399814..ef76dc590c 100644 --- a/justfile +++ b/justfile @@ -13,11 +13,6 @@ alias t := test # or install via `cargo install cargo-binstall` init: cargo binstall cargo-nextest cargo-watch cargo-insta typos-cli taplo-cli wasm-pack cargo-llvm-cov -y - just install-hooks - -# Point git at pacquet/.githooks/ so the tracked pre-push format check runs on `git push`. -install-hooks: - git config core.hooksPath pacquet/.githooks # When ready, run the same CI commands ready: diff --git a/pacquet/.githooks/pre-push b/pacquet/.githooks/pre-push deleted file mode 100755 index 710c8b6030..0000000000 --- a/pacquet/.githooks/pre-push +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env bash -# Catch formatter violations before they hit CI. -# Installed via `just install-hooks` (sets core.hooksPath to .githooks/). -set -euo pipefail - -red() { printf '\033[0;31m%s\033[0m\n' "$*" >&2; } -yellow() { printf '\033[0;33m%s\033[0m\n' "$*" >&2; } - -failed=0 - -if command -v cargo >/dev/null 2>&1; then - yellow '▸ cargo fmt --all -- --check' - if ! cargo fmt --all -- --check; then - red '✗ cargo fmt found unformatted Rust files — run `cargo fmt --all` (or `just fmt`) and commit.' - failed=1 - fi -else - yellow '! cargo not found on PATH — skipping Rust format check.' -fi - -if command -v taplo >/dev/null 2>&1; then - yellow '▸ taplo format --check' - if ! taplo format --check; then - red '✗ taplo found unformatted TOML — run `taplo format` (or `just fmt`) and commit.' - failed=1 - fi -else - yellow '! taplo not found on PATH — skipping TOML format check (install with `cargo binstall taplo-cli` or via `just init`).' -fi - -if [ "$failed" -ne 0 ]; then - red '' - red 'Push aborted. Bypass with `git push --no-verify` if you really need to.' - exit 1 -fi diff --git a/pacquet/AGENTS.md b/pacquet/AGENTS.md index 126fccc48d..25e906abcb 100644 --- a/pacquet/AGENTS.md +++ b/pacquet/AGENTS.md @@ -377,9 +377,11 @@ are part of the public contract, not implementation detail. See reformat unrelated code. - Reference the upstream pnpm commit/PR you ported from, when applicable. - Run `just ready` before pushing. -- The repo installs a pre-push hook via `just install-hooks` that runs - `rustfmt` and `taplo`. Make sure your environment can run cargo (the - hook needs it) before pushing. +- The repo-wide husky `pre-push` hook runs `pacquet/scripts/pre-push-rust.sh`, + which checks `rustfmt`, `taplo`, `cargo doc` (with + `RUSTDOCFLAGS=-D warnings`), and `cargo dylint`. Make sure your environment + can run cargo (the hook needs it) before pushing; `cargo-dylint` is + detected at runtime and skipped with a warning if not installed. ### Commit messages diff --git a/pacquet/CONTRIBUTING.md b/pacquet/CONTRIBUTING.md index afd76d574d..bb4594675e 100644 --- a/pacquet/CONTRIBUTING.md +++ b/pacquet/CONTRIBUTING.md @@ -80,7 +80,7 @@ Install the project's task tools and the git pre-push hook: just init ``` -`just init` invokes `cargo-binstall` to install `cargo-nextest`, `cargo-watch`, `cargo-insta`, `typos-cli`, `taplo-cli`, `wasm-pack`, and `cargo-llvm-cov`, then points `git` at the tracked `.githooks/` directory so the pre-push format check runs on `git push`. +`just init` invokes `cargo-binstall` to install `cargo-nextest`, `cargo-watch`, `cargo-insta`, `typos-cli`, `taplo-cli`, `wasm-pack`, and `cargo-llvm-cov`. The repo-wide `pnpm install` wires up husky, whose `pre-push` hook runs `pacquet/scripts/pre-push-rust.sh` (format, doc, dylint) alongside the TypeScript compile and lint checks. Install the test dependencies: diff --git a/pacquet/scripts/pre-push-rust.sh b/pacquet/scripts/pre-push-rust.sh new file mode 100755 index 0000000000..d2e699cde2 --- /dev/null +++ b/pacquet/scripts/pre-push-rust.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# Catch formatter, rustdoc, and dylint violations before they hit CI. +# Invoked from .husky/pre-push. +set -euo pipefail + +red() { printf '\033[0;31m%s\033[0m\n' "$*" >&2; } +yellow() { printf '\033[0;33m%s\033[0m\n' "$*" >&2; } + +failed=0 + +if command -v cargo >/dev/null 2>&1; then + yellow '▸ cargo fmt --all -- --check' + if ! cargo fmt --all -- --check; then + red '✗ cargo fmt found unformatted Rust files — run `cargo fmt --all` (or `just fmt`) and commit.' + failed=1 + fi + + yellow '▸ RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --workspace --all-features' + if ! RUSTDOCFLAGS='-D warnings' cargo doc --no-deps --workspace --all-features --quiet; then + red '✗ cargo doc reported warnings — fix the rustdoc diagnostics and commit.' + failed=1 + fi + + if command -v cargo-dylint >/dev/null 2>&1; then + yellow '▸ RUSTFLAGS="-D warnings" cargo dylint --all -- --all-targets --workspace' + if ! RUSTFLAGS='-D warnings' cargo dylint --all -- --all-targets --workspace; then + red '✗ cargo dylint reported lints — fix the findings (or `just dylint`) and commit.' + failed=1 + fi + else + yellow '! cargo-dylint not found on PATH — skipping dylint check (install with `cargo binstall cargo-dylint dylint-link`).' + fi +else + yellow '! cargo not found on PATH — skipping Rust format, doc, and dylint checks.' +fi + +if command -v taplo >/dev/null 2>&1; then + yellow '▸ taplo format --check' + if ! taplo format --check; then + red '✗ taplo found unformatted TOML — run `taplo format` (or `just fmt`) and commit.' + failed=1 + fi +else + yellow '! taplo not found on PATH — skipping TOML format check (install with `cargo binstall taplo-cli` or via `just init`).' +fi + +if [ "$failed" -ne 0 ]; then + red '' + red 'Push aborted. Bypass with `git push --no-verify` if you really need to.' + exit 1 +fi