Skip to content

Commit 57b8407

Browse files
committed
Improved spelling, grammar and phrasing
1 parent 67fa480 commit 57b8407

File tree

3 files changed

+59
-14
lines changed

3 files changed

+59
-14
lines changed

guidelines.pdf

-8.77 KB
Binary file not shown.

src/chapters/api/documentation.typ

+40-4
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,56 @@
22
#import mantys: *
33

44
= 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.
66
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.
77

88
#wbox[
99
For the exact syntax used for documentation comments, refer to @sec:style:docs.
1010
]
1111

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.
1314
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
1651
Functions should also document their return type, even if it is general, such as `any`.
1752
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.
1853

54+
== States & Counters
1955
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.
2056
The type of the value itself should likewise be annotatd using the function return type syntax.
2157

src/chapters/style/documentation.typ

+19-10
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
Documentation is placed on special comments using three forward slashes `///` and an optional space.
1010
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 `///`.
1313

1414
#do-dont[
1515
```typst
@@ -68,7 +68,9 @@ Outer doc comments are placed right above the declaration they are attached to.
6868
```
6969
]
7070

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.
7274

7375
#do-dont[
7476
```typst
@@ -81,7 +83,7 @@ Inner doc comments are used to document modules and must not have a declaration,
8183
```
8284
][
8385
```typst
84-
/// Function or valtion doc
86+
/// Function or value doc
8587
#let item = { ... }
8688
8789
/// Stray doc comment, not the module or func doc
@@ -114,7 +116,7 @@ Outer doc comments may be used on `let` bindings only.
114116
]
115117

116118
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.
118120

119121
== Description
120122
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
129131

130132
Parameter description and return types (if present) are placed tightly together, property annotations if present are separated using another empty doc comment line.
131133

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.
135137

136138
#do-dont[
137139
```typst
@@ -173,8 +175,9 @@ Each parameter can only be documented once, but doesn't have to, undocumented pa
173175
```
174176
]
175177

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.
177179
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`.
178181

179182
#do-dont[
180183
```typst
@@ -184,6 +187,11 @@ For non function types the return type annotation can be used as a normal type a
184187
/// -> types
185188
#let func(arg) = { ... }
186189
190+
/// Function doc
191+
///
192+
/// -> types
193+
#let other = func.with(default)
194+
187195
/// Value doc
188196
///
189197
/// -> type
@@ -199,7 +207,8 @@ For non function types the return type annotation can be used as a normal type a
199207
```
200208
]
201209

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.
203212

204213
#do-dont[
205214
```typst

0 commit comments

Comments
 (0)