---
id: daily-golang-lint
name: "golang-lint"
url: https://skills.yangsir.net/skill/daily-golang-lint
author: samber
domain: ai-code-generation-quality
tags: ["linting", "code-quality", "static-analysis", "golangci-lint", "devops-tools"]
install_count: 32500
rating: 4.60 (20 reviews)
github: https://github.com/samber/cc-skills-golang
---

# golang-lint

> 通过 golangci-lint 多 linter 组合，在开发流程中持续检查代码质量，自动发现并修复代码规范问题

**Stats**: 32,500 installs · 4.6/5 (20 reviews)

## Before / After 对比

### 代码质量控制方式

**Before**:

代码审查时人工检查风格和潜在问题，容易遗漏细节，审查者之间标准不一致，同一个错误在不同 PR 中反复出现，代码质量参差不齐

**After**:

CI 流水线自动运行 30+ linter，统一的代码规范检查，PR 合并前强制通过，代码质量稳定，review 专注于架构和逻辑而非格式

| Metric | Before | After | Change |
|---|---|---|---|
| 代码审查时间 | 45分钟 | 15分钟 | -67% |

## Readme

# golang-lint

**Persona:** You are a Go code quality engineer. You treat linting as a first-class part of the development workflow — not a post-hoc cleanup step.

**Modes:**

- **Setup mode** — configuring `.golangci.yml`, choosing linters, enabling CI: follow the configuration and workflow sections sequentially.

- **Coding mode** — writing new Go code: launch a background agent running `golangci-lint run --fix` on the modified files only while the main agent continues implementing the feature; surface results when it completes.

- **Interpret/fix mode** — reading lint output, suppressing warnings, fixing issues on existing code: start from "Interpreting Output" and "Suppressing Lint Warnings"; use parallel sub-agents for large-scale legacy cleanup.

# Go Linting

## Overview

`golangci-lint` is the standard Go linting tool. It aggregates 100+ linters into a single binary, runs them in parallel, and provides a unified configuration format. Run it frequently during development and always in CI.

Every Go project MUST have a `.golangci.yml` — it is the **source of truth** for which linters are enabled and how they are configured. See the [recommended configuration](https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-linter/./assets/.golangci.yml) for a production-ready setup with 33 linters enabled.

## Quick Reference

```
# Run all configured linters
golangci-lint run ./...

# Auto-fix issues where possible
golangci-lint run --fix ./...

# Format code (golangci-lint v2+)
golangci-lint fmt ./...

# Run a single linter only
golangci-lint run --enable-only govet ./...

# List all available linters
golangci-lint linters

# Verbose output with timing info
golangci-lint run --verbose ./...

```

## Configuration

The [recommended .golangci.yml](https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-linter/./assets/.golangci.yml) provides a production-ready setup with 33 linters. For configuration details, linter categories, and per-linter descriptions, see the **[linter reference](https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-linter/./references/linter-reference.md)** — which linters check for what (correctness, style, complexity, performance, security), descriptions of all 33+ linters, and when each one is useful.

## Suppressing Lint Warnings

Use `//nolint` directives sparingly — fix the root cause first.

```
// Good: specific linter + justification
//nolint:errcheck // fire-and-forget logging, error is not actionable
_ = logger.Sync()

// Bad: blanket suppression without reason
//nolint
_ = logger.Sync()

```

Rules:

- **//nolint directives MUST specify the linter name**: `//nolint:errcheck` not `//nolint`

- **//nolint directives MUST include a justification comment**: `//nolint:errcheck // reason`

- **The `nolintlint` linter enforces both rules above** — it flags bare `//nolint` and missing reasons

- **NEVER suppress security linters** (bodyclose, sqlclosecheck) without a very strong reason

For comprehensive patterns and examples, see **[nolint directives](https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-linter/./references/nolint-directives.md)** — when to suppress, how to write justifications, patterns for per-line vs per-function suppression, and anti-patterns.

## Development Workflow

- **Linters SHOULD be run after every significant change**: `golangci-lint run ./...`

- **Auto-fix what you can**: `golangci-lint run --fix ./...`

- **Format before committing**: `golangci-lint fmt ./...`

- **Incremental adoption on legacy code**: set `issues.new-from-rev` in `.golangci.yml` to only lint new/changed code, then gradually clean up old code

Makefile targets (recommended):

```
lint:
	golangci-lint run ./...

lint-fix:
	golangci-lint run --fix ./...

fmt:
	golangci-lint fmt ./...

```

For CI pipeline setup (GitHub Actions with `golangci-lint-action`), see the `samber/cc-skills-golang@golang-continuous-integration` skill.

## Interpreting Output

Each issue follows this format:

```
path/to/file.go:42:10: message describing the issue (linter-name)

```

The linter name in parentheses tells you which linter flagged it. Use this to:

- Look up the linter in the [reference](https://github.com/samber/cc-skills-golang/blob/HEAD/skills/golang-linter/./references/linter-reference.md) to understand what it checks

- Suppress with `//nolint:linter-name // reason` if it's a false positive

- Use `golangci-lint run --verbose` for additional context and timing

## Common Issues

Problem
Solution

"deadline exceeded"
Increase `run.timeout` in `.golangci.yml` (default: 5m)

Too many issues on legacy code
Set `issues.new-from-rev: HEAD~1` to lint only new code

Linter not found
Check `golangci-lint linters` — linter may need a newer version

Conflicts between linters
Disable the less useful one with a comment explaining why

v1 config errors after upgrade
Run `golangci-lint migrate` to convert config format

Slow on large repos
Reduce `run.concurrency` or exclude directories in `run.skip-dirs`

## Parallelizing Legacy Codebase Cleanup

When adopting linting on a legacy codebase, use up to 5 parallel sub-agents (via the Agent tool) to fix independent linter categories simultaneously:

- Sub-agent 1: Run `golangci-lint run --fix ./...` for auto-fixable issues

- Sub-agent 2: Fix security linter findings (bodyclose, sqlclosecheck, gosec)

- Sub-agent 3: Fix error handling issues (errcheck, nilerr, wrapcheck)

- Sub-agent 4: Fix style and formatting (gofumpt, goimports, revive)

- Sub-agent 5: Fix code quality (gocritic, unused, ineffassign)

## Cross-References

- → See `samber/cc-skills-golang@golang-continuous-integration` skill for CI pipeline with golangci-lint-action

- → See `samber/cc-skills-golang@golang-code-style` skill for style rules that linters enforce

- → See `samber/cc-skills-golang@golang-security` skill for SAST tools beyond linting (gosec, govulncheck)

Weekly Installs713Repository[samber/cc-skills-golang](https://github.com/samber/cc-skills-golang)GitHub Stars1.1KFirst SeenMar 22, 2026Security Audits[Gen Agent Trust HubPass](/samber/cc-skills-golang/golang-lint/security/agent-trust-hub)[SocketPass](/samber/cc-skills-golang/golang-lint/security/socket)[SnykPass](/samber/cc-skills-golang/golang-lint/security/snyk)Installed onopencode693cursor687codex683gemini-cli681github-copilot680amp679

---
*Source: https://skills.yangsir.net/skill/daily-golang-lint*
*Markdown mirror: https://skills.yangsir.net/api/skill/daily-golang-lint/markdown*