All skills
cxuu avatar

/go-style-core

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

Use when working with Go formatting, line length, nesting, naked returns, semicolons, or core style principles. Also use when a style question isn't covered by a more specific skill, even if the user doesn't reference a specific style rule. Does not cover domain-specific patterns like error handling, naming, or testing (see specialized skills). Acts as fallback when no more specific style skill applies.

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

This session only. Nothing lands on disk.

referencesPRINCIPLES.md

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

Style Principles Reference

1. Clarity

The code's purpose and rationale must be clear to the reader.

  • What: Use descriptive names, helpful comments, and efficient organization
  • Why: Add commentary explaining rationale, especially for nuances
  • View clarity through the reader's lens, not the author's
  • Code should be easy to read, not easy to write
// Good: Clear purpose
func (c *Config) WriteTo(w io.Writer) (int64, error)

// Bad: Unclear, repeats receiver
func (c *Config) WriteConfigTo(w io.Writer) (int64, error)

2. Simplicity

Code should accomplish goals in the simplest way possible.

Simple code:

  • Is easy to read top to bottom
  • Does not assume prior knowledge
  • Has no unnecessary abstraction levels
  • Has comments explaining "why", not "what"
  • May be mutually exclusive with "clever" code

Least Mechanism

Where there are several ways to express the same idea, prefer the most standard tool:

  1. Core language constructs (channel, slice, map, loop, struct)
  2. Standard library (HTTP client, template engine)
  3. Third-party library — only when (1) and (2) don't suffice

3. Concision

Code should have high signal-to-noise ratio.

  • Avoid repetitive code
  • Avoid extraneous syntax
  • Avoid unnecessary abstraction
  • Use table-driven tests to factor out common code
// Good: Common idiom, high signal
if err := doSomething(); err != nil {
    return err
}

// Good: Signal boost for unusual case
if err := doSomething(); err == nil { // if NO error
    // ...
}

4. Maintainability

Code is edited many more times than written.

Maintainable code:

  • Is easy for future programmers to modify correctly
  • Has APIs that grow gracefully
  • Uses predictable names (same concept = same name)
  • Minimizes dependencies
  • Has comprehensive tests with clear diagnostics
// Bad: Critical detail hidden
if user, err = db.UserByID(userID); err != nil { // = vs :=

// Good: Explicit and clear
u, err := db.UserByID(userID)
if err != nil {
    return fmt.Errorf("invalid origin user: %s", err)
}
user = u

5. Consistency

Code should look and behave like similar code in the codebase.

  • Package-level consistency is most important
  • When ties occur, break in favor of consistency
  • Never override documented style principles for consistency

Source: SKILL.md on GitHub

No alerts17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill provides idiomatic Go style guidelines and formatting rules. It focuses on clarity, simplicity, and reducing nesting while using standard tools like gofmt. No security risks were identified.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    1 file 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 3 months ago

README badge

README badge for cxuu/golang-skills/go-style-core