agentleFS
Baba01hacker666Baba01hacker666/dummyskills/skills/golang/go-code-quality/SKILL.md

go-code-quality

Skill0 starsChanged 2 months agoMITView on GitHub

Guides agents in applying idiomatic Go architecture: explicit error handling, interface segregation, context propagation, and goroutine leak prevention.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 14
  2. Very specific:

    Do not use for testing; use go-testing.

    line 20
  3. Very specific:

    If target_file is missing: ask for target file.

    line 26
  4. Very specific:

    Never introduce panics for standard operational errors.

    line 27
  5. Distinctive:

    Follow these numbered actions:

    line 30
  6. Very specific:

    Ensure ctx context.Context is the first parameter of I/O functions.

    line 32
  7. Very specific:

    Ensure every go func() has a termination condition via ctx.Done().

    line 36
  8. Very specific:

    Run go build ./... and go test ./....

    line 38
  9. Very specific:

    Never use panic() in package libraries.

    line 42
  10. Distinctive:

    Stop and ask the user when:

    line 71

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Go Code Quality & Idioms

Enforces canonical Go idioms: context.Context propagation as the first parameter, small interfaces defined by consumers, explicit error wrapping (fmt.Errorf("%w", err)), and goroutine cancellation.

1. Purpose

Refactor Go code into idiomatic, robust implementations. "Interface Segregation" means declaring 1-2 method interfaces at consumer sites rather than large producer interfaces.

2. When to Use

Use this skill when:

  • Adding cancellation and timeouts to long-running Go operations via context.Context.
  • Wrapping errors with %w for errors.Is() and errors.As().
  • Preventing goroutine leaks by ensuring channels have exits.

3. When Not to Use

  • Do not use for testing; use go-testing.

4. Required Inputs

  • target_file: Path to the Go file to improve.

5. Missing-Input Behavior

  1. If target_file is missing: ask for target file.
  2. Never introduce panics for standard operational errors; use error returns.

6. Procedure

Follow these numbered actions:

  1. Action 1: Check Context Propagation
    • Ensure ctx context.Context is the first parameter of I/O functions.
  2. Action 2: Check Error Wrapping
    • Replace generic string formatting with fmt.Errorf("failed action: %w", err).
  3. Action 3: Audit Goroutine Lifecycles
    • Ensure every go func() has a termination condition via ctx.Done().
  4. Action 4: Verify Compilation & Tests
    • Run go build ./... and go test ./....

7. Decision Rules

  • Accept interfaces, return structs.
  • Never use panic() in package libraries.

8. Output Format

Emit the report using this template:

### Go Code Quality Report: [File]

- **File Modified**: `[path]`
- **Patterns Applied**: [e.g. Context Propagation, Error Wrapping]
- **Compile Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- [Detail 1]
- [Detail 2]

9. Verification Checklist

  • ctx context.Context is first parameter on network/db functions.
  • Errors wrapped using %w.
  • No goroutine leaks.
  • go test ./... passes.

10. Common Failures and Recovery

Failure SymptomCauseRecovery Action
Goroutine hangs foreverChannel read without cancellation selectAdd select { case ch <- val: case <-ctx.Done(): return }.

11. Stop or Escalation Conditions

Stop and ask the user when:

  • Changing function signatures affects exported public package APIs.

12. Examples

Example 1: Successful Execution

Input:

File: internal/fetcher.go
Goal: Add context cancellation to FetchUser

Output:

### Go Code Quality Report: internal/fetcher.go

- **File Modified**: `internal/fetcher.go`
- **Patterns Applied**: Context Propagation & Error Wrapping
- **Compile Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- Updated signature: `func FetchUser(ctx context.Context, id string) (*User, error)`
- Wrapped HTTP request with `http.NewRequestWithContext(ctx, ...)`.
- Wrapped error: `fmt.Errorf("fetching user %s: %w", id, err)`.

Example 2: Ambiguous or Missing Input

Input:

Fix go idioms.

Output:

### Go Code Quality Report: Halted - No Target

- **Status**: Halted

Please specify the target Go file to inspect.

Example 3: Expected Final Output

Output:

### Go Code Quality Report: internal/storage.go

- **File Modified**: `internal/storage.go`
- **Patterns Applied**: Consumer-Defined Interface
- **Compile Status**: PASS
- **Test Status**: PASS

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.