registry/.githooks/pre-commit
Tadas Antanavicius 4e221e49a8
Add linting documentation and pre-commit hooks (#177)
## Summary

This PR improves the developer experience by adding clear linting
documentation and optional pre-commit hooks to catch issues before CI.
Helpful to avoid fighting Claude Code / Copilot on "please make sure
linting passes CI".

## Changes

- Updated `README.md` with:
  - Go 1.23.x requirement (was "1.18 or later")
  - golangci-lint v1.61.0 in prerequisites
  - New Development section with linting instructions
  
- Updated `CLAUDE.md` with:
  - Development Setup section
  
- Added `.githooks/pre-commit`:
  - Runs golangci-lint and gofmt checks
  - References README for installation instructions
  - Can be bypassed with `--no-verify` when needed

## Test Plan

- [x] Verified pre-commit hook blocks commits when golangci-lint is
missing
- [x] Confirmed hook shows clear error message pointing to README
- [x] Tested that linting passes with Go 1.23.0 and golangci-lint
v1.61.0
- [x] Verified gofmt correctly identifies formatting issues

Co-authored w/ Claude Code

---------

Co-authored-by: Charles Lowell <10964656+chlowell@users.noreply.github.com>
2025-07-15 09:31:17 -07:00

35 lines
864 B
Shell
Executable file

#!/bin/bash
# Pre-commit hook for MCP Registry
# Runs linting and formatting checks before allowing commits
set -e
echo "Running pre-commit checks..."
# Check if golangci-lint is installed
if ! command -v golangci-lint &> /dev/null; then
echo "❌ golangci-lint is not installed!"
echo "See README.md Prerequisites section for installation instructions."
exit 1
fi
# Run golangci-lint
echo "Running golangci-lint..."
if ! golangci-lint run --timeout=5m; then
echo "❌ Linting failed! Please fix the issues above."
exit 1
fi
# Check formatting
echo "Checking Go formatting..."
UNFORMATTED=$(gofmt -s -l .)
if [ -n "$UNFORMATTED" ]; then
echo "❌ The following files need formatting:"
echo "$UNFORMATTED"
echo ""
echo "Run 'gofmt -s -w .' to fix formatting issues."
exit 1
fi
echo "✅ All pre-commit checks passed!"