Skip to content

chore: add pre-commit hook for golangci-lint#55

Open
alenkacz wants to merge 1 commit intomainfrom
av/add-pre-commit-hook
Open

chore: add pre-commit hook for golangci-lint#55
alenkacz wants to merge 1 commit intomainfrom
av/add-pre-commit-hook

Conversation

@alenkacz
Copy link
Copy Markdown
Contributor

Summary

  • Adds a pre-commit hook that runs golangci-lint on staged Go files before each commit
  • Helps catch linting issues early, before they fail in CI
  • Includes a simple setup script for contributors

Setup

./.githooks/setup.sh  # One-time after cloning

Test plan

Manually tested the hook:

  1. No Go files staged - Hook passes immediately:

    🔍 Running pre-commit checks...
    No Go files staged for commit.
    ✅ Pre-commit checks PASSED
    
  2. Go file with valid changes - Hook runs linter and passes:

    🔍 Running pre-commit checks...
    📝 Checking staged Go files...
    0 issues.
    ✅ All pre-commit checks PASSED
    
  3. Missing golangci-lint - Hook provides installation instructions

  4. Linting issues found - Hook blocks commit with helpful message:

    ❌ Pre-commit checks FAILED
    Commit blocked to maintain code quality.
    

🤖 Generated with Claude Code

@alenkacz alenkacz requested a review from birdayz January 14, 2026 08:25
@birdayz
Copy link
Copy Markdown
Contributor

birdayz commented Jan 14, 2026

setup and hook need to use task cmds. global golangci-lint is a bad idea, because linting rules and behavior changes a lot between versions. taskfile pins versions and that matches the committed code.

@birdayz birdayz force-pushed the av/add-pre-commit-hook branch from 8b3690a to b514dae Compare January 16, 2026 21:24
@birdayz
Copy link
Copy Markdown
Contributor

birdayz commented Jan 16, 2026

@alenkacz i updated this PR to have the taskw, what do you think? the setup is now clean and uses the existing tooling

@birdayz birdayz force-pushed the av/add-pre-commit-hook branch 2 times, most recently from 1ac1cc1 to 7506186 Compare January 22, 2026 12:20
Add a pre-commit hook that runs golangci-lint on staged Go files.
Uses taskw wrapper to auto-download pinned versions of go-task
and golangci-lint, eliminating external dependencies.

Files added:
- .githooks/pre-commit: runs linter on staged Go files
- .githooks/setup.sh: configures git to use .githooks directory
- taskw: wrapper that downloads pinned go-task version
- .taskversion: pins go-task to v3.40.0

Run '.githooks/setup.sh' after cloning to enable the hook.
@birdayz birdayz force-pushed the av/add-pre-commit-hook branch from 7506186 to 4d5a66f Compare January 22, 2026 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants