Get the FREE Ultimate OpenClaw Setup Guide →

go-linting

Scanned
npx machina-cli add skill cxuu/golang-skills/go-linting --openclaw
Files (1)
SKILL.md
2.9 KB

Go Linting

Source: Uber Go Style Guide

Core Principle

More important than any "blessed" set of linters: lint consistently across a codebase.

Consistent linting helps catch common issues and establishes a high bar for code quality without being unnecessarily prescriptive.


Minimum Recommended Linters

Source: Uber Go Style Guide

These linters catch the most common issues while maintaining a high quality bar:

LinterPurpose
errcheckEnsure errors are handled
goimportsFormat code and manage imports
reviveCommon style mistakes (modern replacement for golint)
govetAnalyze code for common mistakes
staticcheckVarious static analysis checks

Note: revive is the modern, faster successor to the now-deprecated golint.


Lint Runner: golangci-lint

Source: Uber Go Style Guide

Use golangci-lint as your lint runner:

  • Performance: Optimized for large codebases
  • Unified config: Configure many linters at once
  • Extensible: Add linters as needed for your project

See the example .golangci.yml from uber-go/guide.


Example Configuration

Create .golangci.yml in your project root:

linters:
  enable:
    - errcheck
    - goimports
    - revive
    - govet
    - staticcheck

linters-settings:
  goimports:
    local-prefixes: github.com/your-org/your-repo
  revive:
    rules:
      - name: blank-imports
      - name: context-as-argument
      - name: error-return
      - name: error-strings
      - name: exported

run:
  timeout: 5m

Running

# Install
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

# Run all linters
golangci-lint run

# Run on specific paths
golangci-lint run ./pkg/...

Quick Reference

TaskCommand/Action
Install golangci-lintgo install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
Run lintersgolangci-lint run
Run on pathgolangci-lint run ./pkg/...
Config file.golangci.yml in project root
CI integrationRun golangci-lint run in pipeline

Linter Selection Guidelines

When you need...Use
Error handling coverageerrcheck
Import formattinggoimports
Style consistencyrevive
Bug detectiongovet, staticcheck
All of the abovegolangci-lint with config

See Also

  • For core style principles: go-style-core
  • For testing best practices: go-testing

Source

git clone https://github.com/cxuu/golang-skills/blob/main/skills/go-linting/SKILL.mdView on GitHub

Overview

Sets up Go linting with golangci-lint using a curated set of linters (errcheck, goimports, revive, govet, staticcheck). Emphasizes lint consistency across a codebase to catch common issues early and raise the bar for quality without being prescriptive. Includes a ready .golangci.yml configuration and CI/CD integration guidance.

How This Skill Works

Install golangci-lint, configure linters in a .golangci.yml, and run golangci-lint run. golangci-lint provides a unified runner to apply multiple linters across the codebase, with a centralized configuration that can be used in local development and CI. The example config enables core linters and sets revive rules, which can be adjusted to fit your project needs.

When to Use It

  • Setting up linting for a new Go project or CI/CD pipeline
  • Integrating linting into CI to fail builds on style or correctness issues
  • Maintaining code quality across a large Go codebase or monorepo
  • Enforcing error handling, formatting, and style consistency in teams
  • Migrating from golint to revive and consolidating lint checks with golangci-lint

Quick Start

  1. Step 1: Install golangci-lint
  2. Step 2: Create and customize .golangci.yml (enable linters like errcheck, goimports, revive, govet, staticcheck)
  3. Step 3: Run golangci-lint run and optionally integrate with CI

Best Practices

  • Pin and install a specific golangci-lint version in CI to ensure reproducible results
  • Enable the recommended linters: errcheck, goimports, revive, govet, staticcheck
  • Place the config file at the project root as .golangci.yml and commit it
  • Set a reasonable run timeout (e.g., 5m) to balance thoroughness and speed
  • Customize revive rules (blank-imports, context-as-argument, error-return, error-strings, exported) to fit your codebase

Example Use Cases

  • Initialize linting for a new Go service with a starter .golangci.yml and CI checks
  • Integrate golangci-lint into a CI pipeline to run on every pull request
  • Use goimports to automatically format imports and enforce local prefixes
  • Apply revive rules to enforce consistent style across the repository
  • Run errcheck and staticcheck locally to catch error handling and bug-prone patterns

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers