Skip to content

Commit b99bbb5

Browse files
authored
docs: fix lost description texts (#836)
1 parent 00b9d4b commit b99bbb5

File tree

6 files changed

+35
-17
lines changed

6 files changed

+35
-17
lines changed

docs/.vitepress/theme/index.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ table td * {
22
display: inline;
33
}
44

5+
table td ul {
6+
display: block;
7+
}
8+
9+
table td ul li {
10+
display: list-item;
11+
}
12+
513
.nav-bar-title .logo {
614
min-height: 2rem;
715
}

scripts/apidoc/signature.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,17 @@ function extractDefaultFromComment(comment?: Comment): string {
301301
if (!comment) {
302302
return;
303303
}
304-
const text = comment.shortText;
305-
if (!text || text.trim() === '') {
304+
const text = comment.shortText?.trim();
305+
if (!text) {
306306
return;
307307
}
308-
const result = /(.*)[ \n]Defaults to `([^`]+)`./.exec(text);
308+
const result = /^(.*)[ \n]Defaults to `([^`]+)`\.(.*)$/s.exec(text);
309309
if (!result) {
310310
return;
311311
}
312+
if (result[3].trim()) {
313+
throw new Error(`Found description text after the default value:\n${text}`);
314+
}
312315
comment.shortText = result[1];
313316
return result[2];
314317
}

src/internet.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class Internet {
4747
* @param lastName The optional last name to use. If not specified, a random one will be chosen.
4848
* @param provider The mail provider domain to use. If not specified, a random free mail provider will be chosen.
4949
* @param options The options to use. Defaults to `{ allowSpecialCharacters: false }`.
50-
* @param options.allowSpecialCharacters Whether special characters such as `.!#$%&'*+-/=?^_`{|}~` should be included
50+
* @param options.allowSpecialCharacters Whether special characters such as ``.!#$%&'*+-/=?^_`{|}~`` should be included
5151
* in the email address. Defaults to `false`.
5252
*
5353
* @example
@@ -90,7 +90,7 @@ export class Internet {
9090
* @param firstName The optional first name to use. If not specified, a random one will be chosen.
9191
* @param lastName The optional last name to use. If not specified, a random one will be chosen.
9292
* @param options The options to use. Defaults to `{ allowSpecialCharacters: false }`.
93-
* @param options.allowSpecialCharacters Whether special characters such as `.!#$%&'*+-/=?^_`{|}~` should be included
93+
* @param options.allowSpecialCharacters Whether special characters such as ``.!#$%&'*+-/=?^_`{|}~`` should be included
9494
* in the email address. Defaults to `false`.
9595
*
9696
* @example

src/time.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@ export class Time {
1010
/**
1111
* Returns recent time.
1212
*
13-
* @param format The format to use. Defaults to `'unix'`.
13+
* @param format The format to use.
1414
*
1515
* - `'abbr'` Return a string with only the time. `Date.toLocaleTimeString`.
1616
* - `'date'` Return a date instance.
1717
* - `'wide'` Return a string with a long time. `Date.toTimeString()`.
1818
* - `'unix'` Returns a unix timestamp.
1919
*
20+
* Defaults to `'unix'`.
21+
*
2022
* @example
2123
* faker.time.recent() // 1643067231856
2224
* faker.time.recent('abbr') // '12:34:07 AM'

test/scripts/apidoc/signature.example.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,16 @@ export class SignatureTest {
155155
* Test with a function parameters (inline types) with defaults.
156156
*
157157
* @param a Parameter with signature default.
158+
* It also has a more complex description.
158159
* @param a.value The number parameter.
159-
* @param b Parameter with jsdocs default. Defaults to `{ value: 1 }`.
160-
* @param b.value The boolean parameter.
160+
* @param b Parameter with jsdocs default.
161+
*
162+
* It also has a more complex description.
163+
*
164+
* Defaults to `{ value: 1 }`.
165+
* @param b.value The number parameter.
161166
* @param c Parameter with inner jsdocs default.
162-
* @param c.value The boolean parameter. Defaults to `2`.
167+
* @param c.value The number parameter. It also has a more complex description. Defaults to `2`.
163168
*/
164169
optionsInlineParamMethodWithDefaults(
165170
a: { value?: number } = { value: 1 },
@@ -175,9 +180,9 @@ export class SignatureTest {
175180
* @param a Parameter with signature default.
176181
* @param a.value The number parameter.
177182
* @param b Parameter with jsdocs default. Defaults to `{ value: 1 }`.
178-
* @param b.value The boolean parameter.
183+
* @param b.value The number parameter.
179184
* @param c Parameter with inner jsdocs default.
180-
* @param c.value The boolean parameter. Defaults to `2`.
185+
* @param c.value The number parameter. Defaults to `2`.
181186
*/
182187
optionsTypeParamMethodWithDefaults(
183188
a: ParameterOptionsTypeA = { value: 1 },
@@ -193,9 +198,9 @@ export class SignatureTest {
193198
* @param a Parameter with signature default.
194199
* @param a.value The number parameter.
195200
* @param b Parameter with jsdocs default. Defaults to `{ value: 1 }`.
196-
* @param b.value The boolean parameter.
201+
* @param b.value The number parameter.
197202
* @param c Parameter with inner jsdocs default.
198-
* @param c.value The boolean parameter. Defaults to `2`.
203+
* @param c.value The number parameter. Defaults to `2`.
199204
*/
200205
optionsInterfaceParamMethodWithDefaults(
201206
a: ParameterOptionsInterfaceA = { value: 1 },

test/scripts/apidoc/signature.expected.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"name": "a",
131131
"type": "{ ... }",
132132
"default": "{ value: 1 }",
133-
"description": "<p>Parameter with signature default.</p>\n"
133+
"description": "<p>Parameter with signature default.\nIt also has a more complex description.</p>\n"
134134
},
135135
{
136136
"name": "a.value?",
@@ -141,12 +141,12 @@
141141
"name": "b",
142142
"type": "{ ... }",
143143
"default": "{ value: 1 }",
144-
"description": "<p>Parameter with jsdocs default.</p>\n"
144+
"description": "<p>Parameter with jsdocs default.</p>\n<p>It also has a more complex description.</p>\n"
145145
},
146146
{
147147
"name": "b.value?",
148148
"type": "number",
149-
"description": "<p>The boolean parameter.</p>\n"
149+
"description": "<p>The number parameter.</p>\n"
150150
},
151151
{
152152
"name": "c",
@@ -157,7 +157,7 @@
157157
"name": "c.value?",
158158
"type": "number",
159159
"default": "2",
160-
"description": "<p>The boolean parameter.</p>\n"
160+
"description": "<p>The number parameter. It also has a more complex description.</p>\n"
161161
}
162162
],
163163
"returns": "number",

0 commit comments

Comments
 (0)