Skip to content

Commit f44d236

Browse files
committed
docs(agents): forbid reinventing stdlib helpers and nil-passing
1 parent a643a11 commit f44d236

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,23 @@ details; do not duplicate that detail here.
317317
`iota` constants. The `exhaustive` linter catches missing cases.
318318
- **Use stdlib/codebase constants**: No magic numbers when `math.MaxInt64`
319319
or a codebase constant exists.
320+
- **Check the stdlib before writing a helper**: If you find yourself
321+
defining a tiny utility (`boolStr`, `max`, `min`, `clamp`, "convert
322+
this primitive to a string", "join these N things"), spend ten seconds
323+
checking whether Go already has it. Go 1.21+ has builtin `min`/`max`;
324+
`strconv.FormatBool` / `strconv.Itoa` / `strconv.FormatInt` cover
325+
primitive-to-string; `slices.Contains` / `maps.Keys` cover the obvious
326+
collection ops; `cmp.Or` gives you "first non-zero value". A helper
327+
that reimplements stdlib adds a surface area to maintain, hides the
328+
standard name from future readers, and tells reviewers "I didn't
329+
bother looking." If you genuinely need a wrapper around stdlib (for
330+
typing or consistency), say so in a comment.
331+
- **Check your nils**: Before calling a third-party function with a
332+
conceptual zero value (`nil`, `""`, `0`), either read its godoc or
333+
grep for other call sites in the repo. Functions that query the
334+
terminal, open files, or dial the network commonly dereference their
335+
arguments. `lipgloss.HasDarkBackground(os.Stdin, os.Stderr)` — not
336+
`(nil, nil)`. Treat "I'll just pass nil and see" as a red flag.
320337
- **Safe integer narrowing**: Never cast `int64` to `int` directly. Use
321338
`safeconv.Int` (`internal/safeconv`) which returns an error on overflow.
322339
Callers decide how to handle it (return error, clamp, etc.).

0 commit comments

Comments
 (0)