Skip to content

chore: add pre-commit hooks for code quality checks#3194

Merged
QuantumExplorer merged 4 commits intov3.1-devfrom
chore/pre-commit-hooks
Mar 6, 2026
Merged

chore: add pre-commit hooks for code quality checks#3194
QuantumExplorer merged 4 commits intov3.1-devfrom
chore/pre-commit-hooks

Conversation

@QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Mar 6, 2026

Issue being fixed or feature implemented

No pre-commit hooks exist in the platform repo, allowing formatting issues, invalid config files, and merge conflicts to slip into commits.

What was done?

Added .pre-commit-config.yaml with hooks modeled after the grovedb repo setup.

On commit (fast checks):

  • trailing-whitespace — trim trailing whitespace (excludes markdown)
  • check-yaml — validate YAML syntax
  • check-json — validate JSON syntax (excludes JSONC files like tsconfig, devcontainer)
  • check-toml — validate TOML syntax
  • check-merge-conflict — detect merge conflict markers
  • mixed-line-ending — enforce LF line endings
  • check-added-large-files — block files over 1MB
  • check-case-conflict — detect case-insensitive filename conflicts
  • cargo fmt — format Rust code

On push (slow checks):

  • cargo clippy — lint entire Rust workspace

Global exclusions for generated/autogenerated content:

  • Test vectors, supporting files, fixtures
  • Protobuf generated code (_pb.js, _pb_service.js, .pbrpc.h)
  • Lock files, minified JS/CSS, .yarn/, node_modules/, CHANGELOG.md

Setup

pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-push

How has this been tested?

Breaking changes

None. Pre-commit hooks are opt-in per developer.

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Added a pre-commit configuration enabling fast checks on commit and slower checks on push/manual — includes formatting, linting and secret-scanning hooks, plus exclusions to skip generated/build artifacts and common vendor paths.

@github-actions github-actions bot added this to the v3.1.0 milestone Mar 6, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Adds a new .pre-commit-config.yaml that defines fast commit-time hooks (formatting, whitespace, YAML/JSON/TOML checks, secret scanning, file-size/case checks, local Rust fmt) and slower push/manual hooks (workspace cargo clippy). Extensive exclude patterns skip generated, build, vendor, and test-vector paths.

Changes

Cohort / File(s) Summary
Pre-commit configuration
./.pre-commit-config.yaml
New pre-commit config introducing fast checks on commit (trailing-whitespace, check-yaml, check-json with exclusions, check-toml, check-merge-conflict, mixed-line-ending, check-added-large-files, check-case-conflict, gitleaks, local cargo-fmt) and slow checks on push/manual (local cargo-clippy). Adds a descriptive local cargo-fmt hook and many exclude patterns for target/, node_modules/, generated assets, test vectors, and other build outputs.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer (git)
    participant Pre as pre-commit
    participant Fast as Fast Hooks
    participant Slow as Slow Hooks
    participant Tools as Tools (gitleaks, cargo-fmt, check-* etc.)
    Dev->>Pre: git commit / git push
    Pre->>Fast: run commit-stage hooks
    Fast->>Tools: run formatting, lint, checks, secret scan
    Tools-->>Fast: results (pass/fail)
    alt commit successful
      Dev->>Pre: git push (or manual)
      Pre->>Slow: run push/manual hooks
      Slow->>Tools: run cargo-clippy (workspace)
      Tools-->>Slow: results (pass/fail)
    end
Loading

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 I hopped through hooks with a curious twitch,

Fixed spaces, secrets, and Rust code I stitched.
Commits now gleam, pushes keep pace —
A tidy repo, all hopped into place. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'chore: add pre-commit hooks for code quality checks' accurately summarizes the main change: adding a .pre-commit-config.yaml file with pre-commit and pre-push hooks. It is concise, specific, and clearly describes the primary modification in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore/pre-commit-hooks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
.pre-commit-config.yaml (2)

57-66: Consider adding -- -D warnings to fail on clippy warnings.

The clippy hook runs without treating warnings as errors. For a pre-push check, you may want stricter enforcement to catch issues before they reach CI.

♻️ Proposed enhancement for stricter clippy checks
       - id: clippy
         name: clippy (workspace)
         description: Run clippy on entire workspace
-        entry: cargo clippy --workspace
+        entry: cargo clippy --workspace -- -D warnings
         language: system
         types: [rust]
         pass_filenames: false
         stages: [pre-push, manual]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.pre-commit-config.yaml around lines 57 - 66, The clippy hook (id: clippy)
currently runs with entry "cargo clippy --workspace" and doesn't treat warnings
as errors; update the hook's entry to run clippy with strictness by appending
the cargo flag and rustc args (e.g., change the entry for the clippy hook to
include "-- -D warnings") so clippy warnings are treated as failures during
pre-push.

