Integrate golangci-lint into GitHub PR Comments Using Reviewdog

| Categories reviewdog  | Tags reviewdog 

🐢 Integrate golangci-lint into GitHub PR Comments Using Reviewdog

In modern collaborative development, automated code review is a key factor in improving team efficiency. Ideally, we want a linter like golangci-lint to run automatically when a Pull Request is created and provide direct feedback in GitHub PR comments. This is exactly what reviewdog is made for.

This article explains how to combine golangci-lint with reviewdog using GitHub Actions.


🧰 Tool Overview

  • golangci-lint: An all-in-one linting tool for Go that supports many linters (like govet, errcheck, etc.).
  • reviewdog: A tool that supports various linters and posts the results as comments in GitHub PRs.

πŸ“¦ Quick Start

1. Create .github/workflows/lint.yml

name: Lint with golangci-lint and reviewdog

on: [pull_request]

jobs:
  golangci-lint:
    name: πŸ§ͺ Lint Go Code
    runs-on: ubuntu-latest

    steps:
      - name: πŸ“₯ Checkout code
        uses: actions/checkout@v4

      - name: πŸ”§ Set up Go
        uses: actions/setup-go@v5
        with:
          go-version: '1.21'

      - name: 🧹 Run golangci-lint with reviewdog
        uses: reviewdog/action-golangci-lint@v2
        with:
          github_token: $
          golangci_lint_flags: '--timeout=3m'
          reporter: github-pr-review # Alternatives: github-pr-check / github-check
          level: warning

🎯 Result Preview

In your PR, reviewdog will automatically annotate lint issues directly on the code lines, like this:

reviewdog pr example


πŸ›  Configuration Options

Parameter Description
github_token GitHub token, usually secrets.GITHUB_TOKEN.
reporter Output type: github-pr-review (inline), github-pr-check, github-check
level Severity level: info, warning, error
golangci_lint_flags Flags passed to golangci-lint, such as config files or filtering rules.

πŸ“ Project Structure Example

.
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── lint.yml       # reviewdog integration
β”œβ”€β”€ .golangci.yml          # golangci-lint config
β”œβ”€β”€ main.go
└── go.mod

Sample .golangci.yml

run:
  timeout: 3m
linters:
  enable:
    - govet
    - errcheck
    - staticcheck
    - unused
issues:
  exclude-rules:
    - path: _test\.go
      linters:
        - errcheck

βœ… Tips

  • reviewdog/action-golangci-lint automatically installs golangci-lint, no manual setup required.
  • reporter: github-pr-review is ideal for inline annotations during code review.
  • Works with private repos as long as secrets.GITHUB_TOKEN is configured.

🧩 Further Reading


🧠 Conclusion

By integrating golangci-lint with reviewdog in your GitHub PR workflow, you can provide developers with immediate feedback on code style and potential bugs, ultimately improving code quality and team collaboration.