diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0d353cad..e7d2b7e7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,12 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks + +default_stages: [commit] + repos: + # -------------------------------------------------------------------------- + # Standard File System & Integrity Checks + # -------------------------------------------------------------------------- - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: @@ -8,32 +14,77 @@ repos: - id: end-of-file-fixer - id: check-yaml - id: check-added-large-files + args: ['--maxkb=1024'] # Limit file size to 1MB to prevent repo bloat + + # Security: Prevents committing merge conflict markers (<<<<<<<) + - id: check-merge-conflict + + # Security: Detects if files with mixed line endings are committed + - id: mixed-line-ending + args: ['--fix=lf'] + + # Security: Critical for blockchain - prevents accidental commit of Private Keys + - id: detect-private-key + + # -------------------------------------------------------------------------- + # Golang Static Analysis & Linting + # -------------------------------------------------------------------------- - repo: https://github.com/golangci/golangci-lint rev: v1.61.0 hooks: - id: golangci-lint name: lint Go files - args: [--new-from-rev=HEAD, -v, --fix, --exclude-use-default, --sort-results] + description: Fast, parallel runner for Go linters. + # Architecture Note: Using --new-from-rev=HEAD speeds up pre-commit + # by analyzing only changed files. + args: [--new-from-rev=HEAD, --fix, --exclude-use-default, --sort-results] files: \.go$ + + # -------------------------------------------------------------------------- + # Commit Message Standardization + # -------------------------------------------------------------------------- - repo: https://github.com/compilerla/conventional-pre-commit rev: v3.2.0 hooks: - id: conventional-pre-commit stages: [commit-msg] - args: [feat, fix, ci, chore, test, docs, refactor] # optional: list of Conventional Commits types to allow e.g. [feat, fix, ci, chore, test] + # Enforces semantic versioning standard (e.g., "feat: add new endpoint") + args: [feat, fix, ci, chore, test, docs, refactor, perf, build] + + # -------------------------------------------------------------------------- + # Local Go Tools (Formatting & Dependency Management) + # Note: These require the binaries to be installed on the host machine. + # -------------------------------------------------------------------------- - repo: local hooks: + # Architecture: Ensure dependencies are always in sync before commit + - id: go-mod-tidy + name: go mod tidy + entry: go mod tidy + language: system + types: [go] + pass_filenames: false + + # Architecture: Enforces strict import ordering and grouping - id: goimports-reviser name: go imports reviser entry: goimports-reviser -format -recursive - language: golang + language: system # Use 'system' to use the binary from $PATH types: [go] files: \.go$ - - repo: local - hooks: + + # Architecture: Shortens long lines to keep code readable (max 100 chars) - id: golines name: golines entry: golines --max-len=100 -w - language: golang + language: system types: [go] files: \.go$ + + # Security: Basic check to ensure the code actually compiles + - id: go-build + name: go build check + entry: go build ./... + language: system + types: [go] + pass_filenames: false