Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 57 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,90 @@
# 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:
- id: trailing-whitespace
- 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