Skip to content

Commit ae77abd

Browse files
committed
Update docs to add description about versioning and writing documentation
1 parent 402bc02 commit ae77abd

File tree

4 files changed

+97
-60
lines changed

4 files changed

+97
-60
lines changed

docs/src/modules/2-bundle/4-conventions/1-basic.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Neither default nor rest parameters are currently supported due to an [issue](ht
2929

3030
## 2. Cadet facing functions should not use array destructuring for parameters
3131

32-
Javascript allows us to pass destruct iterables directly within the function declaration:
32+
Javascript allows us to destruct iterables directly within a function's parameters:
3333

3434
```ts
3535
export function foo([x, y]: [string, string]) {
@@ -124,7 +124,22 @@ Lists are actually introduced in Source 1, which would make the above function c
124124
functionality specific to arrays, then consider using Source Lists instead.
125125
:::
126126
127-
## 4. Making use of `js-slang/stdlib`
127+
## 4. Semantic Versioning
128+
129+
[Semantic Versioning](https://semver.org) refers to a convention on how version numbers should be specified. In your bundle's `package.json`, a `version` field should
130+
be specified:
131+
132+
```jsonc {3}
133+
{
134+
"name": "@sourceacademy/bundle-bundle0",
135+
"version": "1.0.0"
136+
}
137+
```
138+
139+
This version number should follow the rules of semantic versioning. `js-slang` will use this version number to determine if it currently has the latest version of your bundle
140+
compatible with its current version.
141+
142+
## 5. Making use of `js-slang/stdlib`
128143
129144
Bundles, where necessary, should use the implementations of libraries such as `list` or `stream` from the `js-slang` standard library:
130145

docs/src/modules/2-bundle/5-documentation/5-documentation.md

Lines changed: 78 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ By reading comments and type annotations, `typedoc` is able to generate both hum
1111
1212
## Writing Documentation
1313

14-
`typedoc` reads both Typescript type annotations, as well as [TSDOC](https://tsdoc.org) style comments. It will build documentation for all functions and constants exported by the particular module.
14+
`typedoc` reads both Typescript type annotations, as well as [TSDOC](https://tsdoc.org) style comments. It will build documentation for all functions and constants exported by the particular bundle's entry point.
15+
For example, since the `curve` bundle exports the `make_point` function, `typedoc` will generate documentation for it. However, there are many other functions that the bundle does not expose that won't have documentation generated.
16+
17+
Documentation should be written in [Markdown](https://www.markdownguide.org/getting-started/). That way, both IntelliSense and Typedoc will be able to process it. During documentation generation,
18+
the markdown is converted to raw HTML.
1519

1620
::: details Type Aware annotations
1721
[JSDoc](https://jsdoc.app) (and TSDoc) both support annotations that express type information directly like `@type` or annotations that can optionally contain type information like `@param` and `@returns`.
@@ -23,7 +27,9 @@ so as not to confuse Typedoc and ensure that the Typescript compiler is able to
2327
If you do need to the type of an export to be documented differently from its type in Typescript source code, you can use a [type map](../7-type_map).
2428
:::
2529

26-
Let us look at an example from the `curve` module.
30+
Let us look at more examples from the `curve` module.
31+
32+
### Functions
2733

2834
```ts
2935
// functions.ts
@@ -43,66 +49,21 @@ export function make_point(x: number, y: number): Point {
4349
}
4450
```
4551

46-
```ts
47-
// index.ts
48-
export { make_point } from './functions.ts';
49-
```
50-
51-
Since the `curve` bundle exports the `make_point` function, `typedoc` will generate documentation for it.
52-
53-
Documentation should be written in [Markdown](https://www.markdownguide.org/getting-started/). That way, both IntelliSense and Typedoc will be able to process it. During documentation generation,
54-
the markdown is converted to raw HTML.
55-
56-
The following sections are conventions for writing documentation.
57-
58-
### Entry Point
59-
60-
At the entry point for each bundle, there should be a block comment that provides general information about the bundle.
61-
62-
This example is taken from the `repeat` bundle:
52+
Notice that in the example above, each `@param` tag is followed directly by the name of the parameter its describing, which is then followed
53+
by the description of the parameter itself.
6354

55+
Missing the documentation for a parameter is okay (not that you should), but trying to document a parameter that doesn't exist will cause a linting
56+
error:
6457
```ts
65-
// repeat/src/index.ts
6658
/**
67-
* Test bundle for Source Academy modules repository
68-
* @author Loh Xian Ze, Bryan
69-
* @author Tang Xin Kye, Marcus
70-
* @module repeat
59+
* Oops p1 isn't documented!
60+
* @param p3 This parameter doesn't exist and so this will cause a lint error!
7161
*/
72-
73-
export { repeat, twice, thrice } from './functions';
74-
```
75-
76-
It is important that you provide an `@module` tag in this description. Otherwise, the build tools may not be able to detect your bundle's
77-
documentation properly.
78-
79-
> [!TIP]
80-
> An ESLint Rule has been configured specifically for this purpose, so a lint error should appear if you forget to do so.
81-
82-
### Use of `@hidden`
83-
84-
If there are exports you want hidden from the output of the documentation, you must use the `@hidden` tag.
85-
86-
The example below is taken from the `rune` bundle:
87-
88-
```ts
89-
// rune/src/type_map.ts
90-
import createTypeMap from '@sourceacademy/modules-lib/type_map';
91-
92-
const typeMapCreator = createTypeMap();
93-
94-
export const { functionDeclaration, variableDeclaration, classDeclaration } = typeMapCreator;
95-
96-
/** @hidden */
97-
export const type_map = typeMapCreator.type_map;
62+
export function foo(p1: string, p2: string) {
63+
// ...implementation
64+
}
9865
```
9966

100-
This causes `type_map` to be removed from the documentation, even if it is exported from `rune/src/index.ts`.
101-
102-
> [!WARNING]
103-
> Bundle `type_map`s are supposed to be internal implementation details hidden from users. If you forget to apply a `@hidden` tag to
104-
> your bundle's type map export, the build tools will show a warning.
105-
10667
### Use of `@function`
10768

10869
Following v0.28, Typedoc only documents function-like types as functions if they are explicitly typed as functions (see the issue [here](https://github.com/TypeStrong/typedoc/issues/2881)).
@@ -168,6 +129,67 @@ The export will now be correctly recognized as a function:
168129

169130
There is no automatic way to make this distinction, so it is up to the bundle authors to make sure that this convention is adhered to.
170131

132+
### Variables/Constants
133+
134+
Constants can be documented in a similar fashion:
135+
```ts
136+
/**
137+
* Represents the mathematical constant PI
138+
*/
139+
const PI: number = 3.14159;
140+
```
141+
142+
Also similar to function return types and parameters, because the types of variables is determined by the Typescript compiler, it is unnecessary
143+
to use the `@type` tag here.
144+
145+
### Entry Point
146+
147+
At the entry point for each bundle, there should be a block comment that provides general information about the bundle.
148+
149+
This example is taken from the `repeat` bundle:
150+
151+
```ts
152+
// repeat/src/index.ts
153+
/**
154+
* Test bundle for Source Academy modules repository
155+
* @author Loh Xian Ze, Bryan
156+
* @author Tang Xin Kye, Marcus
157+
* @module repeat
158+
*/
159+
160+
export { repeat, twice, thrice } from './functions';
161+
```
162+
163+
It is important that you provide an `@module` tag in this description. Otherwise, the build tools may not be able to detect your bundle's
164+
documentation properly.
165+
166+
> [!TIP]
167+
> An ESLint Rule has been configured specifically for this purpose, so a lint error should appear if you forget to do so.
168+
169+
### Use of `@hidden`
170+
171+
If there are exports you want hidden from the output of the documentation, you must use the `@hidden` tag.
172+
173+
The example below is taken from the `rune` bundle:
174+
175+
```ts
176+
// rune/src/type_map.ts
177+
import createTypeMap from '@sourceacademy/modules-lib/type_map';
178+
179+
const typeMapCreator = createTypeMap();
180+
181+
export const { functionDeclaration, variableDeclaration, classDeclaration } = typeMapCreator;
182+
183+
/** @hidden */
184+
export const type_map = typeMapCreator.type_map;
185+
```
186+
187+
This causes `type_map` to be removed from the documentation, even if it is exported from `rune/src/index.ts`.
188+
189+
> [!WARNING]
190+
> Bundle `type_map`s are supposed to be internal implementation details hidden from users. If you forget to apply a `@hidden` tag to
191+
> your bundle's type map export, the build tools will show a warning.
192+
171193
### Other Tags
172194

173195
There are a variety of tags that Typedoc supports. This list can be found [here](https://typedoc.org/documents/Tags.html). When writing your documentation you should use these tags

docs/src/modules/3-tabs/3-editing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ You can also add the dependency directly by modifying your `package.json`:
5858
5959
```jsonc {4}
6060
{
61-
"name": "@sourceacademy/bundle-bundle0",
61+
"name": "@sourceacademy/tab-Tab0",
6262
"dependencies": {
6363
"lodash": "^4.0.0"
6464
}

src/bundles/binary_tree/src/__tests__/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { list } from 'js-slang/dist/stdlib/list';
12
import { describe, expect, it } from 'vitest';
23
import * as funcs from '../functions';
3-
import { list } from 'js-slang/dist/stdlib/list';
44

55
describe(funcs.is_tree, () => {
66
it('returns false when argument is not a tree', () => {

0 commit comments

Comments
 (0)