Files
aitbc/docs/development/PRE_COMMIT_HOOKS.md
aitbc b77a6ce007
Some checks failed
API Endpoint Tests / test-api-endpoints (push) Successful in 16s
CLI Tests / test-cli (push) Failing after 3s
Documentation Validation / validate-docs (push) Failing after 10s
Documentation Validation / validate-policies-strict (push) Failing after 3s
Integration Tests / test-service-integration (push) Successful in 3m0s
Python Tests / test-python (push) Successful in 17s
Security Scanning / security-scan (push) Failing after 23s
Blockchain Synchronization Verification / sync-verification (push) Failing after 10s
Node Failover Simulation / failover-test (push) Failing after 5s
P2P Network Verification / p2p-verification (push) Successful in 5s
Multi-Node Blockchain Health Monitoring / health-check (push) Successful in 5s
Systemd Sync / sync-systemd (push) Failing after 14m56s
ci: add daily failover simulation schedule and standardize service configurations
Add daily 2 AM cron schedule for node failover simulation workflow. Relax AITBC address validation to support variable-length addresses. Add missing logging import to chain_sync. Make coordinator database initialization non-fatal to allow startup even if init_db fails. Replace Ethereum address validation with AITBC-specific format checks in multisig transactions. Standardize PYTHONPATH across all systemd services to include
2026-04-27 16:51:13 +02:00

2.4 KiB

Pre-Commit Hooks

This project uses pre-commit hooks to ensure code quality and consistency before commits.

Installation

# Install pre-commit (if not already installed)
pip install pre-commit

# Install the hooks
pre-commit install

# Install pre-commit hooks for all files (optional)
pre-commit install --hook-type pre-push

Usage

Running hooks manually

# Run on all files
pre-commit run --all-files

# Run on staged files only (what happens during commit)
pre-commit run

# Run specific hooks
pre-commit run black flake8 mypy

Automatic execution

Hooks run automatically on git commit for staged files. If a hook fails, the commit will be blocked. Fix the issues and try again.

To bypass hooks (not recommended):

git commit --no-verify

Available Hooks

Python

  • black: Code formatting
  • flake8: Linting (max line length: 120)
  • mypy: Type checking
  • bandit: Security scanning

General

  • trailing-whitespace: Remove trailing whitespace
  • end-of-file-fixer: Ensure newline at end of file
  • check-yaml: Validate YAML syntax
  • check-toml: Validate TOML syntax
  • check-json: Validate JSON syntax
  • check-added-large-files: Prevent large files (>1MB)
  • detect-private-key: Detect private keys in code
  • mixed-line-ending: Ensure consistent line endings (LF)

Configuration Files

  • yamllint: YAML linting with custom config
  • markdownlint: Markdown linting (excludes docs/archive)

JavaScript/TypeScript

  • eslint: JavaScript/TypeScript linting for packages/js and cli

Shell Scripts

  • shellcheck: Shell script linting

Configuration

  • .pre-commit-config.yaml: Main pre-commit configuration
  • .yamllint.yaml: YAML linting rules

Updating Hooks

# Update hook versions
pre-commit autoupdate

# Review changes
git diff .pre-commit-config.yaml

Exclusions

Hooks exclude common directories:

  • venv/, .venv/ (Python virtual environments)
  • build/, dist/ (Build artifacts)
  • docs/archive/ (Archived documentation)

Troubleshooting

Hook fails but you think it's wrong

Check the specific hook documentation and configuration. Some rules may need adjustment for the project.

Pre-commit not running

Ensure hooks are installed:

pre-commit install

Slow execution

Run hooks on specific files only:

pre-commit run <hook-name> <files...>