eslint-plugin-jsdoc 46.4.6 → 46.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/README.md +31 -0
  2. package/dist/index.js +21 -10
  3. package/dist/index.js.map +1 -1
  4. package/dist/jsdocUtils.js +1 -1
  5. package/dist/jsdocUtils.js.map +1 -1
  6. package/dist/rules/matchDescription.js +1 -1
  7. package/dist/rules/matchDescription.js.map +1 -1
  8. package/package.json +14 -12
  9. package/dist/WarnSettings.d.ts +0 -17
  10. package/dist/WarnSettings.d.ts.map +0 -1
  11. package/dist/alignTransform.d.ts +0 -32
  12. package/dist/alignTransform.d.ts.map +0 -1
  13. package/dist/defaultTagOrder.d.ts +0 -5
  14. package/dist/defaultTagOrder.d.ts.map +0 -1
  15. package/dist/exportParser.d.ts +0 -41
  16. package/dist/exportParser.d.ts.map +0 -1
  17. package/dist/getDefaultTagStructureForMode.d.ts +0 -11
  18. package/dist/getDefaultTagStructureForMode.d.ts.map +0 -1
  19. package/dist/index.d.ts +0 -10
  20. package/dist/index.d.ts.map +0 -1
  21. package/dist/iterateJsdoc.d.ts +0 -460
  22. package/dist/iterateJsdoc.d.ts.map +0 -1
  23. package/dist/jsdocUtils.d.ts +0 -421
  24. package/dist/jsdocUtils.d.ts.map +0 -1
  25. package/dist/rules/checkAccess.d.ts +0 -3
  26. package/dist/rules/checkAccess.d.ts.map +0 -1
  27. package/dist/rules/checkAlignment.d.ts +0 -3
  28. package/dist/rules/checkAlignment.d.ts.map +0 -1
  29. package/dist/rules/checkExamples.d.ts +0 -4
  30. package/dist/rules/checkExamples.d.ts.map +0 -1
  31. package/dist/rules/checkIndentation.d.ts +0 -3
  32. package/dist/rules/checkIndentation.d.ts.map +0 -1
  33. package/dist/rules/checkLineAlignment.d.ts +0 -10
  34. package/dist/rules/checkLineAlignment.d.ts.map +0 -1
  35. package/dist/rules/checkParamNames.d.ts +0 -3
  36. package/dist/rules/checkParamNames.d.ts.map +0 -1
  37. package/dist/rules/checkPropertyNames.d.ts +0 -3
  38. package/dist/rules/checkPropertyNames.d.ts.map +0 -1
  39. package/dist/rules/checkSyntax.d.ts +0 -3
  40. package/dist/rules/checkSyntax.d.ts.map +0 -1
  41. package/dist/rules/checkTagNames.d.ts +0 -3
  42. package/dist/rules/checkTagNames.d.ts.map +0 -1
  43. package/dist/rules/checkTypes.d.ts +0 -3
  44. package/dist/rules/checkTypes.d.ts.map +0 -1
  45. package/dist/rules/checkValues.d.ts +0 -3
  46. package/dist/rules/checkValues.d.ts.map +0 -1
  47. package/dist/rules/emptyTags.d.ts +0 -3
  48. package/dist/rules/emptyTags.d.ts.map +0 -1
  49. package/dist/rules/implementsOnClasses.d.ts +0 -3
  50. package/dist/rules/implementsOnClasses.d.ts.map +0 -1
  51. package/dist/rules/importsAsDependencies.d.ts +0 -3
  52. package/dist/rules/importsAsDependencies.d.ts.map +0 -1
  53. package/dist/rules/informativeDocs.d.ts +0 -3
  54. package/dist/rules/informativeDocs.d.ts.map +0 -1
  55. package/dist/rules/matchDescription.d.ts +0 -3
  56. package/dist/rules/matchDescription.d.ts.map +0 -1
  57. package/dist/rules/matchName.d.ts +0 -3
  58. package/dist/rules/matchName.d.ts.map +0 -1
  59. package/dist/rules/multilineBlocks.d.ts +0 -3
  60. package/dist/rules/multilineBlocks.d.ts.map +0 -1
  61. package/dist/rules/noBadBlocks.d.ts +0 -3
  62. package/dist/rules/noBadBlocks.d.ts.map +0 -1
  63. package/dist/rules/noBlankBlockDescriptions.d.ts +0 -3
  64. package/dist/rules/noBlankBlockDescriptions.d.ts.map +0 -1
  65. package/dist/rules/noBlankBlocks.d.ts +0 -3
  66. package/dist/rules/noBlankBlocks.d.ts.map +0 -1
  67. package/dist/rules/noDefaults.d.ts +0 -3
  68. package/dist/rules/noDefaults.d.ts.map +0 -1
  69. package/dist/rules/noMissingSyntax.d.ts +0 -10
  70. package/dist/rules/noMissingSyntax.d.ts.map +0 -1
  71. package/dist/rules/noMultiAsterisks.d.ts +0 -3
  72. package/dist/rules/noMultiAsterisks.d.ts.map +0 -1
  73. package/dist/rules/noRestrictedSyntax.d.ts +0 -3
  74. package/dist/rules/noRestrictedSyntax.d.ts.map +0 -1
  75. package/dist/rules/noTypes.d.ts +0 -3
  76. package/dist/rules/noTypes.d.ts.map +0 -1
  77. package/dist/rules/noUndefinedTypes.d.ts +0 -3
  78. package/dist/rules/noUndefinedTypes.d.ts.map +0 -1
  79. package/dist/rules/requireAsteriskPrefix.d.ts +0 -3
  80. package/dist/rules/requireAsteriskPrefix.d.ts.map +0 -1
  81. package/dist/rules/requireDescription.d.ts +0 -3
  82. package/dist/rules/requireDescription.d.ts.map +0 -1
  83. package/dist/rules/requireDescriptionCompleteSentence.d.ts +0 -3
  84. package/dist/rules/requireDescriptionCompleteSentence.d.ts.map +0 -1
  85. package/dist/rules/requireExample.d.ts +0 -3
  86. package/dist/rules/requireExample.d.ts.map +0 -1
  87. package/dist/rules/requireFileOverview.d.ts +0 -3
  88. package/dist/rules/requireFileOverview.d.ts.map +0 -1
  89. package/dist/rules/requireHyphenBeforeParamDescription.d.ts +0 -3
  90. package/dist/rules/requireHyphenBeforeParamDescription.d.ts.map +0 -1
  91. package/dist/rules/requireJsdoc.d.ts +0 -9
  92. package/dist/rules/requireJsdoc.d.ts.map +0 -1
  93. package/dist/rules/requireParam.d.ts +0 -4
  94. package/dist/rules/requireParam.d.ts.map +0 -1
  95. package/dist/rules/requireParamDescription.d.ts +0 -3
  96. package/dist/rules/requireParamDescription.d.ts.map +0 -1
  97. package/dist/rules/requireParamName.d.ts +0 -3
  98. package/dist/rules/requireParamName.d.ts.map +0 -1
  99. package/dist/rules/requireParamType.d.ts +0 -3
  100. package/dist/rules/requireParamType.d.ts.map +0 -1
  101. package/dist/rules/requireProperty.d.ts +0 -3
  102. package/dist/rules/requireProperty.d.ts.map +0 -1
  103. package/dist/rules/requirePropertyDescription.d.ts +0 -3
  104. package/dist/rules/requirePropertyDescription.d.ts.map +0 -1
  105. package/dist/rules/requirePropertyName.d.ts +0 -3
  106. package/dist/rules/requirePropertyName.d.ts.map +0 -1
  107. package/dist/rules/requirePropertyType.d.ts +0 -3
  108. package/dist/rules/requirePropertyType.d.ts.map +0 -1
  109. package/dist/rules/requireReturns.d.ts +0 -3
  110. package/dist/rules/requireReturns.d.ts.map +0 -1
  111. package/dist/rules/requireReturnsCheck.d.ts +0 -3
  112. package/dist/rules/requireReturnsCheck.d.ts.map +0 -1
  113. package/dist/rules/requireReturnsDescription.d.ts +0 -3
  114. package/dist/rules/requireReturnsDescription.d.ts.map +0 -1
  115. package/dist/rules/requireReturnsType.d.ts +0 -3
  116. package/dist/rules/requireReturnsType.d.ts.map +0 -1
  117. package/dist/rules/requireThrows.d.ts +0 -3
  118. package/dist/rules/requireThrows.d.ts.map +0 -1
  119. package/dist/rules/requireYields.d.ts +0 -3
  120. package/dist/rules/requireYields.d.ts.map +0 -1
  121. package/dist/rules/requireYieldsCheck.d.ts +0 -3
  122. package/dist/rules/requireYieldsCheck.d.ts.map +0 -1
  123. package/dist/rules/sortTags.d.ts +0 -3
  124. package/dist/rules/sortTags.d.ts.map +0 -1
  125. package/dist/rules/tagLines.d.ts +0 -3
  126. package/dist/rules/tagLines.d.ts.map +0 -1
  127. package/dist/rules/textEscaping.d.ts +0 -3
  128. package/dist/rules/textEscaping.d.ts.map +0 -1
  129. package/dist/rules/validTypes.d.ts +0 -3
  130. package/dist/rules/validTypes.d.ts.map +0 -1
  131. package/dist/tagNames.d.ts +0 -16
  132. package/dist/tagNames.d.ts.map +0 -1
  133. package/dist/utils/hasReturnValue.d.ts +0 -20
  134. package/dist/utils/hasReturnValue.d.ts.map +0 -1
  135. package/docs/advanced.md +0 -102
  136. package/docs/rules/check-access.md +0 -193
  137. package/docs/rules/check-alignment.md +0 -169
  138. package/docs/rules/check-examples.md +0 -784
  139. package/docs/rules/check-indentation.md +0 -296
  140. package/docs/rules/check-line-alignment.md +0 -1002
  141. package/docs/rules/check-param-names.md +0 -1035
  142. package/docs/rules/check-property-names.md +0 -244
  143. package/docs/rules/check-syntax.md +0 -80
  144. package/docs/rules/check-tag-names.md +0 -1132
  145. package/docs/rules/check-types.md +0 -1198
  146. package/docs/rules/check-values.md +0 -409
  147. package/docs/rules/empty-tags.md +0 -220
  148. package/docs/rules/implements-on-classes.md +0 -219
  149. package/docs/rules/imports-as-dependencies.md +0 -99
  150. package/docs/rules/informative-docs.md +0 -400
  151. package/docs/rules/match-description.md +0 -1008
  152. package/docs/rules/match-name.md +0 -249
  153. package/docs/rules/multiline-blocks.md +0 -398
  154. package/docs/rules/no-bad-blocks.md +0 -174
  155. package/docs/rules/no-blank-block-descriptions.md +0 -91
  156. package/docs/rules/no-blank-blocks.md +0 -98
  157. package/docs/rules/no-defaults.md +0 -207
  158. package/docs/rules/no-missing-syntax.md +0 -275
  159. package/docs/rules/no-multi-asterisks.md +0 -278
  160. package/docs/rules/no-restricted-syntax.md +0 -383
  161. package/docs/rules/no-types.md +0 -168
  162. package/docs/rules/no-undefined-types.md +0 -789
  163. package/docs/rules/require-asterisk-prefix.md +0 -297
  164. package/docs/rules/require-description-complete-sentence.md +0 -820
  165. package/docs/rules/require-description.md +0 -585
  166. package/docs/rules/require-example.md +0 -390
  167. package/docs/rules/require-file-overview.md +0 -324
  168. package/docs/rules/require-hyphen-before-param-description.md +0 -281
  169. package/docs/rules/require-jsdoc.md +0 -1857
  170. package/docs/rules/require-param-description.md +0 -238
  171. package/docs/rules/require-param-name.md +0 -163
  172. package/docs/rules/require-param-type.md +0 -227
  173. package/docs/rules/require-param.md +0 -1820
  174. package/docs/rules/require-property-description.md +0 -88
  175. package/docs/rules/require-property-name.md +0 -79
  176. package/docs/rules/require-property-type.md +0 -79
  177. package/docs/rules/require-property.md +0 -128
  178. package/docs/rules/require-returns-check.md +0 -1053
  179. package/docs/rules/require-returns-description.md +0 -181
  180. package/docs/rules/require-returns-type.md +0 -144
  181. package/docs/rules/require-returns.md +0 -1191
  182. package/docs/rules/require-throws.md +0 -326
  183. package/docs/rules/require-yields-check.md +0 -544
  184. package/docs/rules/require-yields.md +0 -823
  185. package/docs/rules/sort-tags.md +0 -635
  186. package/docs/rules/tag-lines.md +0 -551
  187. package/docs/rules/text-escaping.md +0 -177
  188. package/docs/rules/valid-types.md +0 -881
  189. package/docs/settings.md +0 -362
  190. package/tsconfig-prod.json +0 -20
  191. package/tsconfig.json +0 -21
