Skip to content

Conversation

@0xDEnYO
Copy link
Contributor

@0xDEnYO 0xDEnYO commented Dec 12, 2025

Why did I implement it this way?

Sometimes the pre-commit check was taking forever, especially on larger git diffs.
This PR introduces some optimizations and parallelizes tasks more efficiently which significantly reduces the runtime of the checks.

This is vibe-coded, please review carefully.

Checklist before requesting a review

Checklist for reviewer (DO NOT DEPLOY and contracts BEFORE CHECKING THIS!!!)

  • I have checked that any arbitrary calls to external contracts are validated and or restricted
  • I have checked that any privileged calls (i.e. storage modifications) are validated and or restricted
  • I have ensured that any new contracts have had AT A MINIMUM 1 preliminary audit conducted on by <company/auditor>

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 12, 2025

Walkthrough

Replaces the single-step pre-commit script with a parallel, file-type-aware pipeline and adds Husky helper files; minor comment/text edits in two scripts. Introduces conditional execution, unified wait-and-check for steps, aggregated secret checks, early exit when nothing is staged, and improved status reporting.

Changes

Cohort / File(s) Change Summary
Pre-commit pipeline
.<span></span>husky/pre-commit
Rewrote hook to detect staged file types (Solidity, TS/JS, TYPE), run conditional steps (forge, typechain, lint-staged, tsc, secret-check) in parallel, add early exit when no staged files, unified wait-and-check, structured/colorized status output, log filtering, temp artifact coordination, and cleanup
Husky runtime files
.<span></span>husky/_/.gitignore, .<span></span>husky/_/husky.sh
Added husky internal .gitignore and a portable husky.sh wrapper that selects shell, guards re-entry, sources optional ~/.huskyrc, runs hooks and preserves/propagates exit codes with diagnostic messages
Script text updates
script/deploy/healthCheck.ts, script/playgroundHelpers.sh
Non-functional edits: a comment added after ALLOW_LIST_NAMESPACE in healthCheck.ts; improved/help text and example placeholder in playgroundHelpers.sh (no behavior changes)

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • .husky/pre-commit: parallel orchestration, inter-process coordination, temp artifact usage, and exit-code aggregation
    • Secret-scan aggregation and exclusion rules (false-positive handling)
    • Correct detection/matching of staged file types and conditional branching
    • .<span></span>husky/_/husky.sh: shell selection and exit-code propagation behavior

Possibly related PRs

  • #1366 — Adjusts pre-commit forge invocation scope; closely related to the conditional/parallel forge step here.
  • #1343 — Earlier addition of forge/typechain/tsc and secret scanning to pre-commit; this PR extends and reorganizes that logic.
  • #1067 — Changes lint-staged/behavior when no staged files; overlaps with the early-exit and lint-staged adjustments in this rewrite.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main objective of the PR—improving pre-commit runtime performance through optimization and parallelization.
Description check ✅ Passed The description includes rationale, key implementation details, and addresses most required template sections, though some reviewer checklist items remain incomplete.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch improve-pre-commit-runtime

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

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.

@lifi-action-bot lifi-action-bot marked this pull request as draft December 12, 2025 03:07
@0xDEnYO 0xDEnYO marked this pull request as ready for review December 12, 2025 03:07
@0xDEnYO 0xDEnYO enabled auto-merge (squash) December 12, 2025 03:07
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: 0

🧹 Nitpick comments (3)
.husky/pre-commit (3)

228-231: Minor: Prefer printf over echo for null-delimited data.

echo may add a trailing newline that could affect xargs processing. Consider using printf '%s' for more predictable behavior with null-delimited strings.

-  FILES_TO_CHECK=$(git diff --cached --name-only --diff-filter=ACM -z)
-  FILES_COUNT=$(echo "$FILES_TO_CHECK" | tr '\0' '\n' | wc -l | tr -d ' ')
+  FILES_TO_CHECK=$(git diff --cached --name-only --diff-filter=ACM -z)
+  FILES_COUNT=$(printf '%s' "$FILES_TO_CHECK" | tr '\0' '\n' | grep -c . || echo 0)

Alternatively, pipe the git command directly:

FILES_COUNT=$(git diff --cached --name-only --diff-filter=ACM | wc -l | tr -d ' ')

