Get the FREE Ultimate OpenClaw Setup Guide →

go-code-review

npx machina-cli add skill cxuu/golang-skills/go-code-review --openclaw
Files (1)
SKILL.md
6.3 KB

Go Code Review Checklist

Based on Go Wiki CodeReviewComments. This checklist provides quick review points with references to detailed skills.


Formatting

  • gofmt: Code is formatted with gofmt or goimportsgo-linting

Documentation

  • Comment sentences: Comments are full sentences starting with the name being described, ending with a period → go-documentation
  • Doc comments: All exported names have doc comments; non-trivial unexported declarations too → go-documentation
  • Package comments: Package comment appears adjacent to package clause with no blank line → go-documentation
  • Named result parameters: Only used when they clarify meaning (e.g., multiple same-type returns), not just to enable naked returns → go-documentation

Error Handling

  • Handle errors: No discarded errors with _; handle, return, or (exceptionally) panic → go-error-handling
  • Error strings: Lowercase, no punctuation (unless starting with proper noun/acronym) → go-error-handling
  • In-band errors: No magic values (-1, "", nil); use multiple returns with error or ok bool → go-error-handling
  • Indent error flow: Handle errors first and return; keep normal path at minimal indentation → go-error-handling

Naming

  • MixedCaps: Use MixedCaps or mixedCaps, never underscores; unexported is maxLength not MAX_LENGTHgo-naming
  • Initialisms: Keep consistent case: URL/url, ID/id, HTTP/http (e.g., ServeHTTP, xmlHTTPRequest) → go-naming
  • Variable names: Short names for limited scope (i, r, c); longer names for wider scope → go-naming
  • Receiver names: One or two letter abbreviation of type (c for Client); no this, self, me; consistent across methods → go-naming
  • Package names: No stuttering (use chubby.File not chubby.ChubbyFile); avoid util, common, miscgo-packages

Concurrency

  • Goroutine lifetimes: Clear when/whether goroutines exit; document if not obvious → go-concurrency
  • Synchronous functions: Prefer sync over async; let callers add concurrency if needed → go-concurrency
  • Contexts: First parameter; not in structs; no custom Context types; pass even if you think you don't need to → go-context

Interfaces

  • Interface location: Define in consumer package, not implementor; return concrete types from producers → go-interfaces
  • No premature interfaces: Don't define before used; don't define "for mocking" on implementor side → go-interfaces
  • Receiver type: Use pointer if mutating, has sync fields, or is large; value for small immutable types; don't mix → go-interfaces

Data Structures

  • Empty slices: Prefer var t []string (nil) over t := []string{} (non-nil zero-length) → go-data-structures
  • Copying: Be careful copying structs with pointer/slice fields; don't copy *T methods' receivers by value → go-data-structures

Security

  • Crypto rand: Use crypto/rand for keys, not math/randgo-defensive
  • Don't panic: Use error returns for normal error handling; panic only for truly exceptional cases → go-defensive

Style

  • Line length: No rigid limit, but avoid uncomfortably long lines; break by semantics, not arbitrary length → go-style-core
  • Naked returns: Only in short functions; explicit returns in medium/large functions → go-style-core
  • Pass values: Don't use pointers just to save bytes; pass string not *string for small fixed-size types → go-performance

Imports

  • Import groups: Standard library first, then blank line, then external packages → go-packages
  • Import renaming: Avoid unless collision; rename local/project-specific import on collision → go-packages
  • Import blank: import _ "pkg" only in main package or tests → go-packages
  • Import dot: Only for circular dependency workarounds in tests → go-packages

Testing

  • Examples: Include runnable Example functions or tests demonstrating usage → go-documentation
  • Useful test failures: Messages include what was wrong, inputs, got, and want; order is got != wantgo-testing

Quick Review Commands

# Format and organize imports
goimports -w .

# Run linter suite
golangci-lint run

# Check for common issues
go vet ./...

See Also

  • go-linting: Automated tooling for style enforcement
  • go-style-core: Core Go style principles
  • go-documentation: Documentation and comment standards
  • go-error-handling: Error handling patterns
  • go-naming: Naming conventions
  • go-packages: Package design and imports
  • go-interfaces: Interface design patterns
  • go-concurrency: Concurrency patterns
  • go-context: Context usage patterns
  • go-data-structures: Data structure idioms
  • go-defensive: Defensive programming
  • go-testing: Testing patterns
  • go-performance: Performance considerations

Source

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

Overview

A quick-reference checklist drawn from the Go Wiki CodeReviewComments. It guides reviewers through formatting, documentation, error handling, naming, concurrency, interfaces, and data structures to ensure Go code meets community standards.

How This Skill Works

The skill provides a structured list of review points. Reviewers check each item and follow links to deeper guidance (e.g., gofmt, go-documentation, go-error-handling) to fix or confirm compliance.

When to Use It

  • Reviewing new Go code for style and correctness before merging
  • Auditing a codebase to ensure alignment with community standards
  • Onboarding new contributors to Go review expectations
  • During refactors to prevent regressions in formatting and comments
  • When auditing exported APIs and error handling

Quick Start

  1. Step 1: Run gofmt/goimports to ensure standard formatting
  2. Step 2: Scan for documentation on exported names and package comments
  3. Step 3: Check error handling, naming, concurrency, and data-structure notes

Best Practices

  • Run gofmt or goimports as a first step
  • Ensure all exported names have doc comments and package comments are present
  • Avoid discarding errors; handle, propagate, or panic only when justified
  • Use proper naming: MixedCaps, consistent initialisms, and concise receiver names
  • Be explicit about goroutine lifetimes and store context in the first parameter

Example Use Cases

  • Review a REST API handler to verify error handling and doc comments
  • Audit a library's interfaces to avoid premature interface definitions
  • Check a package for empty slices vs nil slices and correct initialization
  • Validate naming and initialisms across a new module (URL vs Url, ID vs Id)
  • Refactor a module to remove package name stuttering and improve readability

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers