From efeba30c2edbbbc51ed0d67ea145a36d56194d1b Mon Sep 17 00:00:00 2001 From: Ahmed Din Date: Wed, 21 Oct 2026 16:19:39 +0500 Subject: [PATCH] feat(ci): add pre-commit hooks for rustfmt and eslint (#89) --- .pre-commit-config.yaml | 28 ++++++++++++++++++++++++++++ CHANGELOG.md | 2 ++ CONTRIBUTING.md | 4 ++++ Makefile | 6 ++++++ 4 files changed, 40 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..bf7d485 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.6.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files + + - repo: local + hooks: + - id: cargo-fmt + name: cargo fmt --check + description: Check Rust code formatting using cargo fmt + entry: cargo fmt --all --check + language: system + types: [rust] + pass_filenames: false + + - id: eslint + name: eslint (sdk) + description: Lint TypeScript SDK files using eslint + entry: npm --prefix sdk run lint + language: system + types: [typescript] + pass_filenames: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 097b5dc..22cc7fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Development: Added `.pre-commit-config.yaml` with `cargo fmt --check` and `eslint` hooks on staged files, plus `make hooks-install` target (#89). + - `rwa-asset`: holder count tracking (#146). `holder_count()` returns the number of addresses currently holding a strictly positive balance. The counter is incremented when a balance crosses 0 → >0 (first receive) and decremented when a balance hits exactly 0 (full burn or full send). `set_holder_cap(cap)` lets the admin set an optional ceiling on the holder count (Reg D style); any `mint`, `transfer`, `transfer_from` or `forced_transfer` that would add a new holder when the count already equals the cap is rejected with `ExceedsHolderCap` (error 25). `holder_count_cap()` returns the configured ceiling or `None`. The new `HolderCapSet` event is emitted by `set_holder_cap`, including when the cap is removed. A property test (`tests/test_holder_count.rs`) verifies the invariant `holder_count == count(addresses with balance > 0)` after every step in a 50-operation sequence of mints, burns, and transfers, both with and without an active cap. - `rwa-asset`: `set_governance`, `propose_cap_increase`/`approve_cap_increase`/`cancel_cap_increase` and `pending_cap_increase`. `update_metadata` still refuses to loosen a supply cap by itself (IR-02); raising one now requires the admin to propose a value and a separately configured `governance` address to approve it, mirroring `propose_admin`/`accept_admin`'s two-step shape. See [ADR-007](docs/architecture/007-governance-controlled-supply-cap.md) for why this is a second address rather than the `governance` contract itself (#148). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b902500..7f883b7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -89,6 +89,10 @@ make test # Set up SDK make sdk-install make sdk-test + +# Install pre-commit hooks (cargo fmt & eslint) +pip install pre-commit +make hooks-install ``` ### Running a single contract's tests diff --git a/Makefile b/Makefile index 12da6ce..13aadb8 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,11 @@ deploy-testnet: @echo "Ensure STELLAR_ACCOUNT env var is set to a funded testnet keypair." NETWORK=testnet ./scripts/deploy.sh +# ─── Tooling Hooks ──────────────────────────────────────────────────────────── +hooks-install: + @echo "Installing pre-commit hooks..." + pre-commit install + # ─── Help ───────────────────────────────────────────────────────────────────── help: @echo "" @@ -66,4 +71,5 @@ help: @echo " make sdk-build Build the TypeScript SDK" @echo " make sdk-test Run SDK unit tests" @echo " make deploy-testnet Deploy all four contracts to Stellar testnet" + @echo " make hooks-install Install local git pre-commit hooks" @echo ""