You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/chapters/api/documentation.typ
+40-4
Original file line number
Diff line number
Diff line change
@@ -2,20 +2,56 @@
2
2
#importmantys: *
3
3
4
4
= Documentation <sec:api:docs>
5
-
Documentaiton comemnts are important for consumers of the API as well as new contributors to your package or project to understand the usage and purpose of an item.
5
+
Documentation comments are important for consumers of the API as well as new contributors to your package or project to understand the usage and purpose of an item.
6
6
An item may be a state variable, a counter, a function, a reusable piece of regular content, or anything that can be bound using a `let` statement.
7
7
8
8
#wbox[
9
9
For the exact syntax used for documentation comments, refer to @sec:style:docs.
10
10
]
11
11
12
-
For public functions the documentation should always incldue all public parameters, their usage and purpose as well as possible constraints on their values.
12
+
== Visibility
13
+
For public functions the documentation should always include all public parameters, their usage and purpose, as well as possible constraints on their values.
13
14
Internal arguments may be ommited, if they are not meant to be exposed to a user, but should still be documented for contributors in the source or a contribution document.
14
-
Depending on the doc aprser in use, named arguments may need their defaults explicitly stated and should have if the doc parser can't parse them automatically.
15
-
If functions require or return contextual values, this should also be communicated clearly.
15
+
Only optional arguments may be internal, required arguments must always be documented and therefore public.
16
+
17
+
== Defaults
18
+
Defaults values should not be documented if they are simple expressions such as `"default"` or `5`.
19
+
If default values refer to more complex expressions or bindings form other modules which are not evident from the context of the documentation, then they should be documented in some way.
20
+
21
+
#do-dont[
22
+
```typst
23
+
// - a default is not documented when not necessary
24
+
// - usage of internal default binding default-b is documented and explained
25
+
26
+
/// Function doc
27
+
///
28
+
/// / a (): A doc.
29
+
/// / b (): B doc, defaults to ...
30
+
#let func(a: 5, b: internal.default-b) = { ... }
31
+
```
32
+
][
33
+
```typst
34
+
// - a default is unecessarily documented
35
+
// - user may not know what the default of b refers to
36
+
37
+
/// Function doc
38
+
///
39
+
/// / a (): A doc, defaults to 5.
40
+
/// / b (): B doc.
41
+
#let func(a: 5, b: internal.default-b) = { ... }
42
+
```
43
+
]
44
+
45
+
== Annotations
46
+
Implicit requirements such as contexts should be documented using property annotations (see @sec:style:docs).
47
+
Other annotations may be used to document additional invariants such as visibility or deprecation status.
48
+
Consider elaborating on all unconventional uses of property annotations in your documentation.
49
+
50
+
== Return Values
16
51
Functions should also document their return type, even if it is general, such as `any`.
17
52
Should a function return different types depending on it's inputs or the state of the document, it must be documented when this may happen or at least which types to expect and check for at the call site.
18
53
54
+
== States & Counters
19
55
Values like states and counters, if exposed, should document their invariants, such as the allowed types for states or the expected depth range of a counter for example.
20
56
The type of the value itself should likewise be annotatd using the function return type syntax.
Copy file name to clipboardexpand all lines: src/chapters/style/documentation.typ
+19-10
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,8 @@
8
8
9
9
Documentation is placed on special comments using three forward slashes `///` and an optional space.
10
10
These are called doc comments.
11
-
While the leading space is optional, it is encouraged as it makes the documentaiton easier to read.
12
-
Doc comments may not be interrupted by empty lines, markup, or regular comments.
11
+
While the leading space is optional, it is encouraged, as it makes the documentation easier to read.
12
+
Doc comments may not be interrupted by empty lines, markup, or regular comments, i.e. a blokc of documenation must be one continuous sequence of lines starting with three forward slashes `///`.
13
13
14
14
#do-dont[
15
15
```typst
@@ -68,7 +68,9 @@ Outer doc comments are placed right above the declaration they are attached to.
68
68
```
69
69
]
70
70
71
-
Inner doc comments are used to document modules and must not have a declaration, instead they refer to the file they are placed in and may only be declared once and as the first non comment item in a file.
71
+
Inner doc comments are used to document modules and must not have a declaration, instead they refer to the file they are placed in and may only be declared once and as the first non-comment item in a file.
72
+
There may be regular comments before doc comments to allow placing internal documentation or license information at the top of the file.
73
+
Inner doc comments are currently not permitted anywhere else.
72
74
73
75
#do-dont[
74
76
```typst
@@ -81,7 +83,7 @@ Inner doc comments are used to document modules and must not have a declaration,
81
83
```
82
84
][
83
85
```typst
84
-
/// Function or valtion doc
86
+
/// Function or value doc
85
87
#let item = { ... }
86
88
87
89
/// Stray doc comment, not the module or func doc
@@ -114,7 +116,7 @@ Outer doc comments may be used on `let` bindings only.
114
116
]
115
117
116
118
Doc comments contain a description of the documented item itself, as well as an optional semantic trailer.
117
-
The content of descriptions should generally be simple Typst markup and should not contain any scripting, (i.e. no loops, conditionals or function calls, except for `#link("...")[...]`), this allows the documentation to be turned into Markdown or plaintext or LSP to send to editors.
119
+
The content of descriptions should generally be simple Typst markup and should not contain any scripting, (i.e. no loops, conditionals or function calls, except for `#link("...")[...]`), this allows the documentation to be turned into markdown or plain text for language servers to send to editors.
118
120
119
121
== Description
120
122
As mentioned before, the description should be simple, containing mostly markup and no scripting.
@@ -129,9 +131,9 @@ Types in type lists or return type annotations may be separated by `|` to indica
129
131
130
132
Parameter description and return types (if present) are placed tightly together, property annotations if present are separated using another empty doc comment line.
131
133
132
-
Parameter documentation is created by writing a term item containing the parameter name, a mandatory type list in parenthesis and optional description.
133
-
If the parameter is an argument sink it's name must also containe the spread operator `..`.
134
-
Each parameter can only be documented once, but doesn't have to, undocumented parameters are considered private.
134
+
Parameter documentation is created by writing a term item containing the parameter name, a mandatory type list in parentheses and optional description.
135
+
If the parameter is an argument sink its name must likewise contain the spread operator `..`.
136
+
Each parameter can only be documented once, but doesn't have to, undocumented parameters are considered private by convention and may only optional parameters.
135
137
136
138
#do-dont[
137
139
```typst
@@ -173,8 +175,9 @@ Each parameter can only be documented once, but doesn't have to, undocumented pa
173
175
```
174
176
]
175
177
176
-
The return type can only be annotated once, on a single line after all parameters if any exist.
178
+
The return type can only be annotated once, on a single line after all parameters, if any exist.
177
179
For non function types the return type annotation can be used as a normal type annotation.
180
+
Items which bind a `function.with` expression should be treated as regular function definitions, i.e. their return type is the return type of the function when called, not `function` itself as would be the return value of `function.with`.
178
181
179
182
#do-dont[
180
183
```typst
@@ -184,6 +187,11 @@ For non function types the return type annotation can be used as a normal type a
184
187
/// -> types
185
188
#let func(arg) = { ... }
186
189
190
+
/// Function doc
191
+
///
192
+
/// -> types
193
+
#let other = func.with(default)
194
+
187
195
/// Value doc
188
196
///
189
197
/// -> type
@@ -199,7 +207,8 @@ For non function types the return type annotation can be used as a normal type a
199
207
```
200
208
]
201
209
202
-
Property annotations can be used to document package specific or otherwise important information like deprecation status, visibility or contextuality and may only be used after the return type (if one exists) and an empty doc comment line.
210
+
Property annotations can be used to document package specific or otherwise important information like deprecation status, visibility or contextuality.
211
+
Such annotations may only be used after the return type (if one exists) and an empty doc comment line.
0 commit comments