252-255: Same printf consideration for xargs input.

For consistency with null-delimited data handling:

-  echo "$FILES_TO_CHECK" | xargs -0 -n 1 -P "$PARALLEL_JOBS" sh "$TEMP_SCRIPT" > "${SECRET_CHECK_OUTPUT}.results" 2>&1
+  printf '%s' "$FILES_TO_CHECK" | xargs -0 -n 1 -P "$PARALLEL_JOBS" sh "$TEMP_SCRIPT" > "${SECRET_CHECK_OUTPUT}.results" 2>&1

374-389: Potential duplicate warning output.

The subshell (lines 269-276) already prints warning messages to SECRET_CHECK_OUTPUT. Then lines 375-386 print additional messages based on the same patterns. For the private key case (exit code 0), this could result in duplicate warnings.

Consider removing the redundant message printing in the subshell since the main script handles output display:

-  elif echo "$SECRET_RESULT" | grep -q "Potential private key found"; then
-    printf '\033[36m%s\033[0m\n' "Warning: Potential Ethereum private keys found"
-    printf '\033[91m%s\033[0m\n' "Check each match carefully before pushing to GitHub"
-    EXIT_CODE=0  # Warning only
-  fi
+  fi

Or alternatively, in the main script, skip the secondary warning print since SECRET_RESULT already contains the formatted message.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5b6c862 and 66d8f14.

📒 Files selected for processing (1)
  • .husky/pre-commit (1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1256
File: deployments/zksync.diamond.json:81-87
Timestamp: 2025-07-04T08:59:08.108Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1334
File: deployments/mainnet.json:54-54
Timestamp: 2025-08-26T02:20:52.515Z
Learning: For deployment PRs in the lifinance/contracts repository, carefully verify the specific scope mentioned in the PR title and description before suggesting updates to other networks. Not all deployments are cross-network updates - some are targeted to specific chains only.
Learnt from: mirooon
Repo: lifinance/contracts PR: 1283
File: deployments/ronin.diamond.json:65-68
Timestamp: 2025-08-07T10:20:01.383Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) and deployment log files have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1343
File: .husky/pre-commit:1-3
Timestamp: 2025-08-29T05:16:40.067Z
Learning: In .husky/pre-commit, user 0xDEnYO prefers to keep the existing POSIX sh shebang (#!/usr/bin/env sh) even when the script uses bash-only features like arrays and [[ ]] syntax, prioritizing working code stability over strict shell compliance when the current implementation functions correctly in their environment.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1196
File: script/helperFunctions.sh:1447-1462
Timestamp: 2025-06-19T06:23:47.848Z
Learning: 0xDEnYO prefers to keep eval usage in local bash scripts when the security risk is acceptable in their controlled environment, prioritizing simplicity over security hardening for local tooling.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1266
File: script/deploy/safe/execute-pending-timelock-tx.ts:627-628
Timestamp: 2025-07-17T04:21:26.825Z
Learning: In the lifinance/contracts repository, 0xDEnYO prefers to keep '0x0' as a fallback address in gas estimation calls rather than throwing errors when the wallet account address is not available, prioritizing code simplicity over strict validation.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1325
File: script/tasks/diamondSyncDEXs.sh:116-116
Timestamp: 2025-08-27T08:45:59.606Z
Learning: In script/tasks/diamondSyncDEXs.sh, user 0xDEnYO has chosen to selectively apply ShellCheck fixes, keeping array assignments using $() construct and other patterns as-is in their controlled deployment environment, prioritizing functionality over strict ShellCheck compliance.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1212
File: .github/workflows/convertForkedPRsToInternal.yml:81-106
Timestamp: 2025-07-16T06:18:02.682Z
Learning: 0xDEnYO prefers to use printf "%q" for shell escaping in GitHub workflows to increase security and protection from potential injections, even when it might cause formatting issues, prioritizing security over convenience.
📚 Learning: 2025-08-07T10:20:01.383Z
Learnt from: mirooon
Repo: lifinance/contracts PR: 1283
File: deployments/ronin.diamond.json:65-68
Timestamp: 2025-08-07T10:20:01.383Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) and deployment log files have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.

Applied to files:

  • .husky/pre-commit
