Skip to content

Commit 0245b66

Browse files
Merge pull request #636 from mtrmac/agents
RFC: Add an AGENTS.md in c/image
2 parents e6fb63d + 41f7d3a commit 0245b66

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

image/AGENTS.md

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Commitments
2+
3+
go.podman.io/image/v5 (aka c/image) promises to keep a stable Go API,
4+
following the general Go semantic versioning rules, and not bumping
5+
the major version. Keep that promise.
6+
7+
# Prioritize human attention
8+
9+
Avoid repetitive code. As a rule of thumb, 3 repetitions of
10+
the same >5-line pattern should probably be refactored, _if_
11+
a clear abstraction can be found.
12+
13+
Human’s screens (and attention spans) are limited. Avoid very long
14+
linear functions, look for ways to abstract / split the function
15+
_if_ the resulting smaller functions have a clear purpose and interface.
16+
Use blank lines within function bodies sparingly, less than
17+
you would do by default (but do use them when separating large conceptually
18+
different parts of the function’s code).
19+
20+
Don't add redundant comments that add no value. Code in style
21+
// Add a user
22+
….addUser(…)
23+
is _never_ acceptable.
24+
25+
# Tests
26+
27+
The default pattern is TestFunctionName, or TestObjectMethodName
28+
(in that case, with no underscore), containing all tests for a function/method.
29+
Do not _default_ to adding a new test function when adding a feature
30+
to an existing function.
31+
32+
Tests should typically be table-driven. When choosing between a
33+
semantically precise table types and short table entries, prefer short table entries
34+
so that the whole test table easily fits on a screen. For example, usually don't
35+
add .name fields to test tables - have such descriptions as comments on the same line
36+
as the other test content.
37+
38+
It should be very rare to test error message text. Just a test that an error is reported
39+
is frequently enough.
40+
41+
# Existing code
42+
43+
Have some (but not slavish) deference to existing code structure: don't
44+
refactor a whole file just to add 3 lines, if that addition would be otherwise clean.
45+
46+
If some refactoring _is_ beneficial, the goal is to have one or more _pure_
47+
refactoring commits (which don't change the observable behavior at all, and document that
48+
in the commit message), followed by a separate commit that adds the required feature.
49+
50+
# Documentation
51+
52+
Most data structures with scope larger than a single function probably need documentation.
53+
Document field interactions:
54+
UseTLS bool
55+
TLSConfig … // Only used if UseTLS
56+
special values:
57+
Name // "" if unknown
58+
_Never_ add comments that add no value:
59+
// A user
60+
type User struct { …}
61+
or
62+
Name // name
63+
is never acceptable.
64+
65+
Most functions should have documentation, documenting in enough detail that, when working
66+
on a caller code, humans can read only the callee’s documentation without reading the callee
67+
itself — but no more! The documentation of a function should almost never contain _how_
68+
the function does it, the caller shouldn’t need to care.
69+
70+
If such a function documentation looks too convoluted, that’s a sign that the function’s interface
71+
is probably not right — the function boundary is in the wrong place, or an abstraction is missing
72+
to simplify the concepts.
73+
74+
Comments within function bodies should typically only document non-obvious implementation
75+
decisions, non-obvious constraints that require using one approach over another, or _sometimes_
76+
delineate significantly conceptually separate parts of the same function (definitely not
77+
after every blank line). It should not generally be necessary to document, in a caller, what calling another
78+
function does — if that is confusing, the callee should probably be renamed or refactored.

0 commit comments

Comments
 (0)