@@ -1,1053 +0,0 @@
1
- <a name="user-content-require-returns-check"></a>
2
- <a name="require-returns-check"></a>
3
- # <code>require-returns-check</code>
4
-
5
- * [Options](#user-content-require-returns-check-options)
6
- * [Context and settings](#user-content-require-returns-check-context-and-settings)
7
- * [Failing examples](#user-content-require-returns-check-failing-examples)
8
- * [Passing examples](#user-content-require-returns-check-passing-examples)
9
-
10
-
11
- Requires a return statement (or non-`undefined` Promise resolve value)
12
- be present in a
13
- function body if a `@returns` tag (without a `void` or `undefined` type)
14
- is specified in the function's JSDoc comment block.
15
-
16
- Will also report `@returns {void}` and `@returns {undefined}` if `exemptAsync`
17
- is set to `false` and a non-`undefined` value is returned or a resolved value
18
- is found. Also reports if `@returns {never}` is discovered with a return value.
19
-
20
- Will also report if multiple `@returns` tags are present.
21
-
22
- <a name="user-content-require-returns-check-options"></a>
23
- <a name="require-returns-check-options"></a>
24
- ## Options
25
-
26
- - `exemptGenerators`- Because a generator might be labeled as having a
27
- `IterableIterator` `@returns` value (along with an iterator type
28
- corresponding to the type of any `yield` statements), projects might wish to
29
- leverage `@returns` in generators even without a` return` statement. This
30
- option is therefore `true` by default in `typescript` mode (in "jsdoc" mode,
31
- one might be more likely to take advantage of `@yields`). Set it to `false`
32
- if you wish for a missing `return` to be flagged regardless.
33
- - `exemptAsync` - By default, functions which return a `Promise` that are not
34
- detected as resolving with a non-`undefined` value and `async` functions
35
- (even ones that do not explicitly return a value, as these are returning a
36
- `Promise` implicitly) will be exempted from reporting by this rule.
37
- If you wish to insist that only `Promise`'s which resolve to
38
- non-`undefined` values or `async` functions with explicit `return`'s will
39
- be exempted from reporting (i.e., that `async` functions can be reported
40
- if they lack an explicit (non-`undefined`) `return` when a `@returns` is
41
- present), you can set `exemptAsync` to `false` on the options object.
42
- - `reportMissingReturnForUndefinedTypes` - If `true` and no return or
43
- resolve value is found, this setting will even insist that reporting occur
44
- with `void` or `undefined` (including as an indicated `Promise` type).
45
- Unlike `require-returns`, with this option in the rule, one can
46
- *discourage* the labeling of `undefined` types. Defaults to `false`.
47
-
48
- <a name="user-content-require-returns-check-context-and-settings"></a>
49
- <a name="require-returns-check-context-and-settings"></a>
50
- ## Context and settings
51
-
52
- |||
53
- |---|---|
54
- |Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
55
- |Tags|`returns`|
56
- |Aliases|`return`|
57
- |Options|`exemptAsync`, `exemptGenerators`, `reportMissingReturnForUndefinedTypes`|
58
- |Recommended|true|
59
-
60
- <a name="user-content-require-returns-check-failing-examples"></a>
61
- <a name="require-returns-check-failing-examples"></a>
62
- ## Failing examples
63
-
64
- The following patterns are considered problems:
65
-
66
- ````js
67
- /**
68
- * @returns
69
- */
70
- function quux (foo) {
71
-
72
- }
73
- // Message: JSDoc @returns declaration present but return expression not available in function.
74
-
75
- /**
76
- * @return
77
- */
78
- function quux (foo) {
79
-
80
- }
81
- // Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
82
- // Message: JSDoc @return declaration present but return expression not available in function.
83
-
84
- /**
85
- * @returns
86
- */
87
- const quux = () => {}
88
- // Message: JSDoc @returns declaration present but return expression not available in function.
89
-
90
- /**
91
- * @returns {undefined} Foo.
92
- * @returns {String} Foo.
93
- */
94
- function quux () {
95
-
96
- return foo;
97
- }
98
- // Message: Found more than one @returns declaration.
99
-
100
- const language = {
101
- /**
102
- * @param {string} name
103
- * @returns {string}
104
- */
105
- get name() {
106
- this._name = name;
107
- }
108
- }
109
- // Message: JSDoc @returns declaration present but return expression not available in function.
110
-
111
- class Foo {
112
- /**
113
- * @returns {string}
114
- */
115
- bar () {
116
- }
117
- }
118
- // Message: JSDoc @returns declaration present but return expression not available in function.
119
-
120
- /**
121
- * @returns
122
- */
123
- function quux () {
124
-
125
- }
126
- // Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
127
- // Message: Unexpected tag `@returns`
128
-
129
- /**
130
- * @returns {string}
131
- */
132
- function f () {
133
- function g() {
134
- return 'foo'
135
- }
136
-
137
- () => {
138
- return 5
139
- }
140
- }
141
- // Message: JSDoc @returns declaration present but return expression not available in function.
142
-
143
- /**
144
- * @returns {Promise<void>}
145
- */
146
- async function quux() {}
147
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
148
- // Message: JSDoc @returns declaration present but return expression not available in function.
149
-
150
- /**
151
- * @returns {IterableIterator<any>}
152
- */
153
- function * quux() {}
154
- // Settings: {"jsdoc":{"mode":"jsdoc"}}
155
- // Message: JSDoc @returns declaration present but return expression not available in function.
156
-
157
- /**
158
- * @returns {IterableIterator<any>}
159
- */
160
- function * quux() {}
161
- // Settings: {"jsdoc":{"mode":"typescript"}}
162
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptGenerators":false}]
163
- // Message: JSDoc @returns declaration present but return expression not available in function.
164
-
165
- /**
166
- * @returns {Promise<void>}
167
- */
168
- function quux() {
169
- return new Promise((resolve, reject) => {})
170
- }
171
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
172
- // Message: JSDoc @returns declaration present but return expression not available in function.
173
-
174
- /**
175
- * @returns {Promise<void>}
176
- */
177
- function quux() {
178
- return new Promise((resolve, reject) => {
179
- setTimeout(() => {
180
- resolve();
181
- });
182
- })
183
- }
184
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
185
- // Message: JSDoc @returns declaration present but return expression not available in function.
186
-
187
- /**
188
- * Description.
189
- * @returns {string}
190
- */
191
- async function foo() {
192
- return new Promise(resolve => resolve());
193
- }
194
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
195
- // Message: JSDoc @returns declaration present but return expression not available in function.
196
-
197
- /**
198
- * Description.
199
- * @returns {void}
200
- */
201
- async function foo() {
202
- return new Promise(resolve => resolve());
203
- }
204
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false,"reportMissingReturnForUndefinedTypes":true}]
205
- // Message: JSDoc @returns declaration present but return expression not available in function.
206
-
207
- /**
208
- * @returns { void } Foo.
209
- */
210
- function quux () {}
211
- // "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
212
- // Message: JSDoc @returns declaration present but return expression not available in function.
213
-
214
- /**
215
- * @returns {never} Foo.
216
- */
217
- function quux () {
218
- return undefined;
219
- }
220
- // Message: JSDoc @returns declaration set with "never" but return expression is present in function.
221
-
222
- /**
223
- * @returns {never}
224
- */
225
- function quux (foo) {
226
- return foo;
227
- }
228
- // Message: JSDoc @returns declaration set with "never" but return expression is present in function.
229
-
230
- /**
231
- * Reads a test fixture.
232
- *
233
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
234
- * operating system.
235
- *
236
- * @returns The file contents as buffer.
237
- */
238
- export function readFixture(path: string): void;
239
- // Message: JSDoc @returns declaration present but return expression not available in function.
240
-
241
- /**
242
- * Reads a test fixture.
243
- *
244
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
245
- * operating system.
246
- *
247
- * @returns The file contents as buffer.
248
- */
249
- export function readFixture(path: string);
250
- // Message: JSDoc @returns declaration present but return expression not available in function.
251
-
252
- /**
253
- * @returns {SomeType}
254
- */
255
- function quux (path) {
256
- if (true) {
257
- return;
258
- }
259
- return 15;
260
- };
261
- // Message: JSDoc @returns declaration present but return expression not available in function.
262
-
263
- /**
264
- * Reads a test fixture.
265
- *
266
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
267
- * operating system.
268
- *
269
- * @returns The file contents as buffer.
270
- */
271
- export function readFixture(path: string): void {
272
- return;
273
- };
274
- // Message: JSDoc @returns declaration present but return expression not available in function.
275
-
276
- /**
277
- * @returns {true}
278
- */
279
- function quux () {
280
- if (true) {
281
- return true;
282
- }
283
- }
284
- // Message: JSDoc @returns declaration present but return expression not available in function.
285
-
286
- /**
287
- * @returns {true}
288
- */
289
- function quux () {
290
- if (true) {
291
- } else {
292
- return;
293
- }
294
- }
295
- // Message: JSDoc @returns declaration present but return expression not available in function.
296
-
297
- /**
298
- * @returns {true}
299
- */
300
- function quux (someVar) {
301
- switch (someVar) {
302
- case 1:
303
- return true;
304
- case 2:
305
- return;
306
- }
307
- }
308
- // Message: JSDoc @returns declaration present but return expression not available in function.
309
-
310
- /**
311
- * @returns {boolean}
312
- */
313
- const quux = (someVar) => {
314
- if (someVar) {
315
- return true;
316
- }
317
- };
318
- // Message: JSDoc @returns declaration present but return expression not available in function.
319
-
320
- /**
321
- * @returns {true}
322
- */
323
- function quux () {
324
- try {
325
- return true;
326
- } catch (error) {
327
- }
328
- }
329
- // Message: JSDoc @returns declaration present but return expression not available in function.
330
-
331
- /**
332
- * @returns {true}
333
- */
334
- function quux () {
335
- try {
336
- return true;
337
- } catch (error) {
338
- return true;
339
- } finally {
340
- return;
341
- }
342
- }
343
- // Message: JSDoc @returns declaration present but return expression not available in function.
344
-
345
- /**
346
- * @returns {true}
347
- */
348
- function quux () {
349
- if (true) {
350
- throw new Error('abc');
351
- }
352
-
353
- throw new Error('def');
354
- }
355
- // Message: JSDoc @returns declaration present but return expression not available in function.
356
-
357
- /**
358
- * @returns {SomeType} Baz.
359
- */
360
- function foo() {
361
- switch (true) {
362
- default:
363
- switch (false) {
364
- default: return;
365
- }
366
- return "baz";
367
- }
368
- };
369
- // Message: JSDoc @returns declaration present but return expression not available in function.
370
-
371
- /**
372
- * @returns {SomeType} Baz.
373
- */
374
- function foo() {
375
- switch (true) {
376
- default:
377
- switch (false) {
378
- default: return;
379
- }
380
- return "baz";
381
- }
382
- };
383
- // Message: JSDoc @returns declaration present but return expression not available in function.
384
-
385
- /**
386
- * @returns {number}
387
- */
388
- function foo() {
389
- let n = 1;
390
- while (n > 0.5) {
391
- n = Math.random();
392
- if (n < 0.2) {
393
- return n;
394
- }
395
- }
396
- }
397
- // Message: JSDoc @returns declaration present but return expression not available in function.
398
- ````
399
-
400
-
401
-
402
- <a name="user-content-require-returns-check-passing-examples"></a>
403
- <a name="require-returns-check-passing-examples"></a>
404
- ## Passing examples
405
-
406
- The following patterns are not considered problems:
407
-
408
- ````js
409
- /**
410
- * @returns Foo.
411
- */
412
- function quux () {
413
-
414
- return foo;
415
- }
416
-
417
- /**
418
- * @returns {string} Foo.
419
- */
420
- function quux () {
421
-
422
- return foo;
423
- }
424
-
425
- /**
426
- * @returns {string} Foo.
427
- */
428
- function quux () {
429
-
430
- return foo;
431
- }
432
-
433
- /**
434
- *
435
- */
436
- function quux () {
437
- }
438
-
439
- /**
440
- * @returns {SomeType} Foo.
441
- */
442
- const quux = () => foo;
443
-
444
- /**
445
- * @returns {undefined} Foo.
446
- */
447
- function quux () {}
448
-
449
- /**
450
- * @returns { void } Foo.
451
- */
452
- function quux () {}
453
-
454
- /**
455
- * @returns {Promise<void>}
456
- */
457
- async function quux() {}
458
-
459
- /**
460
- * @returns {Promise<void>}
461
- */
462
- const quux = async function () {}
463
-
464
- /**
465
- * @returns {Promise<void>}
466
- */
467
- const quux = async () => {}
468
-
469
- /**
470
- * @returns Foo.
471
- * @abstract
472
- */
473
- function quux () {
474
- throw new Error('must be implemented by subclass!');
475
- }
476
-
477
- /**
478
- * @returns Foo.
479
- * @virtual
480
- */
481
- function quux () {
482
- throw new Error('must be implemented by subclass!');
483
- }
484
-
485
- /**
486
- * @returns Foo.
487
- * @constructor
488
- */
489
- function quux () {
490
- }
491
-
492
- /**
493
- * @interface
494
- */
495
- class Foo {
496
- /**
497
- * @returns {string}
498
- */
499
- bar () {
500
- }
501
- }
502
-
503
- /**
504
- * @record
505
- */
506
- class Foo {
507
- /**
508
- * @returns {string}
509
- */
510
- bar () {
511
- }
512
- }
513
- // Settings: {"jsdoc":{"mode":"closure"}}
514
-
515
- /**
516
- * @returns {undefined} Foo.
517
- */
518
- function quux () {
519
- }
520
-
521
- /**
522
- * @returns {void} Foo.
523
- */
524
- function quux () {
525
- }
526
-
527
- /**
528
- * @returns {void} Foo.
529
- */
530
- function quux () {
531
- return undefined;
532
- }
533
-
534
- /**
535
- * @returns {never} Foo.
536
- */
537
- function quux () {
538
- }
539
-
540
- /**
541
- * @returns {void} Foo.
542
- */
543
- function quux () {
544
- return;
545
- }
546
-
547
- /**
548
- *
549
- */
550
- function quux () {
551
- return undefined;
552
- }
553
-
554
- /**
555
- *
556
- */
557
- function quux () {
558
- return;
559
- }
560
-
561
- /**
562
- * @returns {true}
563
- */
564
- function quux () {
565
- try {
566
- return true;
567
- } catch (err) {
568
- }
569
- return true;
570
- }
571
-
572
- /**
573
- * @returns {true}
574
- */
575
- function quux () {
576
- try {
577
- } finally {
578
- return true;
579
- }
580
- return true;
581
- }
582
-
583
- /**
584
- * @returns {true}
585
- */
586
- function quux () {
587
- try {
588
- return true;
589
- } catch (err) {
590
- }
591
- return true;
592
- }
593
-
594
- /**
595
- * @returns {true}
596
- */
597
- function quux () {
598
- try {
599
- something();
600
- } catch (err) {
601
- return true;
602
- }
603
- return true;
604
- }
605
-
606
- /**
607
- * @returns {true}
608
- */
609
- function quux () {
610
- switch (true) {
611
- case 'abc':
612
- return true;
613
- }
614
- return true;
615
- }
616
-
617
- /**
618
- * @returns {true}
619
- */
620
- function quux () {
621
- switch (true) {
622
- case 'abc':
623
- return true;
624
- }
625
- return true;
626
- }
627
-
628
- /**
629
- * @returns {true}
630
- */
631
- function quux () {
632
- for (const i of abc) {
633
- return true;
634
- }
635
- return true;
636
- }
637
-
638
- /**
639
- * @returns {true}
640
- */
641
- function quux () {
642
- for (const a in b) {
643
- return true;
644
- }
645
- }
646
-
647
- /**
648
- * @returns {true}
649
- */
650
- function quux () {
651
- for (const a of b) {
652
- return true;
653
- }
654
- }
655
-
656
- /**
657
- * @returns {true}
658
- */
659
- function quux () {
660
- loop: for (const a of b) {
661
- return true;
662
- }
663
- }
664
-
665
- /**
666
- * @returns {true}
667
- */
668
- function quux () {
669
- for (let i=0; i<n; i+=1) {
670
- return true;
671
- }
672
- }
673
-
674
- /**
675
- * @returns {true}
676
- */
677
- function quux () {
678
- while(true) {
679
- return true
680
- }
681
- }
682
-
683
- /**
684
- * @returns {true}
685
- */
686
- function quux () {
687
- do {
688
- return true
689
- }
690
- while(true)
691
- }
692
-
693
- /**
694
- * @returns {true}
695
- */
696
- function quux () {
697
- if (true) {
698
- return true;
699
- }
700
- return true;
701
- }
702
-
703
- /**
704
- * @returns {true}
705
- */
706
- function quux () {
707
- var a = {};
708
- with (a) {
709
- return true;
710
- }
711
- }
712
-
713
- /**
714
- * @returns {true}
715
- */
716
- function quux () {
717
- if (true) {
718
- return true;
719
- } else {
720
- return true;
721
- }
722
- return true;
723
- }
724
-
725
- /**
726
- * @returns {Promise<number>}
727
- */
728
- async function quux() {
729
- return 5;
730
- }
731
-
732
- /**
733
- * @returns {Promise<number>}
734
- */
735
- async function quux() {
736
- return 5;
737
- }
738
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
739
-
740
- /**
741
- * @returns {Promise<void>}
742
- */
743
- function quux() {
744
- return new Promise((resolve, reject) => {
745
- setTimeout(() => {
746
- resolve(true);
747
- });
748
- })
749
- }
750
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
751
-
752
- /**
753
- * Description.
754
- * @returns {void}
755
- */
756
- async function foo() {
757
- return new Promise(resolve => resolve());
758
- }
759
- // "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
760
-
761
- /**
762
- * @returns { void } Foo.
763
- */
764
- function quux () {
765
- return undefined;
766
- }
767
- // "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
768
-
769
- /**
770
- * @returns { string } Foo.
771
- */
772
- function quux () {
773
- return 'abc';
774
- }
775
- // "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
776
-
777
- /**
778
- * @returns {IterableIterator<any>}
779
- */
780
- function * quux() {}
781
- // Settings: {"jsdoc":{"mode":"typescript"}}
782
-
783
- /**
784
- * @returns {IterableIterator<any>}
785
- */
786
- function * quux() {}
787
- // Settings: {"jsdoc":{"mode":"jsdoc"}}
788
- // "jsdoc/require-returns-check": ["error"|"warn", {"exemptGenerators":true}]
789
-
790
- /**
791
- * @param {unknown} val
792
- * @returns { asserts val is number }
793
- */
794
- function assertNumber(val) {
795
- assert(typeof val === 'number');
796
- }
797
-
798
- /**
799
- * Reads a test fixture.
800
- *
801
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
802
- * operating system.
803
- *
804
- * @returns The file contents as buffer.
805
- */
806
- export function readFixture(path: string): Promise<Buffer>;
807
-
808
- /**
809
- * Reads a test fixture.
810
- *
811
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
812
- * operating system.
813
- *
814
- * @returns {SomeType} The file contents as buffer.
815
- */
816
- export function readFixture(path: string): Promise<Buffer>;
817
-
818
- /**
819
- * Reads a test fixture.
820
- *
821
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
822
- * operating system.
823
- *
824
- * @returns The file contents as buffer.
825
- */
826
- export function readFixture(path: string): Promise<Buffer> {
827
- return new Promise(() => {});
828
- }
829
-
830
- /**
831
- * Reads a test fixture.
832
- *
833
- * @param path The path to resolve relative to the fixture base. It will be normalized for the
834
- * operating system.
835
- *
836
- * @returns {void} The file contents as buffer.
837
- */
838
- export function readFixture(path: string);
839
-
840
- /**
841
- * @returns {SomeType}
842
- */
843
- function quux (path) {
844
- if (true) {
845
- return 5;
846
- }
847
- return 15;
848
- };
849
-
850
- /**
851
- * @returns {SomeType} Foo.
852
- */
853
- const quux = () => new Promise((resolve) => {
854
- resolve(3);
855
- });
856
-
857
- /**
858
- * @returns {SomeType} Foo.
859
- */
860
- const quux = function () {
861
- return new Promise((resolve) => {
862
- resolve(3);
863
- });
864
- };
865
-
866
- /**
867
- * @returns {true}
868
- */
869
- function quux () {
870
- if (true) {
871
- return true;
872
- }
873
-
874
- throw new Error('Fail');
875
- }
876
-
877
- /**
878
- * @returns Baz.
879
- */
880
- function foo() {
881
- switch (true) {
882
- default:
883
- switch (false) {
884
- default: break;
885
- }
886
- return "baz";
887
- }
888
- };
889
-
890
- /**
891
- * Return a V1 style query identifier.
892
- *
893
- * @param {string} id - The query identifier.
894
- * @returns {string} V1 style query identifier.
895
- */
896
- function v1QueryId(id) {
897
- switch (id) {
898
- case 'addq':
899
- case 'aliq':
900
- case 'locq':
901
- return id.substring(3);
902
- case 'lost':
903
- return id.substring(4);
904
- default:
905
- return id;
906
- }
907
- }
908
-
909
- /**
910
- * Parses the required header fields for the given SIP message.
911
- *
912
- * @param {string} logPrefix - The log prefix.
913
- * @param {string} sipMessage - The SIP message.
914
- * @param {string[]} headers - The header fields to be parsed.
915
- * @returns {object} Object with parsed header fields.
916
- */
917
- function parseSipHeaders(logPrefix, sipMessage, headers) {
918
- try {
919
- return esappSip.parseHeaders(sipMessage, headers);
920
- } catch (err) {
921
- logger.error(logPrefix, 'Failed to parse');
922
- return {};
923
- }
924
- }
925
-
926
- /**
927
- * @returns {true}
928
- */
929
- function quux () {
930
- try {
931
- } catch (error) {
932
- } finally {
933
- return true;
934
- }
935
- }
936
-
937
- /** Returns true.
938
- *
939
- * @returns {boolean} true
940
- */
941
- function getTrue() {
942
- try {
943
- return true;
944
- } finally {
945
- console.log('returning...');
946
- }
947
- }
948
-
949
- /**
950
- * Maybe return a boolean.
951
- * @returns {boolean|void} true, or undefined.
952
- */
953
- function maybeTrue() {
954
- if (Math.random() > 0.5) {
955
- return true;
956
- }
957
- }
958
-
959
- /**
960
- * @param {AST} astNode
961
- * @returns {AST}
962
- */
963
- const getTSFunctionComment = function (astNode) {
964
- switch (greatGrandparent.type) {
965
- case 'VariableDeclarator':
966
- if (greatGreatGrandparent.type === 'VariableDeclaration') {
967
- return greatGreatGrandparent;
968
- }
969
-
970
- default:
971
- return astNode;
972
- }
973
- };
974
-
975
- const f =
976
- /**
977
- * Description.
978
- *
979
- * @returns Result.
980
- */
981
- () => {
982
- return function () {};
983
- };
984
-
985
- /**
986
- * Description.
987
- *
988
- * @returns Result.
989
- */
990
- export function f(): string {
991
- return "";
992
-
993
- interface I {}
994
- }
995
-
996
- /**
997
- * @param {boolean} bar A fun variable.
998
- * @returns {*} Anything at all!
999
- */
1000
- function foo( bar ) {
1001
- if ( bar ) {
1002
- return functionWithUnknownReturnType();
1003
- }
1004
- }
1005
-
1006
- /**
1007
- * @returns Baz.
1008
- */
1009
- function foo() {
1010
- switch (true) {
1011
- default:
1012
- switch (false) {
1013
- default: return;
1014
- }
1015
- return "baz";
1016
- }
1017
- };
1018
-
1019
- /**
1020
- * @returns Baz.
1021
- */
1022
- function foo() {
1023
- switch (true) {
1024
- default:
1025
- switch (false) {
1026
- default: return;
1027
- }
1028
- return "baz";
1029
- }
1030
- };
1031
-
1032
- /**
1033
- * @returns
1034
- */
1035
- const quux = (someVar) => {
1036
- if (someVar) {
1037
- return true;
1038
- }
1039
- };
1040
-
1041
- /**
1042
- * @returns {number}
1043
- */
1044
- function foo() {
1045
- while (true) {
1046
- const n = Math.random();
1047
- if (n < 0.5) {
1048
- return n;
1049
- }
1050
- }
1051
- }
1052
- ````
1053
-