📚 Learning: 2025-07-04T08:59:08.108Z
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1256
File: deployments/zksync.diamond.json:81-87
Timestamp: 2025-07-04T08:59:08.108Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.

Applied to files:

  • .husky/pre-commit
📚 Learning: 2025-08-29T05:16:40.067Z
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1343
File: .husky/pre-commit:1-3
Timestamp: 2025-08-29T05:16:40.067Z
Learning: In .husky/pre-commit, user 0xDEnYO prefers to keep the existing POSIX sh shebang (#!/usr/bin/env sh) even when the script uses bash-only features like arrays and [[ ]] syntax, prioritizing working code stability over strict shell compliance when the current implementation functions correctly in their environment.

Applied to files:

  • .husky/pre-commit
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: run-unit-tests
  • GitHub Check: run-unit-tests
🔇 Additional comments (12)
.husky/pre-commit (12)

4-9: LGTM! Early exit optimization.

The early exit check when no files are staged is a good optimization that avoids unnecessary work.


11-18: File type detection looks correct.

The single-pass detection using grep -qE with short-circuit evaluation is efficient. Note that .jsx files are not included—this appears intentional if the project doesn't use JSX without TypeScript.


19-33: LGTM! Proper temp directory setup with cleanup.

The trap correctly handles cleanup on EXIT, INT, and TERM signals. The temp file paths are well-organized for parallel execution.


34-52: Good helper functions for readable output.

The colored status indicators (, , ) improve user experience. The print functions are well-structured.


54-80: Output filtering logic is sound.

The || true pattern correctly prevents grep from returning non-zero when no matches are found. The head -20 limit on tsc output (line 74) may truncate useful error context, but is reasonable for pre-commit brevity.


82-111: Robust wait-and-check mechanism.

The pattern of storing exit codes in files and reading them back is the correct approach for capturing exit status from backgrounded subshells. The fallback to echo "1" on read failure is a safe default.


150-152: Excellent race condition prevention.

Using git show ":$FILE" to read staged content instead of the working directory file is the correct approach—it prevents race conditions when lint-staged modifies files concurrently.


283-316: Well-structured parallel execution.

The pattern of running forge and lint-staged in parallel with proper cleanup on failure is correct. The subshell pattern (cmd; echo $? > file) & correctly captures exit codes for backgrounded processes.


318-332: LGTM! Correct sequential dependency.

TypeChain correctly runs after forge build completes, respecting the dependency that typechain needs compiled artifacts. The summary extraction provides good user feedback.


334-349: Verify: TypeScript-only changes skip type checking.

The condition on line 335 requires both TS/JS files AND Solidity files to be changed. This means commits with only TypeScript changes won't run tsc.

If this is intentional for performance (avoiding tsc when typechain types haven't changed), consider adding a comment explaining the rationale. Otherwise, you may want to run tsc whenever HAS_TS_JS_FILES = yes.

-if [ "$HAS_TS_JS_FILES" = "yes" ] && [ "$HAS_SOL_FILES" = "yes" ]; then
+# Only run tsc when Solidity files changed (typechain types may have changed)
+# TS-only changes rely on lint-staged for basic validation
+if [ "$HAS_TS_JS_FILES" = "yes" ] && [ "$HAS_SOL_FILES" = "yes" ]; then

351-358: LGTM! Proper lint-staged completion handling.

The wait occurs after other sequential tasks, allowing lint-staged to run in parallel for maximum efficiency while still ensuring it completes before the final status.


391-392: LGTM! Clean completion.

The final success message and exit 0 provide clear feedback that all checks passed.

@0xDEnYO 0xDEnYO added the WIP Work in progress label Dec 12, 2025
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: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 66d8f14 and 7975f70.

📒 Files selected for processing (5)
  • .husky/_/.gitignore (1 hunks)
  • .husky/_/husky.sh (1 hunks)
  • .husky/pre-commit (3 hunks)
  • script/deploy/healthCheck.ts (1 hunks)
  • script/playgroundHelpers.sh (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • script/deploy/healthCheck.ts
🧰 Additional context used
📓 Path-based instructions (1)
script/**/*.sh

📄 CodeRabbit inference engine (conventions.md)

script/**/*.sh: Bash scripts must begin with #!/bin/bash, use modular functions with clear sections (Logging, Error handling and logging, Deployment functions), follow DRY principle using helper files, use consistent indentation and naming, include proper comments and documentation
Bash scripts must use helper functions for logging (echoDebug, error, warning, success), validate inputs and environment early, check function exit status with checkFailure, use set -e where appropriate, and provide automated retry mechanisms for RPC issues

Files:

  • script/playgroundHelpers.sh
🧠 Learnings (6)
📓 Common learnings
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1256
File: deployments/zksync.diamond.json:81-87
Timestamp: 2025-07-04T08:59:08.108Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.
Learnt from: mirooon
Repo: lifinance/contracts PR: 1283
File: deployments/ronin.diamond.json:65-68
Timestamp: 2025-08-07T10:20:01.383Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) and deployment log files have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1334
File: deployments/mainnet.json:54-54
Timestamp: 2025-08-26T02:20:52.515Z
Learning: For deployment PRs in the lifinance/contracts repository, carefully verify the specific scope mentioned in the PR title and description before suggesting updates to other networks. Not all deployments are cross-network updates - some are targeted to specific chains only.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1343
File: .husky/pre-commit:1-3
Timestamp: 2025-08-29T05:16:40.067Z
Learning: In .husky/pre-commit, user 0xDEnYO prefers to keep the existing POSIX sh shebang (#!/usr/bin/env sh) even when the script uses bash-only features like arrays and [[ ]] syntax, prioritizing working code stability over strict shell compliance when the current implementation functions correctly in their environment.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1196
File: script/helperFunctions.sh:1447-1462
Timestamp: 2025-06-19T06:23:47.848Z
Learning: 0xDEnYO prefers to keep eval usage in local bash scripts when the security risk is acceptable in their controlled environment, prioritizing simplicity over security hardening for local tooling.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1266
File: script/deploy/safe/execute-pending-timelock-tx.ts:627-628
Timestamp: 2025-07-17T04:21:26.825Z
Learning: In the lifinance/contracts repository, 0xDEnYO prefers to keep '0x0' as a fallback address in gas estimation calls rather than throwing errors when the wallet account address is not available, prioritizing code simplicity over strict validation.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1325
File: script/tasks/diamondSyncDEXs.sh:116-116
Timestamp: 2025-08-27T08:45:59.606Z
Learning: In script/tasks/diamondSyncDEXs.sh, user 0xDEnYO has chosen to selectively apply ShellCheck fixes, keeping array assignments using $() construct and other patterns as-is in their controlled deployment environment, prioritizing functionality over strict ShellCheck compliance.
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1212
File: .github/workflows/convertForkedPRsToInternal.yml:81-106
Timestamp: 2025-07-16T06:18:02.682Z
Learning: 0xDEnYO prefers to use printf "%q" for shell escaping in GitHub workflows to increase security and protection from potential injections, even when it might cause formatting issues, prioritizing security over convenience.
📚 Learning: 2025-08-29T05:16:40.067Z
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1343
File: .husky/pre-commit:1-3
Timestamp: 2025-08-29T05:16:40.067Z
Learning: In .husky/pre-commit, user 0xDEnYO prefers to keep the existing POSIX sh shebang (#!/usr/bin/env sh) even when the script uses bash-only features like arrays and [[ ]] syntax, prioritizing working code stability over strict shell compliance when the current implementation functions correctly in their environment.

Applied to files:

  • .husky/_/husky.sh
  • .husky/_/.gitignore
  • .husky/pre-commit
📚 Learning: 2025-07-04T08:59:08.108Z
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 1256
File: deployments/zksync.diamond.json:81-87
Timestamp: 2025-07-04T08:59:08.108Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.

Applied to files:

  • script/playgroundHelpers.sh
  • .husky/pre-commit
📚 Learning: 2025-08-07T10:20:01.383Z
Learnt from: mirooon
Repo: lifinance/contracts PR: 1283
File: deployments/ronin.diamond.json:65-68
Timestamp: 2025-08-07T10:20:01.383Z
Learning: When analyzing deployment PRs in the lifinance/contracts repository, carefully verify that target state configuration files (like script/deploy/_targetState.json) and deployment log files have been updated before flagging missing entries. The AI summary section should be consulted to understand all file changes, as manual searches might miss entries due to formatting differences or search limitations.

Applied to files:

  • script/playgroundHelpers.sh
  • .husky/pre-commit
📚 Learning: 2024-11-26T01:18:52.125Z
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 782
File: script/deploy/deploySingleContract.sh:231-231
Timestamp: 2024-11-26T01:18:52.125Z
Learning: In the `deploySingleContract.sh` script, environment variable assignments preceding the `forge script` command (e.g., `DEPLOYSALT=$DEPLOYSALT ... forge script ...`) are acceptable and function correctly, even when variable expansions like `$DIAMOND_TYPE` and `$NETWORK` are used later in the same command.

Applied to files:

  • .husky/pre-commit
📚 Learning: 2024-12-05T03:41:16.360Z
Learnt from: 0xDEnYO
Repo: lifinance/contracts PR: 894
File: .github/workflows/diamondEmergencyPause.yml:68-68
Timestamp: 2024-12-05T03:41:16.360Z
Learning: Before reporting missing GitHub secrets in the lifinance/contracts repository, conclusively verify that the secret is absent to avoid false alerts.

Applied to files:

  • .husky/pre-commit
🧬 Code graph analysis (1)
script/playgroundHelpers.sh (1)
script/helperFunctions.sh (1)
  • error (3117-3119)
🪛 Shellcheck (0.11.0)
.husky/_/husky.sh

[warning] 9-9: Declare and assign separately to avoid masking return values.

(SC2155)


[warning] 19-19: ShellCheck can't follow non-constant source. Use a directive to specify location.

(SC1090)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: run-unit-tests
🔇 Additional comments (6)
.husky/_/.gitignore (1)

1-3: Good Husky hygiene: ignore everything except the wrapper.
Keeps only husky.sh (and this .gitignore) tracked, avoiding accidental commits of generated/temporary Husky files.

script/playgroundHelpers.sh (1)

720-736: Safer docs: placeholder examples instead of real tx hash / RPC.
This is purely messaging and reduces accidental reuse/leaking of real values.

.husky/pre-commit (3)

1-14: Shebang change to bash is fine, but please verify Husky executes it as bash everywhere.
This hook now relies on bash features (arrays, [[ ... ]], process substitution). Based on prior learnings about preferring #!/usr/bin/env sh in this repo, double-check this doesn’t break anyone’s local hook execution path.


61-295: Secret-check approach looks solid (staged-content scan + .env key-only reporting).
Scanning staged blobs via git show ":$FILE" avoids false negatives from unstaged working tree changes, and the output doesn’t echo secret values.

Also applies to: 371-399


15-22: The lint-staged and tsc configurations are correct; no coverage regression exists.

  • Lint-staged runs on commits with any lintable files (.sol or .(ts|js)), not just when both types change. The HAS_TYPE_FILES gate is inclusive, not restrictive.
  • tsc-files is already part of the lint-staged config for *.{ts,js} files, so TS-only commits receive type checking via lint-staged.
  • JSON/MD/YAML files are not configured in lint-staged, so commits affecting only those file types skipping lint-staged is expected, not a regression.
  • The separate tsc invocation (lines 347–362) only runs when Solidity files also changed; this is redundant with lint-staged's tsc-files but not a gap.
.husky/_/husky.sh (1)

1-37: No issues found. The code works correctly across environments, and both basename -- and string-based exit code comparisons function as intended. Since this file is part of the Husky framework and is already working in the repository's current setup, stylistic portability improvements are not necessary.

Comment on lines +5 to 22
# Early exit: Check if there are any staged files
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
if [ -z "$STAGED_FILES" ]; then
echo "No files staged for commit. Skipping pre-commit checks."
exit 0
fi

echo "TypeChain generation completed successfully!"
echo ""
GIT_ROOT=$(git rev-parse --show-toplevel)
cd "$GIT_ROOT" || exit 1

# Run TypeScript compilation to catch any type errors from outdated typings
echo "Running TypeScript compilation to check for type errors..."
bunx tsc-files --noEmit
# Determine what types of files changed for conditional execution (optimized single pass)
HAS_SOL_FILES="no"
HAS_TS_JS_FILES="no"
HAS_TYPE_FILES="no"

if [ $? -ne 0 ]; then
printf '\n%s\n' "TypeScript compilation failed. This may indicate outdated TypeChain types."
printf '%s\n\n' "Please run 'bun typechain' manually and fix any type errors before committing."
exit 1
fi
echo "$STAGED_FILES" | grep -qE '\.sol$' && HAS_SOL_FILES="yes" && HAS_TYPE_FILES="yes"
echo "$STAGED_FILES" | grep -qE '\.(ts|js|tsx)$' && HAS_TS_JS_FILES="yes" && HAS_TYPE_FILES="yes"

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 | 🟡 Minor

diff-filter=ACM skips renames; consider including R.
Renamed files can still carry secrets / need formatting; they’ll be missed by both the early staged list and secret scanning.

-STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
+STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR)

And likewise in run_secret_checks:

-  done < <(git diff --cached --name-only --diff-filter=ACM -z)
+  done < <(git diff --cached --name-only --diff-filter=ACMR -z)

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In .husky/pre-commit around lines 5 to 22 the staged-files command uses git diff
--cached --name-only --diff-filter=ACM which omits renamed files; update the
diff-filter to include R (e.g., ACMR) so renamed files are returned and scanned,
and apply the same change inside run_secret_checks where git lists staged files
so renames are not skipped by secret scans or formatting checks.

Comment on lines +23 to 35
# Create temp directory for parallel execution
TEMP_DIR=$(mktemp -d)
trap "rm -rf '$TEMP_DIR' 2>/dev/null" EXIT INT TERM

echo ""
echo "Running 'bun lint-staged' now:"
bun lint-staged

echo ""
echo ""
echo "now checking for .env secrets and private keys accidentally being committed to Github"
echo " > any 64-byte hex string will be identified as potential private key"
echo " > disable false positive matches by commenting '[pre-commit-checker: not a secret]' in same line or line above"
echo " > execution might take a while depending on the size of your git diff "
echo " > logs will only be shown once task is completed"
echo ""
FORGE_OUTPUT="$TEMP_DIR/forge.out"
FORGE_EXIT="$TEMP_DIR/forge.exit"
TYPECHAIN_OUTPUT="$TEMP_DIR/typechain.out"
TYPECHAIN_EXIT="$TEMP_DIR/typechain.exit"
TSC_OUTPUT="$TEMP_DIR/tsc.out"
TSC_EXIT="$TEMP_DIR/tsc.exit"
LINT_STAGED_OUTPUT="$TEMP_DIR/lint-staged.out"
LINT_STAGED_EXIT="$TEMP_DIR/lint-staged.exit"

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

mktemp -d is not portable on macOS; add fallback.
This is a common “works on Linux, fails on mac” footgun for local hooks.

-TEMP_DIR=$(mktemp -d)
+TEMP_DIR="$(mktemp -d 2>/dev/null || mktemp -d -t husky-precommit)"
🤖 Prompt for AI Agents
.husky/pre-commit around lines 23 to 35: the script uses mktemp -d which fails
on macOS; modify the TEMP_DIR creation to try the portable form and fall back
for macOS: attempt TEMP_DIR=$(mktemp -d 2>/dev/null) and if that fails, use
TEMP_DIR=$(mktemp -d -t precommit) (or create a fallback with mkdir and a random
suffix), keep the existing trap cleanup, and ensure all subsequent TEMP_DIR
usages remain unchanged.

printAdvise "abort"
echo ""
# TypeScript compilation check (only if both TS/JS files changed AND typechain was regenerated)
if [ "$HAS_TS_JS_FILES" = "yes" ] && [ "$HAS_SOL_FILES" = "yes" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

I think here we don't have to have condition [ "$HAS_SOL_FILES" = "yes" ] as we only need to run tsc files on ts/js files

exit 0
}
print_status "info" "Checking for secrets and private keys..."
run_secret_checks
Copy link
Contributor

Choose a reason for hiding this comment

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

I would run it before all heavy work


# process all files in git diff and search for secrets
local RESULT=$(processGitDiff)
if [ "$HAS_TYPE_FILES" = "yes" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

I’m not sure we gain much from this and it adds extra complexity. lint-staged is already scoped in package.json to the file extensions it should scan. If we introduce new linting rules for additional extensions, we’d have to remember to update both package.json and the pre-commit script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AuditNotRequired WIP Work in progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants