golang-lint

द्वारा samber

Golang प्रोजेक्ट्स के लिए लिंटिंग सर्वोत्तम अभ्यास और golangci-lint कॉन्फ़िगरेशन — लिंटर चलाना, .golangci.yml कॉन्फ़िगर करना, nolint निर्देशों के साथ चेतावनियाँ दबाना, लिंट आउटपुट की व्याख्या करना और लिंटर चुनना। इसका उपयोग तब करें जब golangci-lint कॉन्फ़िगर करना हो, लिंट चेतावनियों या nolint सप्रेशन के बारे में पूछना हो, कोड गुणवत्ता टूलिंग सेट अप करनी हो, या लिंटर चुनने हों। इसका उपयोग तब भी करें

npx skills add https://github.com/samber/cc-skills-golang --skill 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.

Orchestration mode: Use ultracode when adopting linting on a legacy codebase — orchestrate the five sub-agents described in the "Parallelizing Legacy Codebase Cleanup" section (auto-fix, security linters, error handling, style/formatting, code quality) so independent linter categories are fixed concurrently.

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.

Dependencies:

  • golangci-lint: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

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 for a production-ready setup with 48 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 provides a production-ready setup with 33 linters. For configuration details, linter categories, and per-linter descriptions, see the linter reference — 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:

  1. //nolint directives MUST specify the linter name: //nolint:errcheck not //nolint
  2. //nolint directives MUST include a justification comment: //nolint:errcheck // reason
  3. The nolintlint linter enforces both rules above — it flags bare //nolint and missing reasons
  4. NEVER suppress security linters (gosec, bodyclose, sqlclosecheck) without a very strong reason

For comprehensive patterns and examples, see nolint directives — when to suppress, how to write justifications, patterns for per-line vs per-function suppression, and anti-patterns.

Development Workflow

  1. Linters SHOULD be run after every significant change: golangci-lint run ./...
  2. Auto-fix what you can: golangci-lint run --fix ./...
  3. Format before committing: golangci-lint fmt ./...
  4. 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 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

ProblemSolution
"deadline exceeded"Set or increase run.timeout in .golangci.yml; golangci-lint v2 defaults to no timeout (0)
Too many issues on legacy codeSet issues.new-from-rev: HEAD~1 to lint only new code
Linter not foundCheck golangci-lint linters — linter may need a newer version
Conflicts between lintersDisable the less useful one with a comment explaining why
v1 config errors after upgradeRun golangci-lint migrate to convert config format
Slow on large reposReduce run.concurrency or exclude paths with linters.exclusions.paths / formatters.exclusions.paths

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)
  • → See samber/cc-skills-golang@golang-continuous-integration skill for automated AI-driven code review in CI using these guidelines

samber की और Skills

golang-code-style
samber
We need to translate the given English text into Hindi. The text describes a skill about Golang code style conventions. We must preserve the name "golang-code-style" but it's not in the text, so we don't include it. We also preserve URLs, product names, protocol names, numbers, technical terms. The text includes references to other skills like "samber/cc-skills-golang@golang-naming" etc. Those should be preserved as is. The translation should be natural Hindi, but keep technical terms like "Golang", "code style", "line length", "variable declarations", "control flow", "comments", "linter", "doc comments" etc. Possibly use transliteration or Hindi equivalents? For technical terms, often English terms are used in Hindi context. But we can translate where possible. For example, "line length and breaking" -> "पंक्ति की लंबाई और विभाजन". "variable declarations" -> "चर घोषणाएँ". "control flow clarity" -> "न
developmentcode-review
golang-testing
samber
प्रोडक्शन-रेडी गोलैंग टेस्ट — टेबल-ड्रिवन टेस्ट, टेस्टिफाई सूट और मॉक, पैरेलल टेस्ट, फज़िंग, फिक्स्चर, गोलिक के साथ गोरूटीन लीक डिटेक्शन, स्नैपशॉट टेस्टिंग, कोड कवरेज, इंटीग्रेशन टेस्ट, इडियोमैटिक टेस्ट नेमिंग। गो टेस्ट लिखते या रिव्यू करते समय, टेस्टिंग दृष्टिकोण चुनते समय, गो टेस्ट सीआई सेट अप करते समय, या फ्लैकी/स्लो टेस
developmenttestingcode-review
golang-design-patterns
samber
इडियोमैटिक गोलैंग डिज़ाइन पैटर्न — फंक्शनल ऑप्शंस, कंस्ट्रक्टर, एरर फ्लो और कैस्केडिंग, रिसोर्स मैनेजमेंट और लाइफसाइकिल, ग्रेसफुल शटडाउन, रेज़िलिएंस, आर्किटेक्चर, डिपेंडेंसी इंजेक्शन, डेटा हैंडलिंग, स्ट्रीमिंग और अन्य। तब लागू करें जब आर्किटेक्चरल पैटर्न के बीच स्पष्ट रूप से चुनाव करना हो, फंक्शनल ऑप्शंस लागू करना हो, कं
developmentdesigncode-review
golang-error-handling
samber
इडियोमैटिक गोलैंग एरर हैंडलिंग — %w के साथ क्रिएशन और रैपिंग, errors.Is/As, errors.Join, कस्टम एरर टाइप्स, सेंटिनल एरर्स, panic/recover, सिंगल हैंडलिंग रूल, slog के साथ स्ट्रक्चर्ड लॉगिंग, HTTP रिक्वेस्ट लॉगिंग मिडलवेयर, और प्रोडक्शन एरर्स के लिए samber/oops। लॉग एग्रीगेशन थर्ड-पार्टी टूल्स के साथ स्केल पर लॉग्स को उपयोगी बनाने के लिए बनाया गया। Go कोड में एरर्स बनाते, रैप करते, निर
developmentcode-review
golang-performance
samber
गोलांग प्रदर्शन अनुकूलन पैटर्न और पद्धति - यदि X अड़चन है, तो Y लागू करें। इसमें आवंटन कमी, CPU दक्षता, मेमोरी लेआउट, GC ट्यूनिंग, पूलिंग, कैशिंग और हॉट-पाथ अनुकूलन शामिल है। इसका उपयोग तब करें जब प्रोफाइलिंग या बेंचमार्क ने कोई अड़चन पहचान ली हो और आपको उसे ठीक करने के लिए सही अनुकूलन पैटर्न की आवश्यकता हो। इसका उपयोग प्रदर्शन कोड समीक्षा करते समय भी करें ताकि सुधार
developmentcode-review
golang-security
samber
गोलांग के लिए सुरक्षा सर्वोत्तम अभ्यास और भेद्यता रोकथाम। इंजेक्शन (SQL, कमांड, XSS), क्रिप्टोग्राफी, फाइलसिस्टम सुरक्षा, नेटवर्क सुरक्षा, कुकीज़, सीक्रेट्स प्रबंधन, मेमोरी सुरक्षा और लॉगिंग को शामिल करता है। सुरक्षा के लिए Go कोड लिखते, समीक्षा करते या ऑडिट करते समय, या क्रिप्टो, I/O, सीक्रेट्स प्रबंधन, उपयोगकर्ता इनपुट हैंडलिंग या प्रमाणीकरण से जुड़े किसी भी जोख
securitycode-reviewdevelopment
golang-database
samber
Go डेटाबेस एक्सेस के लिए व्यापक मार्गदर्शिका — पैरामीटराइज़्ड क्वेरीज़, स्ट्रक्ट स्कैनिंग, NULL योग्य कॉलम, ट्रांज़ैक्शन, आइसोलेशन लेवल, SELECT FOR UPDATE, कनेक्शन पूल, बैच प्रोसेसिंग, कॉन्टेक्स्ट प्रोपेगेशन और माइग्रेशन टूलिंग। PostgreSQL, MariaDB, MySQL या SQLite के साथ इंटरैक्ट करने वाले Golang कोड को लिखते, समीक्षा करते या डीबग करते समय उपयोग करें; डेटाबेस परीक्षण के लिए; या database/sql, sqlx या pg
developmentdatabase
golang-troubleshooting
samber
गोलांग प्रोग्रामों का व्यवस्थित समस्या निवारण करें - मूल कारण खोजें और ठीक करें। इसका उपयोग तब करें जब गो कोड में बग, क्रैश, डेडलॉक या अप्रत्याशित व्यवहार का सामना हो। इसमें डिबगिंग पद्धति, सामान्य गो पिटफॉल्स, टेस्ट-संचालित डिबगिंग, pprof सेटअप और कैप्चर, डेल्व डिबगर, रेस डिटेक्शन, GODEBUG ट्रेसिंग और प्रोडक्शन डिबगिंग शामिल है। किसी भी 'कुछ गलत है' स्थिति के लिए यहां
developmenttesting