Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/contributing/go-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,21 @@ See [`forge.IsTransient`](../../internal/forge/forge.go) for the canonical examp

**When reviewing PRs:** Flag any `Timeout() bool` interface assertion without a preceding `errors.Is(err, context.DeadlineExceeded)` guard as a medium-severity finding. The fix is to add the context-error check before the `Timeout()` check.

### Template map iteration

Go's `text/template` `range` action visits map keys of basic types (string,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] technical accuracy

The parenthetical list of basic types says '(string, int, float)' but omits unsigned integer types (uint, uint8, uint16, uint32, uint64) which are also basic types with a defined order that receive sorted iteration in text/template. The official Go documentation says 'basic type with a defined order' without limiting to only string/int/float. The 'When reviewing PRs' directive on line 323 repeats the incomplete list ('string, int, and float keys') without the 'basic types' qualifier — a reviewer reading this guidance might incorrectly conclude that a map[uint64]T would NOT get sorted iteration in a template.

Suggested fix: Expand the parenthetical to '(string, int, uint, float)' or use the official phrasing 'basic type with a defined order' to match the upstream documentation. Apply the same fix to the 'When reviewing PRs' directive on line 323.

int, uint, float) in **sorted order** — unlike bare `range` over a map in Go code.
Do **not** flag `{{ range $k, $v := .SomeMap }}` in templates as
non-deterministic when the key type is a basic type. See
[text/template documentation](https://pkg.go.dev/text/template) (search
"sorted key order").

**When reviewing PRs:** Do not flag `range` over a basic-type-keyed map
inside a `text/template` as non-deterministic output. The `text/template`
package guarantees sorted iteration for string, int, uint, and float keys. This
is a well-documented exception to Go's general rule that map iteration
order is unspecified.

## Injectable function variables (test seams)

Package-level variables that hold function values for test overriding must:
Expand Down
Loading