Skip to content

Commit e49ab0f

Browse files
committed
style: add a section on examples
addressing: * anchoring * content of example Signed-off-by: Vincent Batts <[email protected]>
1 parent 547e00b commit e49ab0f

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

style.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,64 @@ The redundancy reduction from removing the namespacing prefix is not useful enou
2121
So we have a consistent way to identify unset values ([source][optional-pointer]).
2222
The exceptions are entries where the Go default for the type is a no-op in the spec, in which case `omitempty` is sufficient and no pointer is needed (sources [here][no-pointer-for-slices], [here][no-pointer-for-boolean], and [here][pointer-when-updates-require-changes]).
2323

24+
## Examples
25+
26+
### Anchoring
27+
28+
For any given section that provides a notable example, it is ideal to have it denoted with [markdown headers][markdown-headers].
29+
The level of header should be such that it is a subheader of the header it is an example of.
30+
31+
#### Example
32+
33+
```markdown
34+
## some topic
35+
36+
### some subheader
37+
38+
#### further subheader
39+
40+
### Example
41+
42+
```
43+
44+
### Content
45+
46+
Where necessary, the values in the example can be empty or unset, but accommodate with comments regarding this intention.
47+
48+
Where feasible, the content and values used in an example should convey the fullest use of the data structures concerned.
49+
Most commonly onlookers will intend to copy-and-paste a "working example".
50+
If the intention of the example is to be a fully utilized example, rather than a copy-and-paste example, perhaps add a comment as such.
51+
52+
```markdown
53+
### Example
54+
```
55+
```json
56+
{
57+
"foo": null,
58+
"bar": ""
59+
}
60+
```
61+
62+
**vs.**
63+
64+
```markdown
65+
### Example
66+
67+
Following is a fully populated example (not necessarily for copy/paste use)
68+
```
69+
```json
70+
{
71+
"foo": [
72+
1,
73+
2,
74+
3
75+
],
76+
"bar": "waffles",
77+
"bif": {
78+
"baz": "potatoes"
79+
}
80+
}
81+
```
2482

2583
[capabilities]: config-linux.md#capabilities
2684
[class-id]: config-linux.md#network
@@ -30,3 +88,4 @@ The exceptions are entries where the Go default for the type is a no-op in the s
3088
[no-pointer-for-slices]: https://github.com/opencontainers/runtime-spec/pull/316/files#r50782982
3189
[optional-pointer]: https://github.com/opencontainers/runtime-spec/pull/233#discussion_r47829711
3290
[pointer-when-updates-require-changes]: https://github.com/opencontainers/runtime-spec/pull/317/files#r50932706
91+
[markdown-headers]: https://help.github.com/articles/basic-writing-and-formatting-syntax/#headings

0 commit comments

Comments
 (0)