Skip to content

feat(pre-commit): add husky pre-commit scan for staged files (issue#257)#411

Merged
mijinummi merged 1 commit into
MDTechLabs:mainfrom
dDevAhmed:feature/issue-257-husky-precommit
May 29, 2026
Merged

feat(pre-commit): add husky pre-commit scan for staged files (issue#257)#411
mijinummi merged 1 commit into
MDTechLabs:mainfrom
dDevAhmed:feature/issue-257-husky-precommit

Conversation

@dDevAhmed
Copy link
Copy Markdown
Contributor

Summary

  • Adds a committed Husky pre-commit hook that runs GasGuard scans on staged smart-contract files so issues are detected before commits.

What changed

  • Files added: pre-commit-scan.js — staged-file scanner that filters .sol, .vy, .rs and invokes the CLI for each file. See pre-commit-scan.js.
  • Files added: pre-commit — committed Husky hook that runs the staged-file scanner. See pre-commit.
  • Files modified: package.json — adds "prepare": "husky install" script and husky devDependency so hooks are installed on pnpm install. See package.json.

Why

  • Prevent gas/regression issues from being committed by scanning staged contract files at commit time.
  • Minimal, developer-local protection that does not change runtime behavior or CI policies.

Testing performed

  • Ran node scripts/pre-commit-scan.js locally; it exits cleanly when no staged scannable files exist.
  • Created branch feature/issue-257-husky-precommit, committed only the three relevant files and pushed the branch.
  • Suggested local test flow:
    • Install deps (sets up Husky):
      • pnpm install
    • Make executable (if required):
      • chmod +x .husky/pre-commit
    • Stage a scannable file and commit:
      • git add path/to/contract.sol
      • git commit -m "test pre-commit hook"

Risks considered

  • Hook invokes the TypeScript CLI via ts-node/register; dev dependencies must be installed for the hook to run. This is documented in the test steps.
  • Running one scan per staged file may be slower with many staged files. This is intentionally minimal; can be optimized to batch-scan if desired.

Edge cases handled

  • If there are no staged scannable files, the hook exits successfully and allows the commit.
  • If a scan fails for a staged file, the commit is blocked (exit code 1), preventing bad commits.

Remediation / follow-ups (optional)

  • Batch staged files into a single scanner invocation for performance.
  • Add a GitHub Action to run the same scan on pushes/PRs for server-side enforcement.
  • Replace ts-node invocation with a built gasguard binary for environments that prefer not to rely on devDependencies.

Branch

  • feature/issue-257-husky-precommit

Closes #257


@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 28, 2026

@dDevAhmed Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@mijinummi mijinummi merged commit 1cff5f0 into MDTechLabs:main May 29, 2026
2 of 6 checks passed
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.

🚀 Pre-Commit Hook Integration

2 participants