|
| 1 | +# fluxdoc formatting |
| 2 | + |
| 3 | +`fluxdoc` uses comments in `.flux` package files in `/stdlib` to generate and |
| 4 | +output standard library documentation in JSON format. |
| 5 | +The generated JSON is used to build the public-facing Flux standard library |
| 6 | +documentation and ensure documentation is up-to-date and featur-complete with |
| 7 | +each new Flux release. |
| 8 | + |
| 9 | +## Syntax and structure |
| 10 | +Each `.flux` package file in `/stdlib` should include comments using the |
| 11 | +following syntax and structure. |
| 12 | +Flux comment lines begin with `//`. |
| 13 | + |
| 14 | +### Use Markdown |
| 15 | +Inline Flux documentation uses Markdown or, more specifically, |
| 16 | +[CommonMark)](https://spec.commonmark.org/). |
| 17 | +For consistency, use the the following Markdown conventions: |
| 18 | + |
| 19 | +- `#` header syntax |
| 20 | +- `-` character for lists |
| 21 | +- Fenced codeblocks |
| 22 | + |
| 23 | +### Package summary documentation |
| 24 | +Add package summary documentation before the package statement in the `.flux` package file. |
| 25 | +Package summary documentation consists of a **headline**, **description**, |
| 26 | +**examples**, and **metadata** to be used by clients when consuming the JSON `fluxdoc` output. |
| 27 | + |
| 28 | +- **headline**: _First paragraph_ of the package documentation that describes |
| 29 | + what the package does. Must begin with `Package <pkg-name>`. |
| 30 | +- **description** _(Optional)_: All paragraphs between the first paragraph and |
| 31 | + optional metadata. Provides additional details about the package. |
| 32 | +- **examples** _(Optional)_: _See [Package and function examples](#package-and-function-examples)._ |
| 33 | +- **metadata** _(Optional)_: Metadata that provides helpful information about |
| 34 | + the package. _See [Package metadata](#package-metadata)_. |
| 35 | + |
| 36 | +#### Package metadata |
| 37 | +Package metadata are string key-value pairs separated by `:`. |
| 38 | +Each key-value pair must be on a single line. |
| 39 | + |
| 40 | +- **introduced**: Flux version the package was added _(Strongly encouraged)_. |
| 41 | +- **deprecated**: Flux version the package was deprecated. |
| 42 | +- **tags**: Comma-separated list of tags used to associate related documentation |
| 43 | + and categorize packages. _See [Metadata tags](#metadata-tags)._ |
| 44 | +- **contributors**: Contributor GitHub usernames or other contact information. |
| 45 | + |
| 46 | +```js |
| 47 | +// Package examplePkg provides functions that do x and y. |
| 48 | +// |
| 49 | +// Package description with additional details not provided in the headline. |
| 50 | +// |
| 51 | +// ## Examples |
| 52 | +// ``` |
| 53 | +// import "examplePkg" |
| 54 | +// |
| 55 | +// examplePkg.foo() |
| 56 | +// ``` |
| 57 | +// |
| 58 | +// introduced: 0.123.0 |
| 59 | +// tags: tag1,tag2,tag3 |
| 60 | +// contributors: [@someuser](https://github.com/someuser) (GitHub) |
| 61 | +package examplePkg |
| 62 | +``` |
| 63 | + |
| 64 | +### Function documentation |
| 65 | +Add function documentation before the function definition in the `.flux` package file. |
| 66 | +Function documentation consists of a **headline**, **description**, |
| 67 | +**parameters**, **examples**, and **metadata** to be used by clients when |
| 68 | +consuming the JSON `fluxdoc` output. |
| 69 | + |
| 70 | +- **headline**: _First paragraph_ of the function documentation that describes |
| 71 | + what the function does. Must begin with the _function name_ (case sensitive). |
| 72 | +- **description** _(Optional)_: All paragraphs between the first paragraph and |
| 73 | + parameters. Provides additional details about the function. |
| 74 | +- **parameters**: _See [Function parameters](#function-parameters)._ |
| 75 | +- **examples**: _(Optional)_: _See [Package and function examples](#package-and-function-examples)._ |
| 76 | +- **metadata** _(Optional)_: Metadata that provides helpful information about |
| 77 | + the package. _See [Function metadata](#function-metadata)._ |
| 78 | + |
| 79 | +#### Function parameters |
| 80 | +Identify the beginning of the parameter list with the `## Parameters` header. |
| 81 | +List parameters as a markdown unordered list. |
| 82 | +Each list item must follow these conventions: |
| 83 | + |
| 84 | +- Use the `-` character when formatting the list. |
| 85 | +- Begin each item with the parameter name (case-sensitive) followed by a colon (`:`). |
| 86 | +- Provide a description of the parameter after the parameter name and colon. |
| 87 | + |
| 88 | +##### Parameter description guidelines |
| 89 | +- The first paragraph of the parameter description is used as the short description. |
| 90 | +- The first paragraph and all subsequent content are used as the long description. |
| 91 | +- Parameter descriptions can contain any valid markdown. |
| 92 | + If there are multiple paragraphs, lists, or other elements that need to be |
| 93 | + included in the description, indent them them under the parameter list item to |
| 94 | + nest them as part of the parameter description. |
| 95 | +- Avoid starting parameter descriptions with an article (the, a, an). |
| 96 | + For example: |
| 97 | + |
| 98 | + ```md |
| 99 | + <!-- Not recommended --> |
| 100 | + - param: The value to multiply. |
| 101 | + - param: A value to multiply. |
| 102 | + |
| 103 | + <!-- Recommended --> |
| 104 | + - param: Value to multiply. |
| 105 | + ``` |
| 106 | +- If a parameter has a default value, specify the default in the description |
| 107 | + with "Default is `defaultValue`." |
| 108 | + |
| 109 | +#### Package and function examples |
| 110 | +Identify the beginning of the examples list with the `## Examples` header. |
| 111 | +Identify each example with a descriptive title formatted as an h3 header |
| 112 | +(`### Example descriptive title`). |
| 113 | + |
| 114 | +##### Example guidelines |
| 115 | +- In example titles, use imperative voice and avoid gerunds (verbs ending in |
| 116 | + "ing" and used as a noun). For example, use "Filter by tag" instead of |
| 117 | + "Filtering by tag." |
| 118 | +- Use fenced code blocks to identify the example code. |
| 119 | +- If an example uses a syntax other than Flux, include the language identifier |
| 120 | + with the fenced codeblock. If the Flux example should not be executed, use |
| 121 | + `no_run` as the language identifier. |
| 122 | +- Examples should pass the `flux fmt` formatting check. |
| 123 | + |
| 124 | +##### Example execution, input, and output |
| 125 | +Each example, if possible, should be able to be run as a standalone script. |
| 126 | +This allows Flux to actually execute the examples to both test the validity of |
| 127 | +the example and provide actual example input and output. |
| 128 | +Use the `array`, `csv`, or `sampledata` packages to include data as part of the |
| 129 | +examples. |
| 130 | + |
| 131 | +Use the following conventions to control example execution, input, and output. |
| 132 | + |
| 133 | +- `# ` omits the line from the rendered example, but keeps the line during example execution. |
| 134 | +- `< ` at the beginning of a line appends a `yield` to the end of the line to specify input. |
| 135 | + The `input` yield is parsed into Markdown tables and included with the JSON documentation output. |
| 136 | +- `> ` at the beginning of a line appends a `yield` to the ind of the line to specify output. |
| 137 | + The `output` yield is parsed into Markdown tables and included with the JSON documentation output. |
| 138 | +- To skip example execution, use the `no_run` language identifier on the code block. |
| 139 | + |
| 140 | +```js |
| 141 | +// ## Examples |
| 142 | +// |
| 143 | +// ### Filter by tag value |
| 144 | +// ``` |
| 145 | +// # import "sampledata" |
| 146 | +// |
| 147 | +// < sampledata.float() |
| 148 | +// > |> filter(fn: (r) => r.tag == "t1") |
| 149 | +// ``` |
| 150 | +``` |
| 151 | + |
| 152 | +#### Function metadata |
| 153 | +Function metadata are string key-value pairs separated by `:`. |
| 154 | +Each key-value pair must be on a single line. |
| 155 | + |
| 156 | +- **introduced**: Flux version the function was added _(if different than the package)_. |
| 157 | +- **deprecated**: Flux version the function was deprecated _(if different than the package)_. |
| 158 | +- **tags**: Comma-separated list of tags used to associate related documentation |
| 159 | + and categorize functions. _See [Metadata tags](#metadata-tags)._ |
| 160 | + |
| 161 | +### Metadata tags |
| 162 | +While tags are somewhat arbitrary, some are used to categorize functions. |
| 163 | +Use the following tags to categorize functions based on their usage and functionality: |
| 164 | + |
| 165 | +- **aggregates**: Add to aggregate functions (functions that aggregate all rows |
| 166 | + in a table into a single row). |
| 167 | +- **date/time**: Add to date/time-related functions. |
| 168 | +- **dynamic queries**: Add to functions that convert streams of tables into |
| 169 | + another composite or basic type. |
| 170 | +- **filters**: Add to functions that filter data. |
| 171 | +- **geotemporal**: Add to geotemporal-related functions. |
| 172 | +- **GIS**: Add to GIS-related functions. |
| 173 | +- **inputs**: Add to functions the retrieve data from a data source. |
| 174 | +- **metadata**: Add to functions that return metadata from input tables or a |
| 175 | + data source. |
| 176 | +- **notification endpoints**: Add to notification endpoint functions. |
| 177 | +- **outputs**: Add to functions to output data to a data source. |
| 178 | +- **sample data**: Add to functions the provide sample data. |
| 179 | +- **selectors**: Add to selector functions (functions that select rows from each |
| 180 | + input table). |
| 181 | +- **single notification**: Add to functions that send a single notification. |
| 182 | +- **tests**: Add to functions that perform tests. |
| 183 | +- **transformations**: Add to transformations (functions that take a stream of |
| 184 | + tables as input and output a stream of tables). |
| 185 | +- **type-conversions**: Add to functions that change data types. |
| 186 | + |
| 187 | +## Full package documentation example |
| 188 | +```js |
| 189 | +// Package pkgName provides functions that do x and y. |
| 190 | +// |
| 191 | +// ## Examples |
| 192 | +// ``` |
| 193 | +// import "pkgName" |
| 194 | +// |
| 195 | +// option pkgName.foo == "bar' |
| 196 | +// ``` |
| 197 | +// |
| 198 | +// introduced: 0.140.0 |
| 199 | +// contributors: [@username](https://github.com/username/) (GitHub) |
| 200 | +package pkgName |
| 201 | + |
| 202 | +// myFn multiplies `x` by `y`. |
| 203 | +// |
| 204 | +// ## Parameters |
| 205 | +// - x: Left operand. |
| 206 | +// - y: Right operand. |
| 207 | +// |
| 208 | +// ## Examples |
| 209 | +// |
| 210 | +// ### Multiply x and y |
| 211 | +// ```no_run |
| 212 | +// import "pkgName" |
| 213 | +// |
| 214 | +// pkgName.myFn(x: 2, y: 4) |
| 215 | +// // Returns 8 |
| 216 | +// ``` |
| 217 | +// |
| 218 | +myFn = (x, y) => x * y |
| 219 | + |
| 220 | +// anotherFn drops columns from input tables. |
| 221 | +// |
| 222 | +// ## Parameters |
| 223 | +// - columns: List of columns to drop. |
| 224 | +// - tables: Input data. Default is piped-forward data. |
| 225 | +// |
| 226 | +// ## Examples |
| 227 | +// |
| 228 | +// ### Drop specific columns |
| 229 | +// ``` |
| 230 | +// import "sampledata" |
| 231 | +// import "pkgName" |
| 232 | +// |
| 233 | +// < sampledata.float() |
| 234 | +// > |> pkgName.anotherFn(columns: [tag]) |
| 235 | +// ``` |
| 236 | +// |
| 237 | +// introduced: 0.141.0 |
| 238 | +// tags: transformations |
| 239 | +anotherFn = (columns, tables=<-) => tables |> drop(columns: columns) |
| 240 | +``` |
0 commit comments