Skip to content

docs: fix lost description texts #836

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

Merged
merged 7 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/.vitepress/theme/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ table td * {
display: inline;
}

table td ul {
display: block;
}

table td ul li {
display: list-item;
}

.nav-bar-title .logo {
min-height: 2rem;
}
9 changes: 6 additions & 3 deletions scripts/apidoc/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,17 @@ function extractDefaultFromComment(comment?: Comment): string {
if (!comment) {
return;
}
const text = comment.shortText;
if (!text || text.trim() === '') {
const text = comment.shortText?.trim();
if (!text) {
return;
}
const result = /(.*)[ \n]Defaults to `([^`]+)`./.exec(text);
const result = /^(.*)[ \n]Defaults to `([^`]+)`\.(.*)$/s.exec(text);
if (!result) {
return;
}
if (result[3].trim()) {
throw new Error(`Found description text after the default value:\n${text}`);
}
comment.shortText = result[1];
return result[2];
}
4 changes: 2 additions & 2 deletions src/internet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Internet {
* @param lastName The optional last name to use. If not specified, a random one will be chosen.
* @param provider The mail provider domain to use. If not specified, a random free mail provider will be chosen.
* @param options The options to use. Defaults to `{ allowSpecialCharacters: false }`.
* @param options.allowSpecialCharacters Whether special characters such as `.!#$%&'*+-/=?^_`{|}~` should be included
* @param options.allowSpecialCharacters Whether special characters such as ``.!#$%&'*+-/=?^_`{|}~`` should be included
* in the email address. Defaults to `false`.
*
* @example
Expand Down Expand Up @@ -75,7 +75,7 @@ export class Internet {
* @param firstName The optional first name to use. If not specified, a random one will be chosen.
* @param lastName The optional last name to use. If not specified, a random one will be chosen.
* @param options The options to use. Defaults to `{ allowSpecialCharacters: false }`.
* @param options.allowSpecialCharacters Whether special characters such as `.!#$%&'*+-/=?^_`{|}~` should be included
* @param options.allowSpecialCharacters Whether special characters such as ``.!#$%&'*+-/=?^_`{|}~`` should be included
* in the email address. Defaults to `false`.
*
* @example
Expand Down
4 changes: 3 additions & 1 deletion src/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ export class Time {
/**
* Returns recent time.
*
* @param format The format to use. Defaults to `'unix'`.
* @param format The format to use.
*
* - `'abbr'` Return a string with only the time. `Date.toLocaleTimeString`.
* - `'date'` Return a date instance.
* - `'wide'` Return a string with a long time. `Date.toTimeString()`.
* - `'unix'` Returns a unix timestamp.
*
* Defaults to `'unix'`.
*
* @example
* faker.time.recent() // 1643067231856
* faker.time.recent('abbr') // '12:34:07 AM'
Expand Down
19 changes: 12 additions & 7 deletions test/scripts/apidoc/signature.example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,16 @@ export class SignatureTest {
* Test with a function parameters (inline types) with defaults.
*
* @param a Parameter with signature default.
* It also has a more complex description.
* @param a.value The number parameter.
* @param b Parameter with jsdocs default. Defaults to `{ value: 1 }`.
* @param b.value The boolean parameter.
* @param b Parameter with jsdocs default.
*
* It also has a more complex description.
*
* Defaults to `{ value: 1 }`.
* @param b.value The number parameter.
* @param c Parameter with inner jsdocs default.
* @param c.value The boolean parameter. Defaults to `2`.
* @param c.value The number parameter. It also has a more complex description. Defaults to `2`.
*/
optionsInlineParamMethodWithDefaults(
a: { value?: number } = { value: 1 },
Expand All @@ -175,9 +180,9 @@ export class SignatureTest {
* @param a Parameter with signature default.
* @param a.value The number parameter.
* @param b Parameter with jsdocs default. Defaults to `{ value: 1 }`.
* @param b.value The boolean parameter.
* @param b.value The number parameter.
* @param c Parameter with inner jsdocs default.
* @param c.value The boolean parameter. Defaults to `2`.
* @param c.value The number parameter. Defaults to `2`.
*/
optionsTypeParamMethodWithDefaults(
a: ParameterOptionsTypeA = { value: 1 },
Expand All @@ -193,9 +198,9 @@ export class SignatureTest {
* @param a Parameter with signature default.
* @param a.value The number parameter.
* @param b Parameter with jsdocs default. Defaults to `{ value: 1 }`.
* @param b.value The boolean parameter.
* @param b.value The number parameter.
* @param c Parameter with inner jsdocs default.
* @param c.value The boolean parameter. Defaults to `2`.
* @param c.value The number parameter. Defaults to `2`.
*/
optionsInterfaceParamMethodWithDefaults(
a: ParameterOptionsInterfaceA = { value: 1 },
Expand Down
8 changes: 4 additions & 4 deletions test/scripts/apidoc/signature.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
"name": "a",
"type": "{ ... }",
"default": "{ value: 1 }",
"description": "<p>Parameter with signature default.</p>\n"
"description": "<p>Parameter with signature default.\nIt also has a more complex description.</p>\n"
},
{
"name": "a.value?",
Expand All @@ -141,12 +141,12 @@
"name": "b",
"type": "{ ... }",
"default": "{ value: 1 }",
"description": "<p>Parameter with jsdocs default.</p>\n"
"description": "<p>Parameter with jsdocs default.</p>\n<p>It also has a more complex description.</p>\n"
},
{
"name": "b.value?",
"type": "number",
"description": "<p>The boolean parameter.</p>\n"
"description": "<p>The number parameter.</p>\n"
},
{
"name": "c",
Expand All @@ -157,7 +157,7 @@
"name": "c.value?",
"type": "number",
"default": "2",
"description": "<p>The boolean parameter.</p>\n"
"description": "<p>The number parameter. It also has a more complex description.</p>\n"
}
],
"returns": "number",
Expand Down