chore: run cargo fmt, doc, and dylint checks in husky pre-push (#12035)
The Rust workspace's pre-push checks were sitting in `pacquet/.githooks/pre-push` and only fired if a developer ran `just install-hooks`, which would also disable every husky-managed TypeScript hook by replacing `core.hooksPath`. Move the bash logic to `pacquet/scripts/pre-push-rust.sh`, invoke it from `.husky/pre-push` alongside the existing TS compile and lint checks, and drop the `install-hooks` recipe so nobody re-points `core.hooksPath` by mistake. The script now also runs `cargo doc --no-deps --workspace --all-features` (with `RUSTDOCFLAGS=-D warnings`) and `cargo dylint --all -- --all-targets --workspace` (with `RUSTFLAGS=-D warnings`), matching CI. `--workspace` covers both `pacquet/crates/*` and `registry/crates/*` since they share the root Cargo workspace.
This commit is contained in:
1 parent
7c9a6c29ea
commit
e375a58261
6 files changed
+58
-45
No files matched your search
+1
-1
@@ -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
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
+5
-3
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
Executable
+51
@@ -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
|
||||
Reference in new issue
Block a user