Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(contributing): jsdocs section #1104

Merged
merged 14 commits into from Jun 30, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
127 changes: 127 additions & 0 deletions CONTRIBUTING.md
Expand Up @@ -71,6 +71,133 @@ get cat() {
}
```

## JSDocs

JSDoc are comments above any code structure (variable, function, class, etc.) that begin with `/**` and end with `*/`. Multiline comments start (if not being the start or end line) with a `*`.
For more info checkout [jsdoc.app](https://jsdoc.app/about-getting-started.html).

JSDoc will be read and automatically processed by generate:api-docs and therefore need to follow some project conventions. Other standards are in place because we think they provide a better code quality in general.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

> We use eslint-plugin-jsdoc to test for rough style and sorting of doc-tags.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

This is in place so all JSDoc decorators will get sorted automatically, so you don't have to bother with it. This also means that most rules in this section can get auto fixed by the eslint formatter.

> JSDocs should always be multiline

While single line JSDoc are technically valid, we decided to follow this rule since it makes changes in the git difference much more clear and easier to understand.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

<table>
<tr>
<th>Do</th>
<th>Dont</th>
</tr>
<tr>
<td>

```ts
/**
* This is a good JSDoc description.
*/
function foo() {
// implementation
}
```

</td>
<td>

```ts
/** This is a bad JSDoc description. */
function foo() {
// implementation
}
```

</td>
</tr>
</table>

> Everything that can be accessed directly by a user should have JSDoc.

This rule is aimed to target anything that is exported from the faker library. This includes types, interfaces, functions, classes and variables. So if you introduce anything new that is not internal, write JSDoc for it.

> If a `@param` has a default value, it needs to be mentioned at the end of the sentence.

```ts
/**
* This is a good JSDoc description.
*
* @param bar this is a parameter description. Defaults to `0`.
*/
function foo(bar: number = 0) {
// implementation
}
```
ST-DDT marked this conversation as resolved.
Show resolved Hide resolved

> If a fucntion can throw an error (FakerError) you have to include the `@throws` decorator with an explanation when an error could be thrown
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

```ts
/**
* This is a good JSDoc description.
*
* @param bar this is a parameter description. Defaults to `0`.
*
* @throws If bar is negative.
*/
function foo(bar: number = 0) {
// implementation
}
```

> Sentences should always end with a period.

This rule ensures a minimal grammatically correctness in the comments and ensures that all comments look the same.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

> Different decorators have to be separated by an empty line.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved

<table>
<tr>
<th>Do</th>
<th>Dont</th>
</tr>
<tr>
<td>

```ts
/**
* This is a good JSDoc description.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
* @param a The first summand.
* @param b The second summand.
* @example sum(1, 1) // 2
* @example sum(13, 56) // 69
*/
function sum(a: number, b: number): string {
// implementation
}
```

</td>
<td>

```ts
/**
* This is a good JSDoc description.
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
*
* @param a The first summand.
* @param b The second summand.
*
* @example sum(1, 1) // 2
* @example sum(13, 56) // 69
*/
xDivisionByZerox marked this conversation as resolved.
Show resolved Hide resolved
function foo(): string {
// implementation
}
```

</td>
</tr>
</table>

## Developing the docs

Before running the docs, build the Faker dist, it's used inside of certain routes.
Expand Down