Autoreview your Go PRs using reviewdog and golangci-lint!

go Oct 2, 2024


Problem?

Detect simple problems problem with Go code within a PR.

Solution?

golangci-lint + reviewdog + Github Actions

golangci-lint - aggregates many open source linters into one linting program.

reviewdog - a glue to connect linter output with Github Actions via:

  • checks
  • PR comments
  • PR annotations

Github Actions - run those two above for each PR

How?

Like this:

name: Reviewdog

on:
    pull_request:
      branches:
        - main
      paths:
      - **/*.go

jobs:
  reviewdog:
    name: reviewdog
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0
          
      - name: Lint
        uses: reviewdog/action-golangci-lint@v2
        with:
          workdir: app/
          golangci_lint_flags: --timeout=10m

.github/workflows/reviewdog.yaml

linters:
  enable:
    # Errcheck is a program for checking for unchecked errors in Go code. These unchecked errors can be critical bugs in some cases.
    - errcheck
    # Linter for Go source code that specializes in simplifying code.
    - gosimple

app/.golangci.yml

How it looks like?



Reference

Tags

Krzysztof Wiatrzyk

Big love for Kubernetes and the entire Cloud Native Computing Foundation. DevOps, biker, hiker, dog lover, guitar player, and lazy gamer.