32-41: The node_modules/ exclusion is redundant with the global exclude pattern.

The global exclude pattern (lines 74–75) already excludes node_modules/ and .*/node_modules/, making the exclusion in the typos hook (lines 37–41) unnecessary. Remove it to keep the configuration DRY.

Additionally, consider whether --write-changes is the desired behavior. While convenient, this flag automatically modifies files when issues are found, which may be surprising for developers who prefer to review suggested changes first. Some teams prefer --diff to show changes without applying them.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.pre-commit-config.yaml around lines 32 - 41, Remove the redundant
node_modules/ exclusion from the typos hook block (repo:
https://github.com/crate-ci/typos, hook id: typos) so the hook relies on the
global exclude pattern instead of repeating .*node_modules/; also evaluate the
args for this hook (currently '--write-changes') and, if you prefer reviewers to
inspect edits before applying them, replace '--write-changes' with '--diff' (or
remove the flag) to avoid auto-applying fixes.
_typos.toml (1)

4-6: Consider expanding the comment or word list.

The comment mentions "Blockchain/crypto terms" but "datas" is a general non-standard pluralization (common in various technical contexts) rather than a blockchain-specific term. Consider either:

  • Updating the comment to be more general (e.g., "Technical terms that are not typos")
  • Adding actual blockchain/crypto terms that might trigger false positives (e.g., merkle, secp, ecdsa, keccak)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@_typos.toml` around lines 4 - 6, The comment above [default.extend-words]
says "Blockchain/crypto terms" but the only entry is "datas" (key: datas), which
is a general non-standard plural rather than a crypto-specific term; update the
comment to a more general description (e.g., "Technical terms that are not
typos") or replace/augment the list with real blockchain/crypto tokens (e.g.,
merkle, secp, ecdsa, keccak, gas, nonce) while keeping or moving "datas" as
needed under [default.extend-words].
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@_typos.toml`:
- Around line 4-6: The comment above [default.extend-words] says
"Blockchain/crypto terms" but the only entry is "datas" (key: datas), which is a
general non-standard plural rather than a crypto-specific term; update the
comment to a more general description (e.g., "Technical terms that are not
typos") or replace/augment the list with real blockchain/crypto tokens (e.g.,
merkle, secp, ecdsa, keccak, gas, nonce) while keeping or moving "datas" as
needed under [default.extend-words].

In @.pre-commit-config.yaml:
- Around line 57-66: The clippy hook (id: clippy) currently runs with entry
"cargo clippy --workspace" and doesn't treat warnings as errors; update the
hook's entry to run clippy with strictness by appending the cargo flag and rustc
args (e.g., change the entry for the clippy hook to include "-- -D warnings") so
clippy warnings are treated as failures during pre-push.
- Around line 32-41: Remove the redundant node_modules/ exclusion from the typos
hook block (repo: https://github.com/crate-ci/typos, hook id: typos) so the hook
relies on the global exclude pattern instead of repeating .*node_modules/; also
evaluate the args for this hook (currently '--write-changes') and, if you prefer
reviewers to inspect edits before applying them, replace '--write-changes' with
'--diff' (or remove the flag) to avoid auto-applying fixes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: af767f17-120f-44c2-ba79-e58982d62d82

📥 Commits

Reviewing files that changed from the base of the PR and between 95b0d5c and fcef7ea.

📒 Files selected for processing (2)
  • .pre-commit-config.yaml
  • _typos.toml

@QuantumExplorer QuantumExplorer requested a review from shumkov as a code owner March 6, 2026 06:53
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

✅ gRPC Query Coverage Report

================================================================================
gRPC Query Coverage Report - NEW QUERIES ONLY
================================================================================

Total queries in proto: 53
Previously known queries: 47
New queries found: 6

================================================================================

New Query Implementation Status:
--------------------------------------------------------------------------------
✓ getAddressInfo                                /home/runner/work/platform/platform/packages/rs-sdk/src/platform/query.rs
✓ getAddressesBranchState                       /home/runner/work/platform/platform/packages/rs-sdk/src/platform/address_sync/mod.rs
✓ getAddressesInfos                             /home/runner/work/platform/platform/packages/rs-sdk/src/platform/fetch_many.rs
✓ getAddressesTrunkState                        /home/runner/work/platform/platform/packages/rs-sdk/src/platform/query.rs
✓ getRecentAddressBalanceChanges                /home/runner/work/platform/platform/packages/rs-sdk/src/platform/query.rs
✓ getRecentCompactedAddressBalanceChanges       /home/runner/work/platform/platform/packages/rs-sdk/src/platform/query.rs

================================================================================
Summary:
--------------------------------------------------------------------------------
New queries implemented: 6 (100.0%)
New queries missing: 0 (0.0%)

Total known queries: 53
  - Implemented: 50
  - Not implemented: 2
  - Excluded: 1

Not implemented queries:
  - getConsensusParams
  - getTokenPreProgrammedDistributions

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

✅ DashSDKFFI.xcframework built for this PR.

SwiftPM (host the zip at a stable URL, then use):

.binaryTarget(
  name: "DashSDKFFI",
  url: "https://your.cdn.example/DashSDKFFI.xcframework.zip",
  checksum: "bdab166b0da2de1ce7c96a853ea79cc3d44a6f6023bb69d4b09c451594caa22c"
)

Xcode manual integration:

  • Download 'DashSDKFFI.xcframework' artifact from the run link above.
  • Drag it into your app target (Frameworks, Libraries & Embedded Content) and set Embed & Sign.
  • If using the Swift wrapper package, point its binaryTarget to the xcframework location or add the package and place the xcframework at the expected path.

QuantumExplorer and others added 2 commits March 6, 2026 16:49
Add pre-commit configuration modeled after grovedb's setup:

On commit (fast):
- Trailing whitespace, EOF fixer, YAML/JSON/TOML validation
- Merge conflict detection, line ending normalization
- Large file check (1MB limit), case conflict detection
- Typos spell checker with blockchain-aware config
- cargo fmt (Rust formatting)

On push (slow):
- cargo clippy (workspace-wide linting)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Typos were already fixed in a separate PR. Remove the typos hook
and its _typos.toml config to keep pre-commit checks lightweight.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Exclude test vectors, supporting files, protobuf generated code,
fixtures, lock files, and other autogenerated content from hooks.
Exclude JSONC files (tsconfig, devcontainer) from check-json.
Remove end-of-file-fixer (conflicts with cargo fmt on empty files)
and shebang checks (pre-existing issues to fix separately).
Add gitleaks hook for secret detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
lklimek
lklimek previously approved these changes Mar 6, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.pre-commit-config.yaml:
- Around line 56-63: Pre-commit's clippy hook (id: clippy, entry: cargo clippy
--workspace) is less strict than CI; update the hook entry to match CI by
running cargo clippy --workspace --all-features -D warnings so local runs fail
on warnings and lint feature-gated code too, leaving out --locked and --no-deps
as noted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 69cd0da1-0c3e-4d17-984c-feed251e93b8

📥 Commits

Reviewing files that changed from the base of the PR and between fcef7ea and 2d378cd.

📒 Files selected for processing (1)
  • .pre-commit-config.yaml

Comment on lines +56 to +63
- id: clippy
name: clippy (workspace)
description: Run clippy on entire workspace
entry: cargo clippy --workspace
language: system
types: [rust]
pass_filenames: false
stages: [pre-push, manual]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Clippy flags should match CI to prevent surprise failures.

The pre-commit clippy hook uses only cargo clippy --workspace, but CI runs with stricter flags including --all-features and -D warnings. This means code can pass the pre-commit hook but fail CI because:

  1. -D warnings is missing: warnings don't fail locally but are errors in CI
  2. --all-features is missing: feature-gated code isn't linted locally
🔧 Proposed fix to align with CI
       - id: clippy
         name: clippy (workspace)
         description: Run clippy on entire workspace
-        entry: cargo clippy --workspace
+        entry: cargo clippy --workspace --all-features -- -D warnings
         language: system
         types: [rust]
         pass_filenames: false
         stages: [pre-push, manual]

Note: --locked and --no-deps from CI are omitted intentionally—--locked can cause issues if Cargo.lock drifts locally, and --no-deps is the default behavior when not using -D warnings on dependencies.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.pre-commit-config.yaml around lines 56 - 63, Pre-commit's clippy hook (id:
clippy, entry: cargo clippy --workspace) is less strict than CI; update the hook
entry to match CI by running cargo clippy --workspace --all-features -D warnings
so local runs fail on warnings and lint feature-gated code too, leaving out
--locked and --no-deps as noted.

Add --all-features and -D warnings to clippy hook to match CI
configuration in tests-rs-package.yml.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@QuantumExplorer QuantumExplorer force-pushed the chore/pre-commit-hooks branch from ce80fac to 43dde2b Compare March 6, 2026 10:18
@QuantumExplorer QuantumExplorer merged commit f0554eb into v3.1-dev Mar 6, 2026
8 of 10 checks passed
@QuantumExplorer QuantumExplorer deleted the chore/pre-commit-hooks branch March 6, 2026 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants