golang-code-style

Enforces Go code style conventions for clarity, control flow, and variable declarations.

Updated Jun 30, 2026
One-click install
npx skills add https://github.com/santoshkal/chezmoi --skill golang-code-style-santoshkal
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-code-style
Source: https://github.com/santoshkal/chezmoi/tree/main/private_dot_config/opencode/skills/Golang/skills/golang-code-style
Command: npx skills add https://github.com/santoshkal/chezmoi --skill golang-code-style-santoshkal

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go linters handle formatting, but style decisions requiring human judgment—like when to use var versus :=, how to structure control flow, or when to pass pointers versus values—are left to developers. This Skill encodes those judgment calls as explicit rules so AI agents and reviewers write and review Go code consistently. ## Core Features & Use Cases - Style Rule Enforcement: Covers line breaking at semantic boundaries, zero-value intent signaling with var vs :=, non-nil slice/map initialization, named struct fields, early returns, and switch-over-if-else chains. - Function Design Guidance: Enforces ≤4 parameters with options structs, context.Context first, and value-vs-pointer argument rules based on size and mutation. - Parallel Code Reviews: Orchestrates up to 5 sub-agents, each covering an independent style concern, for reviewing style across large codebases. - Use Case: When reviewing a pull request, ask the agent to check the diff against these style rules—it will flag nested if-else chains that should use early returns, nil slice returns that serialize to JSON null, and positional struct literals that break on field reordering. ## Quick Start Review the Go files in this repository for code style violations such as missing early returns, nil slice returns, and positional struct literals.

Frequently Asked Questions about golang-code-style

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enforce Go code style rules beyond what linters check?▼

Linters like gofmt and gofumpt handle formatting, but judgment-based rules need explicit conventions. This skill covers early returns over nesting, named booleans for complex conditions, options structs for functions with more than 4 parameters, and value-versus-pointer argument decisions.

When should I use var versus := in Go variable declarations?▼

Use := for non-zero values and var for zero-value initialization, since the form signals intent. For example, use var count int when the counter starts at zero, but name := "default" when assigning a meaningful initial value.

Why should Go functions return empty slices instead of nil?▼

Nil slices serialize to null in JSON while empty slices serialize to [], which surprises API consumers expecting an array. Nil maps additionally panic on write, so slices and maps should always be initialized with []T{} or make().

When should Go function parameters use pointers instead of values?▼

Pass small types like string, int, bool, and time.Time by value. Use pointers when the function mutates the argument, when the struct exceeds roughly 128 bytes, or when nil is meaningful for optional parameters.

Does this skill replace Go linters like golangci-lint?▼

No, it complements them. Linters enforce mechanical formatting automatically, while this skill handles clarity rules requiring judgment, such as reducing nesting and extracting complex conditions. It cross-references a separate golang-lint skill for automated enforcement.

What topics does this Go style skill not cover?▼

It explicitly excludes naming conventions, linter configuration, and doc comments, which are handled by sibling skills golang-naming, golang-lint, and golang-documentation. Struct and interface design is covered by golang-structs-interfaces.