All skills
cxuu avatar

/go-naming

@91f0c2e
by Charles Xucxuu/golang-skills165 stars
19

Use when naming any Go identifier — packages, types, functions, methods, variables, constants, or receivers — to ensure idiomatic, clear names. Also use when a user is creating new types, packages, or exported APIs, even if they don't explicitly ask about naming conventions. Does not cover package organization (see go-packages).

Use this Skill: https://skilld.dev/gh/cxuu/golang-skills/go-naming

This session only. Nothing lands on disk.

referencesREPETITION.md

≈508 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Avoiding Repetition

This reference covers how to avoid redundant naming in Go by considering the context where names appear—package, receiver type, and surrounding code.

Package vs. Exported Symbol

Advisory: Don't repeat package name in exported symbols.

// Bad - repetitive at call site
package widget
func NewWidget() *Widget           // widget.NewWidget()
func NewWidgetWithName(n string)   // widget.NewWidgetWithName()

// Good - concise at call site
package widget
func New() *Widget                 // widget.New()
func NewWithName(n string) *Widget // widget.NewWithName()
// Bad
package db
func LoadFromDatabase() error      // db.LoadFromDatabase()

// Good
package db
func Load() error                  // db.Load()

Method vs. Receiver Type

Advisory: Don't repeat receiver type in method name.

// Bad
func (c *Config) WriteConfigTo(w io.Writer) error
func (p *Project) ProjectName() string

// Good
func (c *Config) WriteTo(w io.Writer) error
func (p *Project) Name() string

Context vs. Local Names

Advisory: Omit information already clear from context.

// Bad - in package "ads/targeting/revenue/reporting"
type AdsTargetingRevenueReport struct{}

// Good
type Report struct{}
// Bad - in package "sqldb"
type DBConnection struct{}

// Good
type Connection struct{}

Complete Example

// Bad - excessive repetition
func (db *DB) UserCount() (userCount int, err error) {
    var userCountInt64 int64
    if dbLoadError := db.LoadFromDatabase("count(distinct users)", &userCountInt64); dbLoadError != nil {
        return 0, fmt.Errorf("failed to load user count: %s", dbLoadError)
    }
    userCount = int(userCountInt64)
    return userCount, nil
}

// Good - clear and concise
func (db *DB) UserCount() (int, error) {
    var count int64
    if err := db.Load("count(distinct users)", &count); err != nil {
        return 0, fmt.Errorf("failed to load user count: %s", err)
    }
    return int(count), nil
}

Source: SKILL.md on GitHub

No alerts18d5 checks · Risk SAFE
  • Gen Agent Trust Hub18d

    This skill provides guidance and a linter script for enforcing idiomatic Go naming conventions. It helps maintain code quality by identifying naming anti-patterns like screaming snake case constants, redundant 'Get' prefixes, and generic package names.

  • Socket18d

    No alerts

  • Snyk18d

    Risk: LOW · No issues

  • Runlayer6mo

    3 files scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 91f0c2e. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 months ago.

Steadyupdated 4 months ago
What it can do
Runs commands
All 1 allowed tools
Bash(bash:*)

README badge

README badge for cxuu/golang-skills/go-naming