UNPKG

454 kBMarkdownView Raw
1<a name="eslint-plugin-jsdoc"></a>
2# eslint-plugin-jsdoc
3
4[![GitSpo Mentions](https://gitspo.com/badges/mentions/gajus/eslint-plugin-jsdoc?style=flat-square)](https://gitspo.com/mentions/gajus/eslint-plugin-jsdoc)
5[![NPM version](https://img.shields.io/npm/v/eslint-plugin-jsdoc.svg?style=flat-square)](https://www.npmjs.org/package/eslint-plugin-jsdoc)
6[![Travis build status](https://img.shields.io/travis/gajus/eslint-plugin-jsdoc/master.svg?style=flat-square)](https://travis-ci.org/gajus/eslint-plugin-jsdoc)
7[![js-canonical-style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)](https://github.com/gajus/canonical)
8[![Discord Chat](https://img.shields.io/badge/chat-on%20disord-green.svg?logo=discord)](https://discord.gg/kFFy3nc)
9
10JSDoc linting rules for ESLint.
11
12* [eslint-plugin-jsdoc](#eslint-plugin-jsdoc)
13 * [Installation](#eslint-plugin-jsdoc-installation)
14 * [Configuration](#eslint-plugin-jsdoc-configuration)
15 * [Options](#eslint-plugin-jsdoc-options)
16 * [Settings](#eslint-plugin-jsdoc-settings)
17 * [Allow tags (`@private` or `@internal`) to disable rules for that comment block](#eslint-plugin-jsdoc-settings-allow-tags-private-or-internal-to-disable-rules-for-that-comment-block)
18 * [`maxLines` and `minLines`](#eslint-plugin-jsdoc-settings-maxlines-and-minlines)
19 * [Mode](#eslint-plugin-jsdoc-settings-mode)
20 * [Alias Preference](#eslint-plugin-jsdoc-settings-alias-preference)
21 * [`@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`](#eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns)
22 * [Settings to Configure `check-types` and `no-undefined-types`](#eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types)
23 * [`structuredTags`](#eslint-plugin-jsdoc-settings-structuredtags)
24 * [Advanced](#eslint-plugin-jsdoc-advanced)
25 * [AST and Selectors](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
26 * [Rules](#eslint-plugin-jsdoc-rules)
27 * [`check-access`](#eslint-plugin-jsdoc-rules-check-access)
28 * [`check-alignment`](#eslint-plugin-jsdoc-rules-check-alignment)
29 * [`check-examples`](#eslint-plugin-jsdoc-rules-check-examples)
30 * [`check-indentation`](#eslint-plugin-jsdoc-rules-check-indentation)
31 * [`check-line-alignment`](#eslint-plugin-jsdoc-rules-check-line-alignment)
32 * [`check-param-names`](#eslint-plugin-jsdoc-rules-check-param-names)
33 * [`check-property-names`](#eslint-plugin-jsdoc-rules-check-property-names)
34 * [`check-syntax`](#eslint-plugin-jsdoc-rules-check-syntax)
35 * [`check-tag-names`](#eslint-plugin-jsdoc-rules-check-tag-names)
36 * [`check-types`](#eslint-plugin-jsdoc-rules-check-types)
37 * [`check-values`](#eslint-plugin-jsdoc-rules-check-values)
38 * [`empty-tags`](#eslint-plugin-jsdoc-rules-empty-tags)
39 * [`implements-on-classes`](#eslint-plugin-jsdoc-rules-implements-on-classes)
40 * [`match-description`](#eslint-plugin-jsdoc-rules-match-description)
41 * [`multiline-blocks`](#eslint-plugin-jsdoc-rules-multiline-blocks)
42 * [`newline-after-description`](#eslint-plugin-jsdoc-rules-newline-after-description)
43 * [`no-bad-blocks`](#eslint-plugin-jsdoc-rules-no-bad-blocks)
44 * [`no-defaults`](#eslint-plugin-jsdoc-rules-no-defaults)
45 * [`no-missing-syntax`](#eslint-plugin-jsdoc-rules-no-missing-syntax)
46 * [`no-multi-asterisks`](#eslint-plugin-jsdoc-rules-no-multi-asterisks)
47 * [`no-restricted-syntax`](#eslint-plugin-jsdoc-rules-no-restricted-syntax)
48 * [`no-types`](#eslint-plugin-jsdoc-rules-no-types)
49 * [`no-undefined-types`](#eslint-plugin-jsdoc-rules-no-undefined-types)
50 * [`require-asterisk-prefix`](#eslint-plugin-jsdoc-rules-require-asterisk-prefix)
51 * [`require-description-complete-sentence`](#eslint-plugin-jsdoc-rules-require-description-complete-sentence)
52 * [`require-description`](#eslint-plugin-jsdoc-rules-require-description)
53 * [`require-example`](#eslint-plugin-jsdoc-rules-require-example)
54 * [`require-file-overview`](#eslint-plugin-jsdoc-rules-require-file-overview)
55 * [`require-hyphen-before-param-description`](#eslint-plugin-jsdoc-rules-require-hyphen-before-param-description)
56 * [`require-jsdoc`](#eslint-plugin-jsdoc-rules-require-jsdoc)
57 * [`require-param-description`](#eslint-plugin-jsdoc-rules-require-param-description)
58 * [`require-param-name`](#eslint-plugin-jsdoc-rules-require-param-name)
59 * [`require-param-type`](#eslint-plugin-jsdoc-rules-require-param-type)
60 * [`require-param`](#eslint-plugin-jsdoc-rules-require-param)
61 * [`require-property`](#eslint-plugin-jsdoc-rules-require-property)
62 * [`require-property-description`](#eslint-plugin-jsdoc-rules-require-property-description)
63 * [`require-property-name`](#eslint-plugin-jsdoc-rules-require-property-name)
64 * [`require-property-type`](#eslint-plugin-jsdoc-rules-require-property-type)
65 * [`require-returns-check`](#eslint-plugin-jsdoc-rules-require-returns-check)
66 * [`require-returns-description`](#eslint-plugin-jsdoc-rules-require-returns-description)
67 * [`require-returns-type`](#eslint-plugin-jsdoc-rules-require-returns-type)
68 * [`require-returns`](#eslint-plugin-jsdoc-rules-require-returns)
69 * [`require-throws`](#eslint-plugin-jsdoc-rules-require-throws)
70 * [`require-yields`](#eslint-plugin-jsdoc-rules-require-yields)
71 * [`require-yields-check`](#eslint-plugin-jsdoc-rules-require-yields-check)
72 * [`tag-lines`](#eslint-plugin-jsdoc-rules-tag-lines)
73 * [`valid-types`](#eslint-plugin-jsdoc-rules-valid-types)
74
75
76<a name="eslint-plugin-jsdoc-installation"></a>
77## Installation
78
79Install [ESLint](https://www.github.com/eslint/eslint) either locally or
80globally.
81
82```sh
83npm install --save-dev eslint
84```
85
86If you have installed `ESLint` globally, you have to install JSDoc plugin
87globally too. Otherwise, install it locally.
88
89```sh
90npm install --save-dev eslint-plugin-jsdoc
91```
92
93<a name="eslint-plugin-jsdoc-configuration"></a>
94## Configuration
95
96Add `plugins` section to [.eslintrc.*](https://eslint.org/docs/user-guide/configuring#configuration-file-formats)
97and specify `eslint-plugin-jsdoc` as a plugin.
98
99```json
100{
101 "plugins": [
102 "jsdoc"
103 ]
104}
105```
106
107Finally, enable all of the rules that you would like to use.
108
109```javascript
110{
111 "rules": {
112 "jsdoc/check-access": 1, // Recommended
113 "jsdoc/check-alignment": 1, // Recommended
114 "jsdoc/check-examples": 1,
115 "jsdoc/check-indentation": 1,
116 "jsdoc/check-line-alignment": 1,
117 "jsdoc/check-param-names": 1, // Recommended
118 "jsdoc/check-property-names": 1, // Recommended
119 "jsdoc/check-syntax": 1,
120 "jsdoc/check-tag-names": 1, // Recommended
121 "jsdoc/check-types": 1, // Recommended
122 "jsdoc/check-values": 1, // Recommended
123 "jsdoc/empty-tags": 1, // Recommended
124 "jsdoc/implements-on-classes": 1, // Recommended
125 "jsdoc/match-description": 1,
126 "jsdoc/multiline-blocks": 1, // Recommended
127 "jsdoc/newline-after-description": 1, // Recommended
128 "jsdoc/no-bad-blocks": 1,
129 "jsdoc/no-defaults": 1,
130 "jsdoc/no-missing-syntax": 1,
131 "jsdoc/no-multi-asterisks": 1, // Recommended
132 "jsdoc/no-restricted-syntax": 1,
133 "jsdoc/no-types": 1,
134 "jsdoc/no-undefined-types": 1, // Recommended
135 "jsdoc/require-asterisk-prefix": 1,
136 "jsdoc/require-description": 1,
137 "jsdoc/require-description-complete-sentence": 1,
138 "jsdoc/require-example": 1,
139 "jsdoc/require-file-overview": 1,
140 "jsdoc/require-hyphen-before-param-description": 1,
141 "jsdoc/require-jsdoc": 1, // Recommended
142 "jsdoc/require-param": 1, // Recommended
143 "jsdoc/require-param-description": 1, // Recommended
144 "jsdoc/require-param-name": 1, // Recommended
145 "jsdoc/require-param-type": 1, // Recommended
146 "jsdoc/require-property": 1, // Recommended
147 "jsdoc/require-property-description": 1, // Recommended
148 "jsdoc/require-property-name": 1, // Recommended
149 "jsdoc/require-property-type": 1, // Recommended
150 "jsdoc/require-returns": 1, // Recommended
151 "jsdoc/require-returns-check": 1, // Recommended
152 "jsdoc/require-returns-description": 1, // Recommended
153 "jsdoc/require-returns-type": 1, // Recommended
154 "jsdoc/require-throws": 1,
155 "jsdoc/require-yields": 1, // Recommended
156 "jsdoc/require-yields-check": 1, // Recommended
157 "jsdoc/tag-lines": 1, // Recommended
158 "jsdoc/valid-types": 1 // Recommended
159 }
160}
161```
162
163Or you can simply add the following to [.eslintrc.*](https://eslint.org/docs/user-guide/configuring#configuration-file-formats),
164which enables the rules commented above as "recommended":
165
166
167```json
168{
169 "extends": ["plugin:jsdoc/recommended"]
170}
171```
172
173You can then selectively add to or override the recommended rules.
174
175<a name="eslint-plugin-jsdoc-options"></a>
176## Options
177
178Rules may, as per the [ESLint user guide](https://eslint.org/docs/user-guide/configuring), have their own individual options. In `eslint-plugin-jsdoc`, a few options,
179such as, `exemptedBy` and `contexts`, may be used across different rules.
180
181`eslint-plugin-jsdoc` options, if present, are generally in the form of an
182object supplied as the second argument in an array after the error level
183(any exceptions to this format are explained within that rule's docs).
184
185```js
186// `.eslintrc.js`
187{
188 rules: {
189 'jsdoc/require-example': [
190 // The Error level should be `error`, `warn`, or `off` (or 2, 1, or 0)
191 'error',
192 // The options vary by rule, but are generally added to an options
193 // object as follows:
194 {
195 avoidExampleOnConstructors: true,
196 exemptedBy: ['type']
197 }
198 ]
199 }
200}
201```
202
203<a name="eslint-plugin-jsdoc-settings"></a>
204## Settings
205
206<a name="eslint-plugin-jsdoc-settings-allow-tags-private-or-internal-to-disable-rules-for-that-comment-block"></a>
207### Allow tags (<code>@private</code> or <code>@internal</code>) to disable rules for that comment block
208
209- `settings.jsdoc.ignorePrivate` - Disables all rules for the comment block
210 on which a `@private` tag (or `@access private`) occurs. Defaults to
211 `false`. Note: This has no effect with the rule `check-access` (whose
212 purpose is to check access modifiers) or `empty-tags` (which checks
213 `@private` itself).
214- `settings.jsdoc.ignoreInternal` - Disables all rules for the comment block
215 on which a `@internal` tag occurs. Defaults to `false`. Note: This has no
216 effect with the rule `empty-tags` (which checks `@internal` itself).
217
218<a name="eslint-plugin-jsdoc-settings-maxlines-and-minlines"></a>
219### <code>maxLines</code> and <code>minLines</code>
220
221One can use `minLines` and `maxLines` to indicate how many line breaks
222(if any) will be checked to find a jsdoc comment block before the given
223code block. These settings default to `0` and `1` respectively.
224
225In conjunction with the `require-jsdoc` rule, these settings can
226be enforced so as to report problems if a jsdoc block is not found within
227the specified boundaries. The settings are also used in the fixer to determine
228how many line breaks to add when a block is missing.
229
230<a name="eslint-plugin-jsdoc-settings-mode"></a>
231### Mode
232
233- `settings.jsdoc.mode` - Set to `typescript`, `closure`, or `jsdoc` (the
234 default unless the `@typescript-eslint` parser is in use in which case
235 `typescript` will be the default).
236 Note that if you do not wish to use separate `.eslintrc.*` files for a
237 project containing both JavaScript and TypeScript, you can also use
238 [`overrides`](https://eslint.org/docs/user-guide/configuring). You may also
239 set to `"permissive"` to try to be as accommodating to any of the styles,
240 but this is not recommended. Currently is used for the following:
241 - `check-tag-names`: Determine valid tags and aliases
242 - `no-undefined-types`: Only check `@template` for types in "closure" and
243 "typescript" modes
244 - `check-syntax`: determines aspects that may be enforced
245 - `valid-types`: in non-Closure mode, `@extends`, `@package` and access tags
246 (e.g., `@private`) with a bracketed type are reported as are missing
247 names with `@typedef`
248 - For type/namepath-checking rules, determine which tags will be checked for
249 types/namepaths (Closure allows types on some tags which the others do not,
250 so these tags will additionally be checked in "closure" mode)
251 - For type-checking rules, impacts parsing of types (through
252 [jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser)
253 dependency); note that some TypeScript features are
254 [not yet](https://github.com/gajus/eslint-plugin-jsdoc/issues/145)
255 [supported](https://github.com/jsdoctypeparser/jsdoctypeparser/issues/50)
256 - Check preferred tag names
257 - Disallows namepath on `@interface` for "closure" mode in `valid-types` (and
258 avoids checking in other rules)
259
260<a name="eslint-plugin-jsdoc-settings-alias-preference"></a>
261### Alias Preference
262
263Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for
264a JSDoc tag. The format of the configuration is:
265`<primary tag name>: <preferred alias name>`, e.g.
266
267```json
268{
269 "rules": {},
270 "settings": {
271 "jsdoc": {
272 "tagNamePreference": {
273 "param": "arg",
274 "returns": "return"
275 }
276 }
277 }
278}
279```
280
281Note: ESLint does not allow settings to have keys which conflict with
282`Object.prototype` e.g. `'constructor'`. To work around this, you can use the
283key `'tag constructor'`.
284
285One may also use an object with a `message` and `replacement`.
286
287The following will report the message
288`@extends is to be used over @augments as it is more evocative of classes than @augments`
289upon encountering `@augments`.
290
291```json
292{
293 "rules": {},
294 "settings": {
295 "jsdoc": {
296 "tagNamePreference": {
297 "augments": {
298 "message": "@extends is to be used over @augments as it is more evocative of classes than @augments",
299 "replacement": "extends"
300 }
301 }
302 }
303 }
304}
305```
306
307If one wishes to reject a normally valid tag, e.g., `@todo`, one may set the
308tag to `false`:
309
310```json
311{
312 "rules": {},
313 "settings": {
314 "jsdoc": {
315 "tagNamePreference": {
316 "todo": false
317 }
318 }
319 }
320}
321```
322
323A project wishing to ensure no blocks are left excluded from entering the
324documentation, might wish to prevent the `@ignore` tag in the above manner.
325
326Or one may set the targeted tag to an object with a custom `message`, but
327without a `replacement` property:
328
329```json
330{
331 "rules": {},
332 "settings": {
333 "jsdoc": {
334 "tagNamePreference": {
335 "todo": {
336 "message": "We expect immediate perfection, so don't leave to-dos in your code."
337 }
338 }
339 }
340 }
341}
342```
343
344Note that the preferred tags indicated in the
345`settings.jsdoc.tagNamePreference` map will be assumed to be defined by
346`check-tag-names`.
347
348See `check-tag-names` for how that fact can be used to set an alias to itself
349to allow both the alias and the default (since aliases are otherwise not
350permitted unless used in `tagNamePreference`).
351
352<a name="eslint-plugin-jsdoc-settings-alias-preference-default-preferred-aliases"></a>
353#### Default Preferred Aliases
354
355The defaults in `eslint-plugin-jsdoc` (for tags which offer
356aliases) are as follows:
357
358- `@abstract` (over `@virtual`)
359- `@augments` (over `@extends`)
360- `@class` (over `@constructor`)
361- `@constant` (over `@const`)
362- `@default` (over `@defaultvalue`)
363- `@description` (over `@desc`)
364- `@external` (over `@host`)
365- `@file` (over `@fileoverview`, `@overview`)
366- `@fires` (over `@emits`)
367- `@function` (over `@func`, `@method`)
368- `@member` (over `@var`)
369- `@param` (over `@arg`, `@argument`)
370- `@property` (over `@prop`)
371- `@returns` (over `@return`)
372- `@throws` (over `@exception`)
373- `@yields` (over `@yield`)
374
375This setting is utilized by the the rule for tag name checking
376(`check-tag-names`) as well as in the `@param` and `@require` rules:
377
378- `check-param-names`
379- `check-tag-names`
380- `require-hyphen-before-param-description`
381- `require-description`
382- `require-param`
383- `require-param-description`
384- `require-param-name`
385- `require-param-type`
386- `require-returns`
387- `require-returns-check`
388- `require-returns-description`
389- `require-returns-type`
390
391<a name="eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns"></a>
392### <code>@override</code>/<code>@augments</code>/<code>@extends</code>/<code>@implements</code> Without Accompanying <code>@param</code>/<code>@description</code>/<code>@example</code>/<code>@returns</code>
393
394The following settings allows the element(s) they reference to be omitted
395on the JSDoc comment block of the function or that of its parent class
396for any of the "require" rules (i.e., `require-param`, `require-description`,
397`require-example`, or `require-returns`).
398
399* `settings.jsdoc.overrideReplacesDocs` (`@override`) - Defaults to `true`
400* `settings.jsdoc.augmentsExtendsReplacesDocs` (`@augments` or its alias
401 `@extends`) - Defaults to `false`.
402* `settings.jsdoc.implementsReplacesDocs` (`@implements`) - Defaults to `false`
403
404The format of the configuration is as follows:
405
406```json
407{
408 "rules": {},
409 "settings": {
410 "jsdoc": {
411 "overrideReplacesDocs": true,
412 "augmentsExtendsReplacesDocs": true,
413 "implementsReplacesDocs": true
414 }
415 }
416}
417```
418
419<a name="eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types"></a>
420### Settings to Configure <code>check-types</code> and <code>no-undefined-types</code>
421
422- `settings.jsdoc.preferredTypes` An option map to indicate preferred
423 or forbidden types (if default types are indicated here, these will
424 have precedence over the default recommendations for `check-types`).
425 The keys of this map are the types to be replaced (or forbidden).
426 These keys may include:
427 1. The "ANY" type, `*`
428 1. The pseudo-type `[]` which we use to denote the parent (array)
429 types used in the syntax `string[]`, `number[]`, etc.
430 1. The pseudo-type `.<>` (or `.`) to represent the format `Array.<value>`
431 or `Object.<key, value>`
432 1. The pseudo-type `<>` to represent the format `Array<value>` or
433 `Object<key, value>`
434 1. A plain string type, e.g., `MyType`
435 1. A plain string type followed by one of the above pseudo-types (except
436 for `[]` which is always assumed to be an `Array`), e.g., `Array.`, or
437 `SpecialObject<>`.
438
439 If a bare pseudo-type is used, it will match all parent types of that form.
440 If a pseudo-type prefixed with a type name is used, it will only match
441 parent types of that form and type name.
442
443 The values can be:
444 - `false` to forbid the type
445 - a string to indicate the type that should be preferred in its place
446 (and which `fix` mode can replace); this can be one of the formats
447 of the keys described above.
448 - Note that the format will not be changed unless you use a pseudo-type
449 in the replacement. (For example, `'Array.<>': 'MyArray'` will change
450 `Array.<string>` to `MyArray.<string>`, preserving the dot. To get rid
451 of the dot, you must use the pseudo-type with `<>`, i.e.,
452 `'Array.<>': 'MyArray<>'`, which will change `Array.<string>` to
453 `MyArray<string>`).
454 - If you use a _bare_ pseudo-type in the replacement (e.g.,
455 `'MyArray.<>': '<>'`), the type will be converted to the format
456 of the pseudo-type without changing the type name. For example,
457 `MyArray.<string>` will become `MyArray<string>` but `Array.<string>`
458 will not be modified.
459 - an object with:
460 - the key `message` to provide a specific error message
461 when encountering the discouraged type.
462 - The message string will have the substrings with special meaning,
463 `{{tagName}}` and `{{tagValue}}`, replaced with their
464 corresponding value.
465 - an optional key `replacement` with either of the following values:
466 - a string type to be preferred in its place (and which `fix` mode
467 can replace)
468 - `false` (for forbidding the type)
469
470Note that the preferred types indicated as targets in
471`settings.jsdoc.preferredTypes` map will be assumed to be defined by
472`no-undefined-types`.
473
474See the option of `check-types`, `unifyParentAndChildTypeChecks`, for
475how the keys of `preferredTypes` may have `<>` or `.<>` (or just `.`)
476appended and its bearing on whether types are checked as parents/children
477only (e.g., to match `Array` if the type is `Array` vs. `Array.<string>`).
478
479Note that if a value is present both as a key and as a value, neither the
480key nor the value will be reported. Thus in `check-types`, this fact can
481be used to allow both `object` and `Object` if one has a `preferredTypes`
482key `object: 'Object'` and `Object: 'object'`.
483
484<a name="eslint-plugin-jsdoc-settings-structuredtags"></a>
485### <code>structuredTags</code>
486
487An object indicating tags whose types and names/namepaths (whether defining or
488referencing namepaths) will be checked, subject to configuration. If the tags
489have predefined behavior or `allowEmptyNamepaths` behavior, this option will
490override that behavior for any specified tags, though this option can also be
491used for tags without predefined behavior. Its keys are tag names and its
492values are objects with the following optional properties:
493 - `name` - String set to one of the following:
494 - `"text"` - When a name is present, plain text will be allowed in the
495 name position (non-whitespace immediately after the tag and whitespace),
496 e.g., in `@throws This is an error`, "This" would normally be the name,
497 but "text" allows non-name text here also. This is the default.
498 - `"namepath-defining"` - As with `namepath-referencing`, but also
499 indicates the tag adds a namepath to definitions, e.g., to prevent
500 `no-undefined-types` from reporting references to that namepath.
501 - `"namepath-referencing"` - This will cause any name position to be
502 checked to ensure it is a valid namepath. You might use this to ensure
503 that tags which normally allow free text, e.g., `@see` will instead
504 require a namepath.
505 - `false` - This will disallow any text in the name position.
506 - `type`:
507 - `true` - Allows valid types within brackets. This is the default.
508 - `false` - Explicitly disallows any brackets or bracketed type. You
509 might use this with `@throws` to suggest that only free form text
510 is being input or with `@augments` (for jsdoc mode) to disallow
511 Closure-style bracketed usage along with a required namepath.
512 - (An array of strings) - A list of permissible types.
513 - `required` - Array of one of the following (defaults to an empty array,
514 meaning none are required):
515 - One or both of the following strings (if both are included, then both
516 are required):
517 - `"name"` - Indicates that a name position is required (not just that
518 if present, it is a valid namepath). You might use this with `see`
519 to insist that a value (or namepath, depending on the `name` value)
520 is always present.
521 - `"type"` - Indicates that the type position (within curly brackets)
522 is required (not just that if present, it is a valid type). You
523 might use this with `@throws` or `@typedef` which might otherwise
524 normally have their types optional. See the type groups 3-5 above.
525 - `"typeOrName"` - Must have either type (e.g., `@throws {aType}`) or
526 name (`@throws Some text`); does not require that both exist but
527 disallows just an empty tag.
528
529<a name="eslint-plugin-jsdoc-advanced"></a>
530## Advanced
531
532<a name="eslint-plugin-jsdoc-advanced-ast-and-selectors"></a>
533### AST and Selectors
534
535For various rules, one can add to the environments to which the rule applies
536by using the `contexts` option.
537
538This option works with [ESLint's selectors](https://eslint.org/docs/developer-guide/selectors) which are [esquery](https://github.com/estools/esquery/#readme)
539expressions one may use to target a specific node type or types, including
540subsets of the type(s) such as nodes with certain children or attributes.
541
542These expressions are used within ESLint plugins to find those parts of
543your files' code which are of interest to check. However, in
544`eslint-plugin-jsdoc`, we also allow you to use these selectors to define
545additional contexts where you wish our own rules to be applied.
546
547<a name="eslint-plugin-jsdoc-advanced-ast-and-selectors-contexts-format"></a>
548#### <code>contexts</code> format
549
550While at their simplest, these can be an array of string selectors, one can
551also supply an object with `context` (in place of the string) and one of two
552properties:
553
5541. For `require-jsdoc`, there is also a `inlineCommentBlock` property. See
555 that rule for details.
5561. For `no-missing-syntax` and `no-restricted-syntax`, there is also a
557 `message` property which allows customization of the message to be shown
558 when the rule is triggered.
5591. For `no-missing-syntax`, there is also a `minimum` property. See that rule.
5601. For other rules, there is a `comment` property which adds to the `context`
561 in requiring that the `comment` AST condition is also met, e.g., to
562 require that certain tags are present and/or or types and type operators
563 are in use. Note that this AST (either for `Jsdoc*` or `JsdocType*` AST)
564 has not been standardized and should be considered experimental.
565 Note that this property might also become obsolete if parsers begin to
566 include JSDoc-structured AST. A
567 [parser](https://github.com/brettz9/jsdoc-eslint-parser/) is available
568 which aims to support comment AST as
569 a first class citizen where comment/comment types can be used anywhere
570 within a normal AST selector but this should only be considered
571 experimental. When using such a parser, you need not use `comment` and
572 can just use a plain string context. The determination of the node on
573 which the comment is attached is also subject to change. It may be
574 currently possible for different structures to map to the same comment
575 block. This is because normally when querying to find either the
576 declaration of the function expression for
577 `const quux = function () {}`, the associated comment would,
578 in both cases, generally be expected to be on the line above both, rather
579 than to be immediately preceding the funciton (in the case of the
580 function). See [@es-joy/jsdoccomment](https://github.com/es-joy/jsdoccomment)
581 for the precise structure of the comment (and comment type) nodes.
582
583<a name="eslint-plugin-jsdoc-advanced-ast-and-selectors-discovering-available-ast-definitions"></a>
584#### Discovering available AST definitions
585
586To know all of the AST definitions one may target, it will depend on the
587[parser](https://eslint.org/docs/user-guide/configuring#specifying-parser)
588you are using with ESLint (e.g., `espree` is the default parser for ESLint,
589and this follows [EStree AST](https://github.com/estree/estree) but
590to support the the latest experimental features of JavaScript, one may use
591`@babel/eslint-parser` or to be able to have one's rules (including JSDoc rules)
592apply to TypeScript, one may use `@typescript-eslint/parser`, etc.
593
594So you can look up a particular parser to see its rules, e.g., browse through
595the [ESTree docs](https://github.com/estree/estree) as used by Espree or see
596ESLint's [overview of the structure of AST](https://eslint.org/docs/developer-guide/working-with-custom-parsers#the-ast-specification).
597
598However, it can sometimes be even more helpful to get an idea of AST by just
599providing some of your JavaScript to the wonderful
600[AST Explorer](https://astexplorer.net/) tool and see what AST is built out
601of your code. You can set the tool to the specific parser which you are using.
602
603<a name="eslint-plugin-jsdoc-advanced-ast-and-selectors-uses-tips-for-ast"></a>
604#### Uses/Tips for AST
605
606And if you wish to introspect on the AST of code within your projects, you can
607use [eslint-plugin-query](https://github.com/brettz9/eslint-plugin-query).
608Though it also works as a plugin, you can use it with its own CLI, e.g.,
609to search your files for matching esquery selectors, optionally showing
610it as AST JSON.
611
612Tip: If you want to more deeply understand not just the resulting AST tree
613structures for any given code but also the syntax for esquery selectors so
614that you can, for example, find only those nodes with a child of a certain
615type, you can set the "Transform" feature to ESLint and test out
616esquery selectors in place of the selector expression (e.g., replace
617`'VariableDeclaration > VariableDeclarator > Identifier[name="someVar"]'` as
618we have
619[here](https://astexplorer.net/#/gist/71a93130c19599d6f197bddb29c13a59/latest))
620to the selector you wish so as to get messages reported in the bottom right
621pane which match your [esquery](https://github.com/estools/esquery/#readme)
622selector).
623
624<a name="eslint-plugin-jsdoc-rules"></a>
625## Rules
626
627<a name="eslint-plugin-jsdoc-rules-check-access"></a>
628### <code>check-access</code>
629
630Checks that `@access` tags use one of the following values:
631
632- "package", "private", "protected", "public"
633
634Also reports:
635
636- Mixing of `@access` with `@public`, `@private`, `@protected`, or `@package`
637 on the same doc block.
638- Use of multiple instances of `@access` (or the `@public`, etc. style tags)
639 on the same doc block.
640
641|||
642|---|---|
643|Context|everywhere|
644|Tags|`@access`|
645|Recommended|false|
646|Settings||
647|Options||
648
649The following patterns are considered problems:
650
651````js
652/**
653 * @access foo
654 */
655function quux (foo) {
656
657}
658// Message: Missing valid JSDoc @access level.
659
660/**
661 * @access foo
662 */
663function quux (foo) {
664
665}
666// Settings: {"jsdoc":{"ignorePrivate":true}}
667// Message: Missing valid JSDoc @access level.
668
669/**
670 * @accessLevel foo
671 */
672function quux (foo) {
673
674}
675// Settings: {"jsdoc":{"tagNamePreference":{"access":"accessLevel"}}}
676// Message: Missing valid JSDoc @accessLevel level.
677
678/**
679 * @access
680 */
681function quux (foo) {
682
683}
684// Settings: {"jsdoc":{"tagNamePreference":{"access":false}}}
685// Message: Unexpected tag `@access`
686
687class MyClass {
688 /**
689 * @access
690 */
691 myClassField = 1
692}
693// Message: Missing valid JSDoc @access level.
694
695/**
696 * @access public
697 * @public
698 */
699function quux (foo) {
700
701}
702// Message: The @access tag may not be used with specific access-control tags (@package, @private, @protected, or @public).
703
704/**
705 * @access public
706 * @access private
707 */
708function quux (foo) {
709
710}
711// Message: At most one access-control tag may be present on a jsdoc block.
712
713/**
714 * @access public
715 * @access private
716 */
717function quux (foo) {
718
719}
720// Settings: {"jsdoc":{"ignorePrivate":true}}
721// Message: At most one access-control tag may be present on a jsdoc block.
722
723/**
724 * @public
725 * @private
726 */
727function quux (foo) {
728
729}
730// Message: At most one access-control tag may be present on a jsdoc block.
731
732/**
733 * @public
734 * @private
735 */
736function quux (foo) {
737
738}
739// Settings: {"jsdoc":{"ignorePrivate":true}}
740// Message: At most one access-control tag may be present on a jsdoc block.
741
742/**
743 * @public
744 * @public
745 */
746function quux (foo) {
747
748}
749// Message: At most one access-control tag may be present on a jsdoc block.
750````
751
752The following patterns are not considered problems:
753
754````js
755/**
756 *
757 */
758function quux (foo) {
759
760}
761
762/**
763 * @access public
764 */
765function quux (foo) {
766
767}
768
769/**
770 * @accessLevel package
771 */
772function quux (foo) {
773
774}
775// Settings: {"jsdoc":{"tagNamePreference":{"access":"accessLevel"}}}
776
777class MyClass {
778 /**
779 * @access private
780 */
781 myClassField = 1
782}
783
784/**
785 * @public
786 */
787function quux (foo) {
788
789}
790
791/**
792 * @private
793 */
794function quux (foo) {
795
796}
797// Settings: {"jsdoc":{"ignorePrivate":true}}
798````
799
800
801<a name="eslint-plugin-jsdoc-rules-check-alignment"></a>
802### <code>check-alignment</code>
803
804Reports invalid alignment of JSDoc block asterisks.
805
806|||
807|---|---|
808|Context|everywhere|
809|Tags|N/A|
810|Recommended|true|
811
812The following patterns are considered problems:
813
814````js
815/**
816 * @param {Number} foo
817 */
818function quux (foo) {
819 // with spaces
820}
821// Message: Expected JSDoc block to be aligned.
822
823/**
824 * @param {Number} foo
825 */
826function quux (foo) {
827 // with tabs
828}
829// Message: Expected JSDoc block to be aligned.
830
831/**
832 * @param {Number} foo
833 */
834function quux (foo) {
835 // with spaces
836}
837// Message: Expected JSDoc block to be aligned.
838
839/**
840* @param {Number} foo
841*/
842function quux (foo) {
843 // with spaces
844}
845// Message: Expected JSDoc block to be aligned.
846
847/**
848 * @param {Number} foo
849 */
850function quux (foo) {
851
852}
853// Message: Expected JSDoc block to be aligned.
854
855 /**
856 * @param {Number} foo
857 */
858function quux (foo) {
859
860}
861// Message: Expected JSDoc block to be aligned.
862
863 /**
864 * @param {Number} foo
865 */
866function quux (foo) {
867
868}
869// Message: Expected JSDoc block to be aligned.
870
871/**
872 * @param {Number} foo
873 */
874 function quux (foo) {
875
876 }
877// Message: Expected JSDoc block to be aligned.
878
879/**
880 * A jsdoc not attached to any node.
881 */
882// Message: Expected JSDoc block to be aligned.
883
884class Foo {
885 /**
886 * Some method
887 * @param a
888 */
889 quux(a) {}
890}
891// Message: Expected JSDoc block to be aligned.
892````
893
894The following patterns are not considered problems:
895
896````js
897/**
898 * Desc
899 *
900 * @param {Number} foo
901 */
902function quux (foo) {
903
904}
905
906/**
907 * Desc
908 *
909 * @param {{
910 foo: Bar,
911 bar: Baz
912 * }} foo
913 *
914 */
915function quux (foo) {
916
917}
918
919/* <- JSDoc must start with 2 stars.
920 * So this is unchecked.
921 */
922function quux (foo) {}
923
924/**
925 * @param {Number} foo
926 * @private
927 */
928function quux (foo) {
929 // with spaces
930}
931// Settings: {"jsdoc":{"ignorePrivate":true}}
932
933/**
934 * @param {Number} foo
935 * @access private
936 */
937function quux (foo) {
938 // with spaces
939}
940// Settings: {"jsdoc":{"ignorePrivate":true}}
941````
942
943
944<a name="eslint-plugin-jsdoc-rules-check-examples"></a>
945### <code>check-examples</code>
946
947Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules. Also
948has options to lint the default values of optional `@param`/`@arg`/`@argument`
949and `@property`/`@prop` tags or the values of `@default`/`@defaultvalue` tags.
950
951<a name="eslint-plugin-jsdoc-rules-check-examples-options-1"></a>
952#### Options
953
954The options below all default to no-op/`false` except as noted.
955
956<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-captionrequired"></a>
957##### <code>captionRequired</code>
958
959JSDoc specs use of an optional `<caption>` element at the beginning of
960`@example`.
961
962The option `captionRequired` insists on a `<caption>` being present at
963the beginning of any `@example`.
964
965Used only for `@example`.
966
967<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-examplecoderegex-and-rejectexamplecoderegex"></a>
968##### <code>exampleCodeRegex</code> and <code>rejectExampleCodeRegex</code>
969
970JSDoc does not specify a formal means for delimiting code blocks within
971`@example` (it uses generic syntax highlighting techniques for its own
972syntax highlighting). The following options determine whether a given
973`@example` tag will have the `check-examples` checks applied to it:
974
975* `exampleCodeRegex` - Regex which whitelists lintable
976 examples. If a parenthetical group is used, the first one will be used,
977 so you may wish to use `(?:...)` groups where you do not wish the
978 first such group treated as one to include. If no parenthetical group
979 exists or matches, the whole matching expression will be used.
980 An example might be ````"^```(?:js|javascript)([\\s\\S]*)```\s*$"````
981 to only match explicitly fenced JavaScript blocks. Defaults to only
982 using the `u` flag, so to add your own flags, encapsulate your
983 expression as a string, but like a literal, e.g., ````/```js.*```/gi````.
984 Note that specifying a global regular expression (i.e., with `g`) will
985 allow independent linting of matched blocks within a single `@example`.
986* `rejectExampleCodeRegex` - Regex blacklist which rejects
987 non-lintable examples (has priority over `exampleCodeRegex`). An example
988 might be ```"^`"``` to avoid linting fenced blocks which may indicate
989 a non-JavaScript language. See `exampleCodeRegex` on how to add flags
990 if the default `u` is not sufficient.
991
992If neither is in use, all examples will be matched. Note also that even if
993`captionRequired` is not set, any initial `<caption>` will be stripped out
994before doing the regex matching.
995
996<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-paddedindent"></a>
997##### <code>paddedIndent</code>
998
999This integer property allows one to add a fixed amount of whitespace at the
1000beginning of the second or later lines of the example to be stripped so as
1001to avoid linting issues with the decorative whitespace. For example, if set
1002to a value of `4`, the initial whitespace below will not trigger `indent`
1003rule errors as the extra 4 spaces on each subsequent line will be stripped
1004out before evaluation.
1005
1006```js
1007/**
1008 * @example
1009 * anArray.filter((a) => {
1010 * return a.b;
1011 * });
1012 */
1013```
1014
1015Only applied to `@example` linting.
1016
1017<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-reportunuseddisabledirectives"></a>
1018##### <code>reportUnusedDisableDirectives</code>
1019
1020If not set to `false`, `reportUnusedDisableDirectives` will report disabled
1021directives which are not used (and thus not needed). Defaults to `true`.
1022Corresponds to ESLint's [`--report-unused-disable-directives`](https://eslint.org/docs/user-guide/command-line-interface#--report-unused-disable-directives).
1023
1024Inline ESLint config within `@example` JavaScript is allowed (or within
1025`@default`, etc.), though the disabling of ESLint directives which are not
1026needed by the resolved rules will be reported as with the ESLint
1027`--report-unused-disable-directives` command.
1028
1029<a name="eslint-plugin-jsdoc-rules-check-examples-options-for-determining-eslint-rule-applicability-allowinlineconfig-nodefaultexamplerules-matchingfilename-configfile-checkeslintrc-and-baseconfig"></a>
1030#### Options for Determining ESLint Rule Applicability (<code>allowInlineConfig</code>, <code>noDefaultExampleRules</code>, <code>matchingFileName</code>, <code>configFile</code>, <code>checkEslintrc</code>, and <code>baseConfig</code>)
1031
1032The following options determine which individual ESLint rules will be
1033applied to the JavaScript found within the `@example` tags (as determined
1034to be applicable by the above regex options) or for the other tags checked by
1035`checkDefaults`, `checkParams`, or `checkProperties` options. They are ordered
1036by decreasing precedence:
1037
1038* `allowInlineConfig` - If not set to `false`, will allow
1039 inline config within the `@example` to override other config. Defaults
1040 to `true`.
1041* `noDefaultExampleRules` - Setting to `true` will disable the
1042 default rules which are expected to be troublesome for most documentation
1043 use. See the section below for the specific default rules.
1044* `configFile` - A config file. Corresponds to ESLint's [`-c`](https://eslint.org/docs/user-guide/command-line-interface#-c---config).
1045* `matchingFileName` - Option for a file name (even non-existent) to trigger
1046 specific rules defined in one's config; usable with ESLint `.eslintrc.*`
1047 `overrides` -> `files` globs, to apply a desired subset of rules with
1048 `@example` (besides allowing for rules specific to examples, this option
1049 can be useful for enabling reuse of the same rules within `@example` as
1050 with JavaScript Markdown lintable by
1051 [other plugins](https://github.com/eslint/eslint-plugin-markdown), e.g.,
1052 if one sets `matchingFileName` to `dummy.md/*.js` so that `@example`
1053 rules will follow rules for fenced JavaScript blocks within one's Markdown
1054 rules). (In ESLint 6's processor API and `eslint-plugin-markdown` < 2, one
1055 would instead use `dummy.md`.) For `@example` only.
1056* `matchingFileNameDefaults` - As with `matchingFileName` but for use with
1057 `checkDefaults` and defaulting to `.jsdoc-defaults` as extension.
1058* `matchingFileNameParams` - As with `matchingFileName` but for use with
1059 `checkParams` and defaulting to `.jsdoc-params` as extension.
1060* `matchingFileNameProperties` As with `matchingFileName` but for use with
1061 `checkProperties` and defaulting to `.jsdoc-properties` as extension.
1062* `checkEslintrc` - Defaults to `true` in adding rules
1063 based on an `.eslintrc.*` file. Setting to `false` corresponds to
1064 ESLint's [`--no-eslintrc`](https://eslint.org/docs/user-guide/command-line-interface#--no-eslintrc).
1065 If `matchingFileName` is set, this will automatically be `true` and
1066 will use the config corresponding to that file. If `matchingFileName` is
1067 not set and this value is set to `false`, the `.eslintrc.*` configs will
1068 not be checked. If `matchingFileName` is not set, and this is unset or
1069 set to `true`, the `.eslintrc.*` configs will be checked as though the file
1070 name were the same as the file containing the example, with any file
1071 extension changed to `".md/*.js"` (and if there is no file extension,
1072 `"dummy.md/*.js"` will be the result). This allows convenient sharing of
1073 similar rules with often also context-free Markdown as well as use of
1074 `overrides` as described under `matchingFileName`. Note that this option
1075 (whether set by `matchingFileName` or set manually to `true`) may come at
1076 somewhat of a performance penalty as the file's existence is checked by
1077 eslint.
1078* `baseConfig` - Set to an object of rules with the same schema
1079 as `.eslintrc.*` for defaults.
1080
1081<a name="eslint-plugin-jsdoc-rules-check-examples-options-for-determining-eslint-rule-applicability-allowinlineconfig-nodefaultexamplerules-matchingfilename-configfile-checkeslintrc-and-baseconfig-rules-disabled-by-default-unless-nodefaultexamplerules-is-set-to-true"></a>
1082##### Rules Disabled by Default Unless <code>noDefaultExampleRules</code> is Set to <code>true</code>
1083
1084* `eol-last` - Insisting that a newline "always" be at the end is less likely
1085 to be desired in sample code as with the code file convention.
1086* `no-console` - This rule is unlikely to have inadvertent temporary debugging
1087 within examples.
1088* `no-multiple-empty-lines` - This rule may be problematic for projects which
1089 use an initial newline just to start an example. Also, projects may wish to
1090 use extra lines within examples just for easier illustration
1091 purposes.
1092* `no-undef` - Many variables in examples will be `undefined`.
1093* `no-unused-vars` - It is common to define variables for clarity without
1094 always using them within examples.
1095* `padded-blocks` - It can generally look nicer to pad a little even if one's
1096 code follows more stringency as far as block padding.
1097* `jsdoc/require-file-overview` - Shouldn't check example for jsdoc blocks.
1098* `jsdoc/require-jsdoc` - Wouldn't expect jsdoc blocks within jsdoc blocks.
1099* `import/no-unresolved` - One wouldn't generally expect example paths to
1100 resolve relative to the current JavaScript file as one would with real code.
1101* `import/unambiguous` - Snippets in examples are likely too short to always
1102 include full import/export info.
1103* `node/no-missing-import` - See `import/no-unresolved`.
1104* `node/no-missing-require` - See `import/no-unresolved`.
1105
1106For `checkDefaults`, `checkParams`, and `checkProperties`, the following
1107expression-oriented rules will be used by default as well:
1108
1109* `quotes` - Will insist on "double".
1110* `semi` - Will insist on "never"
1111* `strict` - Disabled.
1112* `no-new` - Disabled.
1113* `no-unused-expressions` - Disabled.
1114
1115<a name="eslint-plugin-jsdoc-rules-check-examples-options-for-determining-eslint-rule-applicability-allowinlineconfig-nodefaultexamplerules-matchingfilename-configfile-checkeslintrc-and-baseconfig-options-for-checking-other-than-example-checkdefaults-checkparams-or-checkproperties"></a>
1116##### Options for checking other than <code>@example</code> (<code>checkDefaults</code>, <code>checkParams</code>, or <code>checkProperties</code>)
1117
1118* `checkDefaults` - Whether to check the values of `@default`/`@defaultvalue` tags
1119* `checkParams` - Whether to check `@param`/`@arg`/`@argument` default values
1120* `checkProperties` - Whether to check `@property`/`@prop` default values
1121
1122|||
1123|---|---|
1124|Context|everywhere|
1125|Tags|`example`|
1126|Recommended|false|
1127|Options| *See above* |
1128
1129The following patterns are considered problems:
1130
1131````js
1132/**
1133 * @example alert('hello')
1134 */
1135function quux () {
1136
1137}
1138// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-alert":2,"semi":["error","always"]}},"checkEslintrc":false}]
1139// Message: @example error (no-alert): Unexpected alert.
1140
1141/**
1142 * @example alert('hello')
1143 */
1144class quux {
1145
1146}
1147// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-alert":2,"semi":["error","always"]}},"checkEslintrc":false}]
1148// Message: @example error (no-alert): Unexpected alert.
1149
1150/**
1151 * @example ```js
1152 alert('hello');
1153 ```
1154 */
1155function quux () {
1156
1157}
1158// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
1159// Message: @example error (semi): Extra semicolon.
1160
1161/**
1162 * @example
1163 *
1164 * ```js alert('hello'); ```
1165 */
1166function quux () {
1167
1168}
1169// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js ([\\s\\S]*)```"}]
1170// Message: @example error (semi): Extra semicolon.
1171
1172/**
1173 * @example
1174 * ```js alert('hello'); ```
1175 */
1176var quux = {
1177
1178};
1179// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js ([\\s\\S]*)```"}]
1180// Message: @example error (semi): Extra semicolon.
1181
1182/**
1183 * @example ```
1184 * js alert('hello'); ```
1185 */
1186function quux () {
1187
1188}
1189// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```\njs ([\\s\\S]*)```"}]
1190// Message: @example error (semi): Extra semicolon.
1191
1192/**
1193 * @example <b>Not JavaScript</b>
1194 */
1195function quux () {
1196
1197}
1198/**
1199 * @example quux2();
1200 */
1201function quux2 () {
1202
1203}
1204// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"rejectExampleCodeRegex":"^\\s*<.*>\\s*$"}]
1205// Message: @example error (semi): Extra semicolon.
1206
1207/**
1208 * @example
1209 * quux(); // does something useful
1210 */
1211function quux () {
1212
1213}
1214// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-undef":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":true}]
1215// Message: @example error (no-undef): 'quux' is not defined.
1216
1217/**
1218 * @example <caption>Valid usage</caption>
1219 * quux(); // does something useful
1220 *
1221 * @example
1222 * quux('random unwanted arg'); // results in an error
1223 */
1224function quux () {
1225
1226}
1227// "jsdoc/check-examples": ["error"|"warn", {"captionRequired":true,"checkEslintrc":false}]
1228// Message: Caption is expected for examples.
1229
1230/**
1231 * @example quux();
1232 */
1233function quux () {
1234
1235}
1236// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1237// Message: @example error (indent): Expected indentation of 0 spaces but found 1.
1238
1239/**
1240 * @example test() // eslint-disable-line semi
1241 */
1242function quux () {}
1243// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false,"noDefaultExampleRules":true,"reportUnusedDisableDirectives":true}]
1244// Message: @example error: Unused eslint-disable directive (no problems were reported from 'semi').
1245
1246/**
1247 * @example
1248 test() // eslint-disable-line semi
1249 */
1250function quux () {}
1251// "jsdoc/check-examples": ["error"|"warn", {"allowInlineConfig":false,"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"noDefaultExampleRules":true}]
1252// Message: @example error (semi): Missing semicolon.
1253
1254/**
1255 * @example const i = 5;
1256 * quux2()
1257 */
1258function quux2 () {
1259
1260}
1261// "jsdoc/check-examples": ["error"|"warn", {"matchingFileName":"../../jsdocUtils.js"}]
1262// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
1263
1264/**
1265 * @example const i = 5;
1266 * quux2()
1267 */
1268function quux2 () {
1269
1270}
1271// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
1272
1273/**
1274 * @example const i = 5;
1275 * quux2()
1276 */
1277function quux2 () {
1278
1279}
1280// "jsdoc/check-examples": ["error"|"warn", {"paddedIndent":2}]
1281// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
1282
1283/**
1284 * @example
1285 * const i = 5;
1286 * quux2()
1287 */
1288function quux2 () {
1289
1290}
1291// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
1292
1293/**
1294 * @example const idx = 5;
1295 * quux2()
1296 */
1297function quux2 () {
1298
1299}
1300// "jsdoc/check-examples": ["error"|"warn", {"matchingFileName":"dummy.js"}]
1301// Message: @example error (semi): Missing semicolon.
1302
1303/**
1304 * @example const idx = 5;
1305 *
1306 * quux2()
1307 */
1308function quux2 () {
1309
1310}
1311// "jsdoc/check-examples": ["error"|"warn", {"matchingFileName":"dummy.js"}]
1312// Message: @example error (semi): Missing semicolon.
1313
1314/**
1315 * @example const idx = 5;
1316 *
1317 * quux2()
1318 */
1319function quux2 () {
1320
1321}
1322// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false,"matchingFileName":"dummy.js"}]
1323// Message: @example error: Parsing error: The keyword 'const' is reserved
1324
1325/**
1326 * @example // begin
1327 alert('hello')
1328 // end
1329 */
1330function quux () {
1331
1332}
1333// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["warn","always"]}},"checkEslintrc":false,"exampleCodeRegex":"// begin[\\s\\S]*// end","noDefaultExampleRules":true}]
1334// Message: @example warning (semi): Missing semicolon.
1335
1336/**
1337 * @typedef {string} Foo
1338 * @example <caption></caption>
1339 * 'foo'
1340 */
1341// "jsdoc/check-examples": ["error"|"warn", {"captionRequired":true,"checkEslintrc":false}]
1342// Message: Caption is expected for examples.
1343
1344/**
1345 * @example
1346 * const list: number[] = [1, 2, 3]
1347 * quux(list);
1348 */
1349function quux () {
1350
1351}
1352// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"checkEslintrc":false}]
1353// Message: @example error (semi): Missing semicolon.
1354
1355/**
1356 * @example
1357 * const test = something.find((_) => {
1358 * return _
1359 * });
1360 */
1361function quux () {
1362
1363}
1364// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}}}]
1365// Message: @example error (semi): Missing semicolon.
1366
1367/**
1368 * @example <caption>Say `Hello!` to the user.</caption>
1369 * First, import the function:
1370 *
1371 * ```js
1372 * import popup from './popup'
1373 * const aConstInSameScope = 5;
1374 * ```
1375 *
1376 * Then use it like this:
1377 *
1378 * ```js
1379 * const aConstInSameScope = 7;
1380 * popup('Hello!')
1381 * ```
1382 *
1383 * Here is the result on macOS:
1384 *
1385 * ![Screenshot](path/to/screenshot.jpg)
1386 */
1387// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"checkEslintrc":false,"exampleCodeRegex":"/^```(?:js|javascript)\\n([\\s\\S]*?)```$/gm"}]
1388// Message: @example error (semi): Missing semicolon.
1389
1390/**
1391 * @example // begin
1392 alert('hello')
1393 // end
1394 * And here is another example:
1395 // begin
1396 alert('there')
1397 // end
1398 */
1399function quux () {
1400
1401}
1402// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["warn","always"]}},"checkEslintrc":false,"exampleCodeRegex":"/\\/\\/ begin[\\s\\S]*?// end/g","noDefaultExampleRules":true}]
1403// Message: @example warning (semi): Missing semicolon.
1404
1405/**
1406 * @example
1407 * quux();
1408 */
1409function quux () {
1410
1411}
1412// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1413// Message: @example error (indent): Expected indentation of 0 spaces but found 2.
1414
1415/**
1416 * @default 'abc'
1417 */
1418const str = 'abc';
1419// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":true}]
1420// Message: @default error (quotes): Strings must use doublequote.
1421
1422/**
1423 * @param {myType} [name='abc']
1424 */
1425function quux () {
1426}
1427// "jsdoc/check-examples": ["error"|"warn", {"checkParams":true}]
1428// Message: @param error (quotes): Strings must use doublequote.
1429
1430/**
1431 * @property {myType} [name='abc']
1432 */
1433const obj = {};
1434// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":true}]
1435// Message: @property error (quotes): Strings must use doublequote.
1436
1437/**
1438 * Test function.
1439 *
1440 * @example <caption>functionName (paramOne: string, paramTwo?: any,
1441 * paramThree?: any): boolean</caption> test()
1442 *
1443 * @param {string} paramOne Parameter description.
1444 * @param {any} [paramTwo] Parameter description.
1445 * @param {any} [paramThree] Parameter description.
1446 * @returns {boolean} Return description.
1447 */
1448const functionName = function (paramOne, paramTwo,
1449 paramThree) {
1450 return false;
1451};
1452// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"captionRequired":true,"checkEslintrc":false}]
1453// Message: @example error (semi): Missing semicolon.
1454````
1455
1456The following patterns are not considered problems:
1457
1458````js
1459/**
1460 * @example ```js
1461 alert('hello');
1462 ```
1463 */
1464function quux () {
1465
1466}
1467// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
1468
1469/**
1470 * @example ```js
1471 alert('hello');
1472 ```
1473 */
1474function quux () {
1475
1476}
1477// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"exampleCodeRegex":"/```js([\\s\\S]*)```/"}]
1478
1479/**
1480 * @example
1481 * // arbitrary example content
1482 */
1483function quux () {
1484
1485}
1486// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false}]
1487
1488/**
1489 * @example
1490 * quux(); // does something useful
1491 */
1492function quux () {
1493
1494}
1495// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"no-undef":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1496
1497/**
1498 * @example quux();
1499 */
1500function quux () {
1501
1502}
1503// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1504
1505/**
1506 * @example <caption>Valid usage</caption>
1507 * quux(); // does something useful
1508 *
1509 * @example <caption>Invalid usage</caption>
1510 * quux('random unwanted arg'); // results in an error
1511 */
1512function quux () {
1513
1514}
1515// "jsdoc/check-examples": ["error"|"warn", {"captionRequired":true,"checkEslintrc":false}]
1516
1517/**
1518 * @example test() // eslint-disable-line semi
1519 */
1520function quux () {}
1521// "jsdoc/check-examples": ["error"|"warn", {"checkEslintrc":false,"noDefaultExampleRules":true,"reportUnusedDisableDirectives":false}]
1522
1523/**
1524 * @example
1525 test() // eslint-disable-line semi
1526 */
1527function quux () {}
1528// "jsdoc/check-examples": ["error"|"warn", {"allowInlineConfig":true,"baseConfig":{"rules":{"semi":["error","always"]}},"checkEslintrc":false,"noDefaultExampleRules":true}]
1529
1530/**
1531 * @example ```js
1532 alert('hello')
1533 ```
1534 */
1535var quux = {
1536
1537};
1538// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"semi":["error","never"]}},"checkEslintrc":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
1539
1540/**
1541 * @example
1542 * foo(function (err) {
1543 * throw err;
1544 * });
1545 */
1546function quux () {}
1547// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1548
1549/**
1550 * @example
1551 * const list: number[] = [1, 2, 3];
1552 * quux(list);
1553 */
1554function quux () {
1555
1556}
1557// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"checkEslintrc":false}]
1558
1559/**
1560 * @example const ident = 5;
1561 * quux2();
1562 * bar();
1563 */
1564function quux2 () {
1565
1566}
1567// "jsdoc/check-examples": ["error"|"warn", {"paddedIndent":2}]
1568
1569/**
1570 * @example
1571 * function quux() {
1572 * bar();
1573 * }
1574 */
1575function quux () {
1576
1577}
1578// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"rules":{"indent":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1579
1580// Comment
1581a();
1582
1583export default {};
1584
1585/**
1586 *
1587 */
1588function f () {
1589
1590}
1591
1592/**
1593 * Does quux
1594 * @example
1595 * // Do it!
1596 * quux();
1597 */
1598function quux () {
1599}
1600// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"plugins":["jsdoc"],"rules":{"jsdoc/require-file-overview":["error"]}},"checkEslintrc":false,"noDefaultExampleRules":false}]
1601
1602/**
1603 * @default "abc"
1604 */
1605const str = 'abc';
1606// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":true}]
1607
1608/**
1609 * @default
1610 */
1611const str = 'abc';
1612// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":true}]
1613
1614/**
1615 * @param {myType} [name="abc"]
1616 */
1617function quux () {
1618}
1619// "jsdoc/check-examples": ["error"|"warn", {"checkParams":true}]
1620
1621/**
1622 * @param {myType} name
1623 */
1624function quux () {
1625}
1626// "jsdoc/check-examples": ["error"|"warn", {"checkParams":true}]
1627
1628/**
1629 * @property {myType} [name="abc"]
1630 */
1631const obj = {};
1632// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":true}]
1633
1634/**
1635 * @property {myType} [name]
1636 */
1637const obj = {};
1638// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":true}]
1639
1640/**
1641 * @default 'abc'
1642 */
1643const str = 'abc';
1644// "jsdoc/check-examples": ["error"|"warn", {"checkDefaults":false,"matchingFileNameDefaults":"dummy.js"}]
1645
1646/**
1647 * @param {myType} [name='abc']
1648 */
1649function quux () {
1650}
1651// "jsdoc/check-examples": ["error"|"warn", {"checkParams":false,"matchingFileNameParams":"dummy.js"}]
1652
1653/**
1654 * @property {myType} [name='abc']
1655 */
1656const obj = {};
1657// "jsdoc/check-examples": ["error"|"warn", {"checkProperties":false,"matchingFileNameProperties":"dummy.js"}]
1658
1659/**
1660 * Test function.
1661 *
1662 * @example <caption>functionName (paramOne: string, paramTwo?: any,
1663 * paramThree?: any): boolean</caption> test();
1664 *
1665 * @param {string} paramOne Parameter description.
1666 * @param {any} [paramTwo] Parameter description.
1667 * @param {any} [paramThree] Parameter description.
1668 * @returns {boolean} Return description.
1669 */
1670const functionName = function (paramOne, paramTwo,
1671 paramThree) {
1672 return false;
1673};
1674// "jsdoc/check-examples": ["error"|"warn", {"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"captionRequired":true,"checkEslintrc":false}]
1675````
1676
1677
1678<a name="eslint-plugin-jsdoc-rules-check-indentation"></a>
1679### <code>check-indentation</code>
1680
1681Reports invalid padding inside JSDoc blocks.
1682
1683Ignores parts enclosed in Markdown "code block"'s. For example,
1684the following description is not reported:
1685
1686```js
1687/**
1688 * Some description:
1689 * ```html
1690 * <section>
1691 * <title>test</title>
1692 * </section>
1693 * ```
1694 */
1695```
1696
1697<a name="eslint-plugin-jsdoc-rules-check-indentation-options-2"></a>
1698#### Options
1699
1700This rule has an object option.
1701
1702<a name="eslint-plugin-jsdoc-rules-check-indentation-options-2-excludetags"></a>
1703##### <code>excludeTags</code>
1704
1705Array of tags (e.g., `['example', 'description']`) whose content will be
1706"hidden" from the `check-indentation` rule. Defaults to `['example']`.
1707
1708By default, the whole JSDoc block will be checked for invalid padding.
1709That would include `@example` blocks too, which can get in the way
1710of adding full, readable examples of code without ending up with multiple
1711linting issues.
1712
1713When disabled (by passing `excludeTags: []` option), the following code *will*
1714report a padding issue:
1715
1716```js
1717/**
1718 * @example
1719 * anArray.filter((a) => {
1720 * return a.b;
1721 * });
1722 */
1723```
1724
1725|||
1726|---|---|
1727|Context|everywhere|
1728|Tags|N/A|
1729|Recommended|false|
1730|Options| `excludeTags` |
1731
1732The following patterns are considered problems:
1733
1734````js
1735/** foo */
1736function quux () {
1737
1738}
1739// Message: There must be no indentation.
1740
1741/**
1742 * foo
1743 *
1744 * @param bar
1745 * baz
1746 */
1747function quux () {
1748
1749}
1750// Message: There must be no indentation.
1751
1752/**
1753 * Foo
1754 * bar
1755 */
1756class Moo {}
1757// Message: There must be no indentation.
1758
1759/**
1760 * foo
1761 *
1762 * @example
1763 * anArray.filter((a) => {
1764 * return a.b;
1765 * });
1766 */
1767function quux () {
1768
1769}
1770// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
1771// Message: There must be no indentation.
1772
1773/**
1774 * foo
1775 *
1776 * @example
1777 * aaaa
1778 * @returns
1779 * eeee
1780 */
1781function quux () {
1782
1783}
1784// Message: There must be no indentation.
1785
1786/**
1787 * foo
1788 * ```html
1789 * <section>
1790 * <title>test</title>
1791 * </section>
1792 * ```
1793 * @returns
1794 * eeee
1795 */
1796function quux () {
1797
1798}
1799// Message: There must be no indentation.
1800
1801/**
1802 * foo
1803 * ``` aaaa```
1804 * @returns
1805 * eeee
1806 */
1807function quux () {
1808
1809}
1810// Message: There must be no indentation.
1811
1812/**
1813* @example <caption>
1814* Here is a long
1815* indented summary of this
1816* example
1817* </caption>
1818* ```js
1819* function hi () {
1820* alert('Hello');
1821* }
1822* ```
1823*/
1824// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
1825// Message: There must be no indentation.
1826
1827/**
1828* @example <caption>
1829* Here is a long
1830* summary of this
1831* example
1832* </caption>
1833* // Code is not wrapped into fenced code block
1834* function hi () {
1835* alert('Hello');
1836* }
1837*/
1838// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
1839// Message: There must be no indentation.
1840````
1841
1842The following patterns are not considered problems:
1843
1844````js
1845/**
1846 * foo
1847 *
1848 * @param bar
1849 * baz
1850 */
1851function quux () {
1852
1853}
1854
1855/*** foo */
1856function quux () {
1857
1858}
1859
1860/**
1861 * foo
1862 *
1863 * @example
1864 * anArray.filter((a) => {
1865 * return a.b;
1866 * });
1867 */
1868function quux () {
1869
1870}
1871
1872/**
1873 * foo
1874 *
1875 * @example
1876 * anArray.filter((a) => {
1877 * return a.b;
1878 * });
1879 * @returns
1880 * eeee
1881 */
1882function quux () {
1883
1884}
1885// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":["example","returns"]}]
1886
1887/**
1888 * foo
1889 * ```html
1890 * <section>
1891 * <title>test</title>
1892 * </section>
1893 * ```
1894 * @returns eeee
1895 */
1896function quux () {
1897
1898}
1899
1900/**
1901 * foo
1902 * ``` aaaa```
1903 * @returns eeee
1904 */
1905function quux () {
1906
1907}
1908
1909/**
1910* @example <caption>
1911* Here is a long
1912* summary of this
1913* example
1914* </caption>
1915* ```js
1916* function hi () {
1917* alert('Hello');
1918* }
1919* ```
1920*/
1921// "jsdoc/check-indentation": ["error"|"warn", {"excludeTags":[]}]
1922````
1923
1924
1925<a name="eslint-plugin-jsdoc-rules-check-line-alignment"></a>
1926### <code>check-line-alignment</code>
1927
1928Reports invalid alignment of JSDoc block lines. This is a
1929[standard recommended to WordPress code](https://make.wordpress.org/core/handbook/best-practices/inline-documentation-standards/javascript/#aligning-comments),
1930for example.
1931
1932<a name="eslint-plugin-jsdoc-rules-check-line-alignment-options-3"></a>
1933#### Options
1934
1935This rule allows one optional string argument. If it is `"always"` then a
1936problem is raised when the lines are not aligned. If it is `"never"` then
1937a problem should be raised when there is more than one space between each
1938line's parts. Defaults to `"never"`.
1939
1940Note that in addition to alignment, both options will ensure at least one
1941space is present after the asterisk delimiter.
1942
1943After the string, an options object is allowed with the following properties.
1944
1945<a name="eslint-plugin-jsdoc-rules-check-line-alignment-options-3-tags"></a>
1946##### <code>tags</code>
1947
1948Use this to change the tags which are sought for alignment changes. *Currently*
1949*only works with the "never" option.* Defaults to an array of
1950`['param', 'arg', 'argument', 'property', 'prop', 'returns', 'return']`.
1951
1952<a name="eslint-plugin-jsdoc-rules-check-line-alignment-options-3-customspacings"></a>
1953##### <code>customSpacings</code>
1954
1955An object with any of the following keys set to an integer. Affects spacing:
1956
1957- `postDelimiter` - after the asterisk (e.g., `* @param`)
1958- `postTag` - after the tag (e.g., `* @param `)
1959- `postType` - after the type (e.g., `* @param {someType} `)
1960- `postName` - after the name (e.g., `* @param {someType} name `)
1961
1962If a spacing is not defined, it defaults to one.
1963
1964|||
1965|---|---|
1966|Context|everywhere|
1967|Options|(a string matching `"always" or "never"` and optional object with `tags` and `customSpacings`)|
1968|Tags|`param`, `property`, `returns` and others added by `tags`|
1969|Aliases|`arg`, `argument`, `prop`, `return`|
1970|Recommended|false|
1971
1972The following patterns are considered problems:
1973
1974````js
1975/**
1976 * Function description.
1977 *
1978 * @param {string} lorem Description.
1979 * @param {int} sit Description multi words.
1980 */
1981const fn = ( lorem, sit ) => {}
1982// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
1983// Message: Expected JSDoc block lines to be aligned.
1984
1985/**
1986 * With tabs.
1987 *
1988 * @param {string} lorem Description.
1989 * @param {int} sit Description multi words.
1990 */
1991 const fn = ( lorem, sit ) => {}
1992// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
1993// Message: Expected JSDoc block lines to be aligned.
1994
1995/**
1996 * Function description.
1997 *
1998 * @param {string} lorem - Description.
1999 * @param {int} sit - Description multi words.
2000 */
2001const fn = ( lorem, sit ) => {}
2002// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2003// Message: Expected JSDoc block lines to be aligned.
2004
2005/**
2006 * Function description.
2007 *
2008 * @param {string} lorem Description.
2009 * @param {int} sit Description multi words.
2010 */
2011const fn = ( lorem, sit ) => {}
2012// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2013// Message: Expected JSDoc block lines to be aligned.
2014
2015/**
2016 * Function description.
2017 *
2018 * @param {string} lorem Description.
2019 * @param {int} sit Description multi words.
2020 */
2021const fn = ( lorem, sit ) => {}
2022// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2023// Message: Expected JSDoc block lines to be aligned.
2024
2025/**
2026 * Function description.
2027 *
2028 * @param {string} lorem Description.
2029 * @param {int} sit Description multi words.
2030 */
2031const fn = ( lorem, sit ) => {}
2032// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2033// Message: Expected JSDoc block lines to be aligned.
2034
2035/**
2036 * Function description.
2037 *
2038 * @param {string} lorem Description.
2039 * @param {int} sit Description multi words.
2040 */
2041const fn = ( lorem, sit ) => {}
2042// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2043// Message: Expected JSDoc block lines to be aligned.
2044
2045/**
2046 * Function description.
2047 *
2048 * @param {string} lorem Description.
2049 * @param {int} sit Description multi words.
2050 */
2051function fn( lorem, sit ) {}
2052// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2053// Message: Expected JSDoc block lines to be aligned.
2054
2055const object = {
2056 /**
2057 * Function description.
2058 *
2059 * @param {string} lorem Description.
2060 * @param {int} sit Description multi words.
2061 */
2062 fn( lorem, sit ) {}
2063}
2064// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2065// Message: Expected JSDoc block lines to be aligned.
2066
2067class ClassName {
2068 /**
2069 * Function description.
2070 *
2071 * @param {string} lorem Description.
2072 * @param {int} sit Description multi words.
2073 */
2074 fn( lorem, sit ) {}
2075}
2076// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2077// Message: Expected JSDoc block lines to be aligned.
2078
2079/**
2080 * Function description.
2081 *
2082 * @arg {string} lorem Description.
2083 * @arg {int} sit Description multi words.
2084 */
2085const fn = ( lorem, sit ) => {}
2086// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2087// Message: Expected JSDoc block lines to be aligned.
2088
2089/**
2090 * @namespace
2091 * @property {object} defaults Description.
2092 * @property {int} defaults.lorem Description multi words.
2093 */
2094const config = {
2095 defaults: {
2096 lorem: 1
2097 }
2098}
2099// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2100// Message: Expected JSDoc block lines to be aligned.
2101
2102/**
2103 * My object.
2104 *
2105 * @typedef {Object} MyObject
2106 *
2107 * @property {string} lorem Description.
2108 * @property {int} sit Description multi words.
2109 */
2110// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2111// Message: Expected JSDoc block lines to be aligned.
2112
2113/**
2114 * My object.
2115 *
2116 * @typedef {Object} MyObject
2117 *
2118 * @property {{a: number, b: string, c}} lorem Description.
2119 * @property {Object.<string, Class>} sit Description multi words.
2120 * @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
2121 * @property {Object.<string, Class>} dolor
2122 */
2123// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2124// Message: Expected JSDoc block lines to be aligned.
2125
2126/**
2127 * My object.
2128 *
2129 * @typedef {Object} MyObject
2130 *
2131 * @property {{a: number, b: string, c}} lorem Description.
2132 * @property {Object.<string, Class>} sit Description multi words.
2133 * @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
2134 * @property {Object.<string, Class>} dolor
2135 */
2136// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["typedef","property"]}]
2137// Message: Expected JSDoc block lines to be aligned.
2138
2139/**
2140 * My function.
2141 *
2142 * @param {string} lorem Description.
2143 * @param {int} sit Description multi words.
2144 */
2145const fn = ( lorem, sit ) => {}
2146// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2147// Message: Expected JSDoc block lines to not be aligned.
2148
2149/**
2150 * My function.
2151 *
2152 * @param {string} lorem Description.
2153 * @param {int} sit Description multi words.
2154 */
2155const fn = ( lorem, sit ) => {}
2156// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2157// Message: Expected JSDoc block lines to not be aligned.
2158
2159/**
2160 * My function.
2161 *
2162 * @param {string} lorem Description.
2163 * @param {int} sit
2164 */
2165const fn = ( lorem, sit ) => {}
2166// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2167// Message: Expected JSDoc block lines to not be aligned.
2168
2169/**
2170 * My function.
2171 *
2172 * @param {string} lorem Description.
2173 * @param {int} sit
2174 */
2175const fn = ( lorem, sit ) => {}
2176// Message: Expected JSDoc block lines to not be aligned.
2177
2178/**
2179 * Function description.
2180 *
2181 * @param {string} lorem Description.
2182 * @param {int} sit Description multi
2183 line without *.
2184 */
2185const fn = ( lorem, sit ) => {}
2186// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2187// Message: Expected JSDoc block lines to be aligned.
2188
2189/**
2190 * My function.
2191 *
2192 * @param {string} lorem Description.
2193 * @param {int} sit
2194 *
2195 * @return {string} Return description
2196 * with multi line, but don't touch.
2197 */
2198const fn = ( lorem, sit ) => {}
2199// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["param"]}]
2200// Message: Expected JSDoc block lines to be aligned.
2201
2202/**
2203 * Only return doc.
2204 *
2205 * @return {boolean} Return description.
2206 */
2207const fn = ( lorem, sit ) => {}
2208// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2209// Message: Expected JSDoc block lines to be aligned.
2210
2211/**
2212 * Creates OS based shortcuts for files, folders, and applications.
2213 *
2214 * @param {object} options Options object for each OS.
2215 * @return {boolean} True = success, false = failed to create the icon
2216 */
2217 function quux () {}
2218// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2219// Message: Expected JSDoc block lines to not be aligned.
2220
2221/**
2222 * Creates OS based shortcuts for files, folders, and applications.
2223 *
2224 * @param {object} options Options object for each OS.
2225 * @return {boolean} True = success, false = failed to create the icon
2226 */
2227 function quux () {}
2228// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2229// Message: Expected JSDoc block lines to not be aligned.
2230
2231/**
2232 * Creates OS based shortcuts for files, folders, and applications.
2233 *
2234 * @param {object} options Options object for each OS.
2235 * @return True = success, false = failed to create the icon
2236 */
2237 function quux () {}
2238// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2239// Message: Expected JSDoc block lines to not be aligned.
2240
2241/**
2242 * Creates OS based shortcuts for files, folders, and applications.
2243 *
2244 * @param options Options object for each OS.
2245 * @return True = success, false = failed to create the icon
2246 */
2247 function quux () {}
2248// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2249// Message: Expected JSDoc block lines to not be aligned.
2250
2251/**
2252 * Creates OS based shortcuts for files, folders, and applications.
2253 *
2254 * @param {object} options Options object for each OS.
2255 * @param {object} other Other.
2256 * @return True = success, false = failed to create the icon
2257 */
2258 function quux () {}
2259// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"tags":["param","return"]}]
2260// Message: Expected JSDoc block lines to not be aligned.
2261
2262/**
2263 * Returns the value stored in the process.env for a given
2264 * environment variable.
2265 *
2266 * @param {string} withPercents '%USERNAME%'
2267 * @param {string} withoutPercents 'USERNAME'
2268 * @return {string} 'bob' || '%USERNAME%'
2269 */
2270function quux () {}
2271// "jsdoc/check-line-alignment": ["error"|"warn", "never"]
2272// Message: Expected JSDoc block lines to not be aligned.
2273
2274/**
2275 * Function description
2276 * description with post delimiter.
2277 *
2278 * @param {string} lorem Description.
2279 * @param {int} sit Description multi words.
2280 */
2281const fn = ( lorem, sit ) => {}
2282// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2283// Message: Expected JSDoc block lines to be aligned.
2284
2285/**
2286 * Function description.
2287 *
2288 * @param {string} lorem Description.
2289 * @param {int} sit Description multi words.
2290 *
2291 * @return {string} Return description.
2292 */
2293const fn = ( lorem, sit ) => {}
2294// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
2295// Message: Expected JSDoc block lines to be aligned.
2296
2297/**
2298 * Function description.
2299 *
2300 * @param {string} lorem Description.
2301 * @param {int} sit Description multi words.
2302 *
2303 * @return {string} Return description.
2304 */
2305const fn = ( lorem, sit ) => {}
2306// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"customSpacings":{"postName":3}}]
2307// Message: Expected JSDoc block lines to be aligned.
2308
2309/**
2310 * Function description.
2311 *
2312 * @param {string} lorem Description.
2313 * @param {int} sit Description multi words.
2314 */
2315const fn = ( lorem, sit ) => {}
2316// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
2317// Message: Expected JSDoc block lines to not be aligned.
2318
2319/**
2320 * Function description.
2321 *
2322 * @param {string} lorem Description.
2323 * @param {int} sit Description multi words.
2324 */
2325const fn = ( lorem, sit ) => {}
2326// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postName":3}}]
2327// Message: Expected JSDoc block lines to not be aligned.
2328````
2329
2330The following patterns are not considered problems:
2331
2332````js
2333/**
2334 * Function description.
2335 *
2336 * @param {string} lorem Description.
2337 * @param {int} sit Description multi words.
2338 */
2339const fn = ( lorem, sit ) => {}
2340// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2341
2342/**
2343 * With tabs.
2344 *
2345 * @param {string} lorem Description.
2346 * @param {int} sit Description multi words.
2347 */
2348 const fn = ( lorem, sit ) => {}
2349// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2350
2351/**
2352 * Function description.
2353 *
2354 * @param {string} lorem - Description.
2355 * @param {int} sit - Description multi words.
2356 */
2357const fn = ( lorem, sit ) => {}
2358// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2359
2360/**
2361 * @param {string} lorem Description.
2362 * @param {int} sit
2363 */
2364const fn = ( lorem, sit ) => {}
2365// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2366
2367/**
2368 * @param {int} sit
2369 * @param {string} lorem Description.
2370 */
2371const fn = ( lorem, sit ) => {}
2372// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2373
2374/**
2375 * No params.
2376 */
2377const fn = () => {}
2378// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2379
2380const fn = ( lorem, sit ) => {}
2381// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2382
2383/**
2384 * Function description.
2385 *
2386 * @param {string} lorem Description.
2387 * @param {int} sit Description multi words.
2388 */
2389function fn( lorem, sit ) {}
2390// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2391
2392const object = {
2393 /**
2394 * Function description.
2395 *
2396 * @param {string} lorem Description.
2397 * @param {int} sit Description multi words.
2398 */
2399 fn( lorem, sit ) {},
2400}
2401// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2402
2403class ClassName {
2404 /**
2405 * Function description.
2406 *
2407 * @param {string} lorem Description.
2408 * @param {int} sit Description multi words.
2409 */
2410 fn( lorem, sit ) {}
2411}
2412// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2413
2414/**
2415 * Function description.
2416 *
2417 * @arg {string} lorem Description.
2418 * @arg {int} sit Description multi words.
2419 */
2420const fn = ( lorem, sit ) => {}
2421// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2422
2423/**
2424 * @namespace
2425 * @property {object} defaults Description.
2426 * @property {int} defaults.lorem Description multi words.
2427 */
2428const config = {
2429 defaults: {
2430 lorem: 1
2431 }
2432}
2433// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2434
2435/**
2436 * My object.
2437 *
2438 * @typedef {Object} MyObject
2439 *
2440 * @property {string} lorem Description.
2441 * @property {int} sit Description multi words.
2442 */
2443// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2444
2445/**
2446 * My object.
2447 *
2448 * @typedef {Object} MyObject
2449 *
2450 * @property {{a: number, b: string, c}} lorem Description.
2451 * @property {Object.<string, Class>} sit Description multi words.
2452 * @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
2453 * @property {Object.<string, Class>} dolor
2454 */
2455// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2456
2457/**
2458 * My object.
2459 *
2460 * @typedef {Object} MyObject
2461 *
2462 * @property {{a: number, b: string, c}} lorem Description.
2463 * @property {Object.<string, Class>} sit Description multi words.
2464 * @property {Object.<string, Class>} amet Description} weird {multi} {{words}}.
2465 * @property {Object.<string, Class>} dolor
2466 */
2467// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["typedef","property"]}]
2468
2469/**
2470 * My object.
2471 *
2472 * @template T
2473 * @template W,X,Y,Z
2474 * @template {string} K - K must be a string or string literal
2475 * @template {{ serious(): string }} Seriousalizable - must have a serious method
2476 *
2477 * @param {{a: number, b: string, c}} lorem Description.
2478 */
2479// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"tags":["template","param"]}]
2480
2481/** @param {number} lorem */
2482const fn = ( lorem ) => {}
2483// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2484
2485/**
2486 * Creates OS based shortcuts for files, folders, and applications.
2487 *
2488 * @param {object} options Options object for each OS.
2489 * @return {boolean} True = success, false = failed to create the icon
2490 */
2491 function quux () {}
2492// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2493
2494/**
2495 * Creates OS based shortcuts for files, folders, and applications.
2496 *
2497 * @param {object} options Options object for each OS.
2498 * @return {boolean}
2499 */
2500 function quux () {}
2501// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2502
2503/**
2504 * Only return doc.
2505 *
2506 * @return {boolean} Return description.
2507 */
2508 function quux () {}
2509// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2510
2511/**
2512 * Not validating without option.
2513 *
2514 * @param {string} lorem Description.
2515 * @param {int} sit Description multi words.
2516 */
2517const fn = ( lorem, sit ) => {}
2518
2519/**
2520 * Creates OS based shortcuts for files, folders, and applications.
2521 *
2522 * @param {object} options Options object for each OS.
2523 * @return {boolean} True = success, false = failed to create the icon
2524 */
2525function quux (options) {}
2526
2527/**
2528 * Creates OS based shortcuts for files, folders, and applications.
2529 *
2530 * @param {object} options Options object for each OS.
2531 * @param {object} other Other.
2532 * @return True = success, false = failed to create the icon
2533 */
2534 function quux () {}
2535// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"tags":["param"]}]
2536
2537/**
2538 * @param parameter Description.
2539 */
2540function func(parameter){
2541
2542}
2543
2544/**
2545 * Function description
2546 * description with post delimiter.
2547 *
2548 * @param {string} lorem Description.
2549 * @param {int} sit Description multi words.
2550 */
2551const fn = ( lorem, sit ) => {}
2552// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"preserveMainDescriptionPostDelimiter":true}]
2553
2554/**
2555 * Function description.
2556 *
2557 * @param {string} lorem Description.
2558 * @param {int} sit Description multi words.
2559 *
2560 * @return {string} Return description.
2561 */
2562const fn = ( lorem, sit ) => {}
2563// "jsdoc/check-line-alignment": ["error"|"warn", "always",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
2564
2565/**
2566 * Function description.
2567 *
2568 * @param {string} lorem Description.
2569 * @param {int} sit Description multi words.
2570 *
2571 * @return {string} Return description.
2572 */
2573const fn = ( lorem, sit ) => {}
2574// "jsdoc/check-line-alignment": ["error"|"warn", "never",{"customSpacings":{"postDelimiter":2,"postTag":3,"postType":2}}]
2575
2576/**
2577 * @param {{
2578 * ids: number[]
2579 * }} params
2580 */
2581const fn = ({ids}) => {}
2582// "jsdoc/check-line-alignment": ["error"|"warn", "always"]
2583````
2584
2585
2586<a name="eslint-plugin-jsdoc-rules-check-param-names"></a>
2587### <code>check-param-names</code>
2588
2589Ensures that parameter names in JSDoc match those in the function declaration.
2590
2591<a name="eslint-plugin-jsdoc-rules-check-param-names-destructuring"></a>
2592#### Destructuring
2593
2594Note that by default the rule will not report parameters present on the docs
2595but non-existing on the function signature when an object rest property is part
2596of that function signature since the seemingly non-existing properties might
2597actually be a part of the object rest property.
2598
2599```js
2600/**
2601 * @param options
2602 * @param options.foo
2603 */
2604function quux ({foo, ...extra}) {}
2605```
2606
2607To require that `extra` be documented--and that any extraneous properties
2608get reported--e.g., if there had been a `@param options.bar` above--you
2609can use the `checkRestProperty` option which insists that the rest
2610property be documented (and that there be no other implicit properties).
2611Note, however, that jsdoc [does not appear](https://github.com/jsdoc/jsdoc/issues/1773)
2612to currently support syntax or output to distinguish rest properties from
2613other properties, so in looking at the docs alone without looking at the
2614function signature, the disadvantage of enabling this option is that it
2615may appear that there is an actual property named `extra`.
2616
2617<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4"></a>
2618#### Options
2619
2620<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-checkrestproperty"></a>
2621##### <code>checkRestProperty</code>
2622
2623See the "Destructuring" section. Defaults to `false`.
2624
2625<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-checktypespattern"></a>
2626##### <code>checkTypesPattern</code>
2627
2628See `require-param` under the option of the same name.
2629
2630<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-enablefixer"></a>
2631##### <code>enableFixer</code>
2632
2633Set to `true` to auto-remove `@param` duplicates (based on identical
2634names).
2635
2636Note that this option will remove duplicates of the same name even if
2637the definitions do not match in other ways (e.g., the second param will
2638be removed even if it has a different type or description).
2639
2640<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-allowextratrailingparamdocs"></a>
2641##### <code>allowExtraTrailingParamDocs</code>
2642
2643If set to `true`, this option will allow extra `@param` definitions (e.g.,
2644representing future expected or virtual params) to be present without needing
2645their presence within the function signature. Other inconsistencies between
2646`@param`'s and present function parameters will still be reported.
2647
2648<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-checkdestructured"></a>
2649##### <code>checkDestructured</code>
2650
2651Whether to check destructured properties. Defaults to `true`.
2652
2653<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-usedefaultobjectproperties"></a>
2654##### <code>useDefaultObjectProperties</code>
2655
2656Set to `true` if you wish to avoid reporting of child property documentation
2657where instead of destructuring, a whole plain object is supplied as default
2658value but you wish its keys to be considered as signalling that the properties
2659are present and can therefore be documented. Defaults to `false`.
2660
2661<a name="eslint-plugin-jsdoc-rules-check-param-names-options-4-disableextrapropertyreporting"></a>
2662##### <code>disableExtraPropertyReporting</code>
2663
2664Whether to check for extra destructured properties. Defaults to `false`. Change
2665to `true` if you want to be able to document properties which are not actually
2666destructured. Keep as `false` if you expect properties to be documented in
2667their own types. Note that extra properties will always be reported if another
2668item at the same level is destructured as destructuring will prevent other
2669access and this option is only intended to permit documenting extra properties
2670that are available and actually used in the function.
2671
2672|||
2673|---|---|
2674|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
2675|Options|`allowExtraTrailingParamDocs`, `checkDestructured`, `checkRestProperty`, `checkTypesPattern`, `useDefaultObjectProperties`, `disableExtraPropertyReporting`|
2676|Tags|`param`|
2677|Aliases|`arg`, `argument`|
2678|Recommended|true|
2679The following patterns are considered problems:
2680
2681````js
2682/**
2683 * @param Foo
2684 */
2685function quux (foo = 'FOO') {
2686
2687}
2688// Message: Expected @param names to be "foo". Got "Foo".
2689
2690/**
2691 * @arg Foo
2692 */
2693function quux (foo = 'FOO') {
2694
2695}
2696// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
2697// Message: Expected @arg names to be "foo". Got "Foo".
2698
2699/**
2700 * @param Foo
2701 */
2702function quux (foo) {
2703
2704}
2705// Message: Expected @param names to be "foo". Got "Foo".
2706
2707/**
2708 * @param Foo.Bar
2709 */
2710function quux (foo) {
2711
2712}
2713// Message: @param path declaration ("Foo.Bar") appears before any real parameter.
2714
2715/**
2716 * @param foo
2717 * @param Foo.Bar
2718 */
2719function quux (foo) {
2720
2721}
2722// Message: @param path declaration ("Foo.Bar") root node name ("Foo") does not match previous real parameter name ("foo").
2723
2724/**
2725 * Assign the project to a list of employees.
2726 * @param {string} employees[].name - The name of an employee.
2727 * @param {string} employees[].department - The employee's department.
2728 */
2729function assign (employees) {
2730
2731};
2732// Message: @param path declaration ("employees[].name") appears before any real parameter.
2733
2734/**
2735 * Assign the project to a list of employees.
2736 * @param {string} employees[].name - The name of an employee.
2737 * @param {string} employees[].name - The employee's department.
2738 */
2739function assign (employees) {
2740
2741};
2742// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2743// Message: Duplicate @param "employees[].name"
2744
2745/**
2746 * @param foo
2747 * @param foo.bar
2748 * @param bar
2749 */
2750function quux (bar, foo) {
2751
2752}
2753// Message: Expected @param names to be "bar, foo". Got "foo, bar".
2754
2755/**
2756 * @param foo
2757 * @param bar
2758 */
2759function quux (foo) {
2760
2761}
2762// Message: @param "bar" does not match an existing function parameter.
2763
2764/**
2765 * @param foo
2766 * @param foo
2767 */
2768function quux (foo) {
2769
2770}
2771// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2772// Message: Duplicate @param "foo"
2773
2774class bar {
2775 /**
2776 * @param foo
2777 * @param foo
2778 */
2779 quux (foo) {
2780
2781 }
2782}
2783// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2784// Message: Duplicate @param "foo"
2785
2786/**
2787 * @param foo
2788 * @param foo
2789 */
2790function quux (foo, bar) {
2791
2792}
2793// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2794// Message: Duplicate @param "foo"
2795
2796/**
2797 * @param foo
2798 * @param foo
2799 */
2800function quux (foo, foo) {
2801
2802}
2803// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2804// Message: Duplicate @param "foo"
2805
2806/**
2807 * @param cfg
2808 * @param cfg.foo
2809 * @param cfg.foo
2810 */
2811function quux ({foo}) {
2812
2813}
2814// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2815// Message: Duplicate @param "cfg.foo"
2816
2817/**
2818 * @param cfg
2819 * @param cfg.foo
2820 * @param cfg.foo
2821 */
2822function quux ({foo}) {
2823
2824}
2825// Message: Duplicate @param "cfg.foo"
2826
2827/**
2828 * @param cfg
2829 * @param cfg.foo
2830 */
2831function quux ({foo, bar}) {
2832
2833}
2834// Message: Missing @param "cfg.bar"
2835
2836/**
2837 * @param cfg
2838 * @param cfg.foo
2839 * @param [cfg.foo]
2840 * @param baz
2841 */
2842function quux ({foo}, baz) {
2843
2844}
2845// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2846// Message: Duplicate @param "cfg.foo"
2847
2848/**
2849 * @param cfg
2850 * @param cfg.foo
2851 * @param [cfg.foo="with a default"]
2852 * @param baz
2853 */
2854function quux ({foo, bar}, baz) {
2855
2856}
2857// Message: Missing @param "cfg.bar"
2858
2859/**
2860 * @param cfg
2861 * @param cfg.foo
2862 * @param [cfg.foo="with a default"]
2863 * @param baz
2864 */
2865function quux ({foo}, baz) {
2866
2867}
2868// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
2869// Message: Duplicate @param "cfg.foo"
2870
2871/**
2872 * @param cfg
2873 * @param [cfg.foo="with a default"]
2874 * @param baz
2875 */
2876function quux ({foo, bar}, baz) {
2877
2878}
2879// Message: Missing @param "cfg.bar"
2880
2881/**
2882 * @param args
2883 */
2884function quux ({a, b}) {
2885
2886}
2887// Message: Missing @param "args.a"
2888
2889/**
2890 * @param args
2891 */
2892function quux ({a, b} = {}) {
2893
2894}
2895// Message: Missing @param "args.a"
2896
2897export class SomeClass {
2898 /**
2899 * @param prop
2900 */
2901 constructor(private property: string) {}
2902}
2903// Message: Expected @param names to be "property". Got "prop".
2904
2905export class SomeClass {
2906 /**
2907 * @param prop
2908 * @param prop.foo
2909 */
2910 constructor(prop: { foo: string, bar: string }) {}
2911}
2912// Message: Missing @param "prop.bar"
2913
2914export class SomeClass {
2915 /**
2916 * @param prop
2917 * @param prop.foo
2918 * @param prop.bar
2919 */
2920 constructor(options: { foo: string, bar: string }) {}
2921}
2922// Message: @param "prop" does not match parameter name "options"
2923
2924export class SomeClass {
2925 /**
2926 * @param options
2927 * @param options.foo
2928 * @param options.bar
2929 */
2930 constructor(options: { foo: string }) {}
2931}
2932// Message: @param "options.bar" does not exist on options
2933
2934/**
2935 * @param foo
2936 */
2937function quux (foo) {
2938
2939}
2940// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
2941// Message: Unexpected tag `@param`
2942
2943/**
2944 * @param {Error} error Exit code
2945 * @param {number} [code = 1] Exit code
2946 */
2947function quux (error, cde = 1) {
2948};
2949// Message: Expected @param names to be "error, cde". Got "error, code".
2950
2951/**
2952 * @param foo
2953 */
2954function quux ([a, b] = []) {
2955
2956}
2957// Message: Missing @param "foo."0""
2958
2959/**
2960 * @param options
2961 * @param options.foo
2962 */
2963function quux ({foo, ...extra}) {
2964}
2965// "jsdoc/check-param-names": ["error"|"warn", {"checkRestProperty":true}]
2966// Message: Missing @param "options.extra"
2967
2968/**
2969 * @param cfg
2970 * @param cfg.foo
2971 * @param cfg.bar
2972 * @param cfg.extra
2973 */
2974function quux ({foo, ...extra}) {
2975
2976}
2977// "jsdoc/check-param-names": ["error"|"warn", {"checkRestProperty":true}]
2978// Message: @param "cfg.bar" does not exist on cfg
2979
2980/**
2981 * Converts an SVGRect into an object.
2982 * @param {SVGRect} bbox - a SVGRect
2983 */
2984const bboxToObj = function ({x, y, width, height}) {
2985 return {x, y, width, height};
2986};
2987// "jsdoc/check-param-names": ["error"|"warn", {"checkTypesPattern":"SVGRect"}]
2988// Message: Missing @param "bbox.x"
2989
2990/**
2991 * Converts an SVGRect into an object.
2992 * @param {object} bbox - a SVGRect
2993 */
2994const bboxToObj = function ({x, y, width, height}) {
2995 return {x, y, width, height};
2996};
2997// Message: Missing @param "bbox.x"
2998
2999module.exports = class GraphQL {
3000 /**
3001 * @param fetchOptions
3002 * @param cacheKey
3003 */
3004 fetch = ({ url, ...options }, cacheKey) => {
3005 }
3006};
3007// "jsdoc/check-param-names": ["error"|"warn", {"checkRestProperty":true}]
3008// Message: Missing @param "fetchOptions.url"
3009
3010/**
3011 * Testing
3012 *
3013 * @param options
3014 * @param options.one One
3015 * @param options.two Two
3016 * @param options.four Four
3017 */
3018function testingEslint(options: {
3019 one: string;
3020 two: string;
3021 three: string;
3022}): string {
3023 return one + two + three;
3024}
3025// Message: Missing @param "options.three"
3026
3027/**
3028 *
3029 */
3030function quux() {
3031
3032}
3033// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
3034// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
3035
3036/**
3037 * @param root
3038 * @param foo
3039 */
3040function quux ({foo, bar}, baz) {
3041
3042}
3043// "jsdoc/check-param-names": ["error"|"warn", {"checkDestructured":false}]
3044// Message: Expected @param names to be "root, baz". Got "root, foo".
3045
3046/**
3047 * Description.
3048 * @param {Object} options
3049 * @param {FooBar} foo
3050 */
3051function quux ({ foo: { bar } }) {}
3052// Message: Missing @param "options.foo"
3053
3054/**
3055 * Description.
3056 * @param {Object} options
3057 * @param options.foo
3058 */
3059function quux ({ foo: { bar } }) {}
3060// Message: Missing @param "options.foo.bar"
3061
3062/**
3063 * Description.
3064 * @param {object} options Options.
3065 * @param {object} options.foo A description.
3066 * @param {object} options.foo.bar
3067 */
3068function foo({ foo: { bar: { baz } }}) {}
3069// Message: Missing @param "options.foo.bar.baz"
3070
3071/**
3072* Returns a number.
3073* @param {Object} props Props.
3074* @param {Object} props.prop Prop.
3075* @param {string} props.prop.a String.
3076* @param {string} props.prop.b String.
3077* @return {number} A number.
3078*/
3079export function testFn1 ({ prop = { a: 1, b: 2 } }) {
3080}
3081// "jsdoc/check-param-names": ["error"|"warn", {"useDefaultObjectProperties":false}]
3082// Message: @param "props.prop.a" does not exist on props
3083
3084/**
3085 * @param {object} cfg
3086 * @param {string} cfg.foo
3087 * @param {string} cfg.bar
3088 * @param {object} cfg.extra
3089 */
3090function quux ({foo}) {
3091
3092}
3093// Message: @param "cfg.bar" does not exist on cfg
3094
3095/**
3096 * @param {object} cfg
3097 * @param {string} cfg.foo
3098 * @param {string} cfg.bar
3099 * @param {object} cfg.extra
3100 */
3101function quux ({foo}) {
3102
3103}
3104// "jsdoc/check-param-names": ["error"|"warn", {"disableExtraPropertyReporting":true}]
3105// Message: @param "cfg.bar" does not exist on cfg
3106
3107/**
3108 * @param {object} root
3109 * @param {object} root.cfg
3110 * @param {object} root.cfg.a
3111 * @param {string} root.cfg.a.foo
3112 * @param {string} root.cfg.a.bar
3113 * @param {object} root.cfg.a.extra
3114 */
3115function quux ({cfg: {a: {foo}}}) {
3116
3117}
3118// Message: @param "root.cfg.a.bar" does not exist on root
3119
3120/**
3121 * @param {object} root
3122 * @param {object} root.cfg
3123 * @param {object} root.cfg.a
3124 * @param {string} root.cfg.a.foo
3125 * @param {string} root.cfg.a.bar
3126 * @param {object} root.cfg.a.extra
3127 */
3128function quux ({cfg: {a: {foo}}}) {
3129
3130}
3131// "jsdoc/check-param-names": ["error"|"warn", {"disableExtraPropertyReporting":true}]
3132// Message: @param "root.cfg.a.bar" does not exist on root
3133
3134/**
3135 * @param {object} root
3136 * @param {object} root.cfg
3137 * @param {string} root.cfg.foo
3138 * @param {string} root.cfg.bar
3139 * @param {object} root.cfg.extra
3140 */
3141function quux ({cfg}) {
3142
3143}
3144// Message: @param "root.cfg.foo" does not exist on root
3145
3146/**
3147 * @param foo
3148 * @param foo
3149 * on another line
3150 */
3151function quux (foo) {
3152
3153}
3154// "jsdoc/check-param-names": ["error"|"warn", {"enableFixer":true}]
3155// Message: Duplicate @param "foo"
3156````
3157
3158The following patterns are not considered problems:
3159
3160````js
3161/**
3162 *
3163 */
3164function quux (foo) {
3165
3166}
3167
3168/**
3169 * @param foo
3170 */
3171function quux (foo) {
3172
3173}
3174
3175/**
3176 * @param foo
3177 * @param bar
3178 */
3179function quux (foo, bar) {
3180
3181}
3182
3183/**
3184 * @param foo
3185 * @param bar
3186 */
3187function quux (foo, bar, baz) {
3188
3189}
3190
3191/**
3192 * @param foo
3193 * @param foo.foo
3194 * @param bar
3195 */
3196function quux (foo, bar) {
3197
3198}
3199
3200/**
3201 * @param args
3202 */
3203function quux (...args) {
3204
3205}
3206
3207/**
3208 * @param foo
3209 * @param foo.a
3210 * @param foo.b
3211 */
3212function quux ({a, b}) {
3213
3214}
3215
3216/**
3217 * @param foo
3218 * @param foo.a
3219 * @param foo.b
3220 */
3221function quux ({"a": A, b}) {
3222
3223}
3224
3225/**
3226 * @param foo
3227 * @param foo."a"
3228 * @param foo.b
3229 */
3230function quux ({a: A, b}) {
3231
3232}
3233
3234/**
3235 * @param foo
3236 * @param foo."a-b"
3237 * @param foo.b
3238 */
3239function quux ({"a-b": A, b}) {
3240
3241}
3242
3243/**
3244 * @param foo
3245 * @param foo.bar
3246 * @param foo.baz
3247 * @param bar
3248 */
3249function quux (foo, bar) {
3250
3251}
3252
3253/**
3254 * Assign the project to a list of employees.
3255 * @param {object[]} employees - The employees who are responsible for the project.
3256 * @param {string} employees[].name - The name of an employee.
3257 * @param {string} employees[].department - The employee's department.
3258 */
3259function assign (employees) {
3260
3261};
3262
3263export class SomeClass {
3264 /**
3265 * @param property
3266 */
3267 constructor(private property: string) {}
3268}
3269
3270export class SomeClass {
3271 /**
3272 * @param options
3273 * @param options.foo
3274 * @param options.bar
3275 */
3276 constructor(options: { foo: string, bar: string }) {}
3277}
3278
3279export class SomeClass {
3280 /**
3281 * @param options
3282 * @param options.foo
3283 * @param options.bar
3284 */
3285 constructor({ foo, bar }: { foo: string, bar: string }) {}
3286}
3287
3288export class SomeClass {
3289 /**
3290 * @param options
3291 * @param options.foo
3292 * @param options.bar
3293 */
3294 constructor({ foo, bar }: { foo: string, bar: string }) {}
3295}
3296
3297/**
3298 * @param {Error} error Exit code
3299 * @param {number} [code = 1] Exit code
3300 */
3301function quux (error, code = 1) {
3302};
3303
3304/**
3305 * @param foo
3306 * @param bar
3307 */
3308function quux (foo) {
3309
3310}
3311// "jsdoc/check-param-names": ["error"|"warn", {"allowExtraTrailingParamDocs":true}]
3312
3313/**
3314 * @param cfg
3315 * @param cfg.foo
3316 * @param baz
3317 */
3318function quux ({foo}, baz) {
3319
3320}
3321
3322/**
3323 * @param cfg
3324 * @param cfg.foo
3325 * @param cfg2
3326 */
3327function quux ({foo}, cfg2) {
3328
3329}
3330
3331/**
3332 * @param cfg
3333 * @param cfg.foo
3334 * @param baz
3335 * @param baz.cfg
3336 */
3337function quux ({foo}, {cfg}) {
3338
3339}
3340
3341/**
3342 * @param options
3343 * @param options.foo
3344 */
3345function quux ({foo, ...extra}) {
3346}
3347
3348/**
3349 * @param foo
3350 * @param bar
3351 */
3352function quux (foo, bar, ...extra) {
3353
3354}
3355
3356/**
3357* Converts an SVGRect into an object.
3358* @param {SVGRect} bbox - a SVGRect
3359*/
3360const bboxToObj = function ({x, y, width, height}) {
3361 return {x, y, width, height};
3362};
3363
3364/**
3365* Converts an SVGRect into an object.
3366* @param {SVGRect} bbox - a SVGRect
3367*/
3368const bboxToObj = function ({x, y, width, height}) {
3369 return {x, y, width, height};
3370};
3371
3372/**
3373* Converts an SVGRect into an object.
3374* @param {object} bbox - a SVGRect
3375*/
3376const bboxToObj = function ({x, y, width, height}) {
3377 return {x, y, width, height};
3378};
3379// "jsdoc/check-param-names": ["error"|"warn", {"checkTypesPattern":"SVGRect"}]
3380
3381class CSS {
3382 /**
3383 * Set one or more CSS properties for the set of matched elements.
3384 *
3385 * @param {Object} propertyObject - An object of property-value pairs to set.
3386 */
3387 setCssObject(propertyObject: {[key: string]: string | number}): void {
3388 }
3389}
3390
3391/**
3392 * Logs a string.
3393 *
3394 * @param input - String to output.
3395 */
3396export default function (input: {
3397 [foo: string]: { a: string; b: string };
3398}): void {
3399 input;
3400}
3401
3402export class Thing {
3403 foo: any;
3404
3405 /**
3406 * @param {} C
3407 */
3408 constructor(C: { new (): any }) {
3409 this.foo = new C();
3410 }
3411}
3412
3413/**
3414 * @param foo
3415 * @param root
3416 */
3417function quux (foo, {bar}) {
3418
3419}
3420// "jsdoc/check-param-names": ["error"|"warn", {"checkDestructured":false}]
3421
3422class A {
3423 /**
3424 * Show a prompt.
3425 * @param hideButton true if button should be hidden, false otherwise
3426 * @param onHidden delegate to call when the prompt is hidden
3427 */
3428 public async showPrompt(hideButton: boolean, onHidden: {(): void}): Promise<void>
3429 {
3430 }
3431}
3432
3433/**
3434 * Description.
3435 * @param {Object} options Options.
3436 * @param {FooBar} options.foo foo description.
3437 */
3438function quux ({ foo: { bar }}) {}
3439
3440/**
3441 * Description.
3442 * @param {FooBar} options
3443 * @param {Object} options.foo
3444 */
3445function quux ({ foo: { bar } }) {}
3446// "jsdoc/check-param-names": ["error"|"warn", {"checkTypesPattern":"FooBar"}]
3447
3448/**
3449 * Description.
3450 * @param {Object} options
3451 * @param {FooBar} options.foo
3452 * @param {FooBar} options.baz
3453 */
3454function quux ({ foo: { bar }, baz: { cfg } }) {}
3455
3456/**
3457 * Item
3458 *
3459 * @param {object} props
3460 * @param {object} props.data - case data
3461 * @param {string} props.data.className - additional css class
3462 * @param props.val
3463 */
3464export default function Item({
3465 data: {
3466 className,
3467 } = {},
3468 val = 4
3469}) {
3470}
3471
3472/**
3473 * @param obj
3474 * @param obj.data
3475 * @param obj.data."0"
3476 * @param obj.data."1"
3477 * @param obj.data."2"
3478 * @param obj.defaulting
3479 * @param obj.defaulting."0"
3480 * @param obj.defaulting."1"
3481 */
3482function Item({
3483 data: [foo, bar, ...baz],
3484 defaulting: [quux, xyz] = []
3485}) {
3486}
3487
3488/**
3489* Returns a number.
3490* @param {Object} props Props.
3491* @param {Object} props.prop Prop.
3492* @param {string} props.prop.a String.
3493* @param {string} props.prop.b String.
3494* @return {number} A number.
3495*/
3496export function testFn1 ({ prop = { a: 1, b: 2 } }) {
3497}
3498// "jsdoc/check-param-names": ["error"|"warn", {"useDefaultObjectProperties":true}]
3499
3500/**
3501 * @param {object} root
3502 * @param {object} root.cfg
3503 * @param {string} root.cfg.foo
3504 * @param {string} root.cfg.bar
3505 * @param {object} root.cfg.extra
3506 */
3507function quux ({cfg}) {
3508
3509}
3510// "jsdoc/check-param-names": ["error"|"warn", {"disableExtraPropertyReporting":true}]
3511
3512class A {
3513 /**
3514 * @param cfg
3515 * @param cfg.abc
3516 */
3517 constructor({
3518 [new.target.prop]: cX,
3519 abc
3520 }) {
3521 }
3522}
3523
3524/**
3525 * @param root
3526 * @param root."0" Ignored
3527 * @param root."1" Our "b"
3528 */
3529const foo = ([, b]) => b;
3530````
3531
3532
3533<a name="eslint-plugin-jsdoc-rules-check-property-names"></a>
3534### <code>check-property-names</code>
3535
3536Ensures that property names in JSDoc are not duplicated on the same block
3537and that nested properties have defined roots.
3538
3539<a name="eslint-plugin-jsdoc-rules-check-property-names-options-5"></a>
3540#### Options
3541
3542<a name="eslint-plugin-jsdoc-rules-check-property-names-options-5-enablefixer-1"></a>
3543##### <code>enableFixer</code>
3544
3545Set to `true` to auto-remove `@property` duplicates (based on
3546identical names).
3547
3548Note that this option will remove duplicates of the same name even if
3549the definitions do not match in other ways (e.g., the second property will
3550be removed even if it has a different type or description).
3551
3552|||
3553|---|---|
3554|Context|Everywhere|
3555|Options|`enableFixer`|
3556|Tags|`property`|
3557|Aliases|`prop`|
3558|Recommended|true|
3559
3560The following patterns are considered problems:
3561
3562````js
3563/**
3564 * @typedef (SomeType) SomeTypedef
3565 * @property Foo.Bar
3566 */
3567// Message: @property path declaration ("Foo.Bar") appears before any real property.
3568
3569/**
3570 * @typedef (SomeType) SomeTypedef
3571 * @property foo
3572 * @property Foo.Bar
3573 */
3574// Message: @property path declaration ("Foo.Bar") root node name ("Foo") does not match previous real property name ("foo").
3575
3576/**
3577 * Assign the project to a list of employees.
3578 * @typedef (SomeType) SomeTypedef
3579 * @property {string} employees[].name - The name of an employee.
3580 * @property {string} employees[].department - The employee's department.
3581 */
3582// Message: @property path declaration ("employees[].name") appears before any real property.
3583
3584/**
3585 * Assign the project to a list of employees.
3586 * @typedef (SomeType) SomeTypedef
3587 * @property {string} employees[].name - The name of an employee.
3588 * @property {string} employees[].name - The employee's department.
3589 */
3590// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3591// Message: Duplicate @property "employees[].name"
3592
3593/**
3594 * @typedef (SomeType) SomeTypedef
3595 * @property foo
3596 * @property foo
3597 */
3598// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3599// Message: Duplicate @property "foo"
3600
3601/**
3602 * @typedef (SomeType) SomeTypedef
3603 * @property foo
3604 * @property foo
3605 */
3606// Message: Duplicate @property "foo"
3607
3608/**
3609 * @typedef (SomeType) SomeTypedef
3610 * @property cfg
3611 * @property cfg.foo
3612 * @property cfg.foo
3613 */
3614function quux ({foo, bar}) {
3615
3616}
3617// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3618// Message: Duplicate @property "cfg.foo"
3619
3620class Test {
3621 /**
3622 * @typedef (SomeType) SomeTypedef
3623 * @property cfg
3624 * @property cfg.foo
3625 * @property cfg.foo
3626 */
3627 quux ({foo, bar}) {
3628
3629 }
3630}
3631// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3632// Message: Duplicate @property "cfg.foo"
3633
3634/**
3635 * @typedef (SomeType) SomeTypedef
3636 * @property cfg
3637 * @property cfg.foo
3638 * @property [cfg.foo]
3639 * @property baz
3640 */
3641function quux ({foo, bar}, baz) {
3642
3643}
3644// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3645// Message: Duplicate @property "cfg.foo"
3646
3647/**
3648 * @typedef (SomeType) SomeTypedef
3649 * @property cfg
3650 * @property cfg.foo
3651 * @property [cfg.foo="with a default"]
3652 * @property baz
3653 */
3654function quux ({foo, bar}, baz) {
3655
3656}
3657// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3658// Message: Duplicate @property "cfg.foo"
3659
3660/**
3661 * @typedef (SomeType) SomeTypedef
3662 * @prop foo
3663 * @prop foo
3664 */
3665// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
3666// "jsdoc/check-property-names": ["error"|"warn", {"enableFixer":true}]
3667// Message: Duplicate @prop "foo"
3668
3669/**
3670 * @typedef (SomeType) SomeTypedef
3671 * @property foo
3672 */
3673// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
3674// Message: Unexpected tag `@property`
3675````
3676
3677The following patterns are not considered problems:
3678
3679````js
3680/**
3681 *
3682 */
3683
3684/**
3685 * @typedef (SomeType) SomeTypedef
3686 * @property foo
3687 */
3688
3689/**
3690 * @typedef (SomeType) SomeTypedef
3691 * @prop foo
3692 */
3693
3694/**
3695 * @typedef (SomeType) SomeTypedef
3696 * @property foo
3697 * @property bar
3698 */
3699
3700/**
3701 * @typedef (SomeType) SomeTypedef
3702 * @property foo
3703 * @property foo.foo
3704 * @property bar
3705 */
3706
3707/**
3708 * Assign the project to a list of employees.
3709 * @typedef (SomeType) SomeTypedef
3710 * @property {object[]} employees - The employees who are responsible for the project.
3711 * @property {string} employees[].name - The name of an employee.
3712 * @property {string} employees[].department - The employee's department.
3713 */
3714
3715/**
3716 * @typedef (SomeType) SomeTypedef
3717 * @property {Error} error Exit code
3718 * @property {number} [code = 1] Exit code
3719 */
3720
3721/**
3722 * @namespace (SomeType) SomeNamespace
3723 * @property {Error} error Exit code
3724 * @property {number} [code = 1] Exit code
3725 */
3726
3727/**
3728 * @class
3729 * @property {Error} error Exit code
3730 * @property {number} [code = 1] Exit code
3731 */
3732function quux (code = 1) {
3733 this.error = new Error('oops');
3734 this.code = code;
3735}
3736
3737/**
3738 * @typedef (SomeType) SomeTypedef
3739 * @property foo
3740 * @property foo.bar
3741 * @property foo.baz
3742 * @property bar
3743 */
3744````
3745
3746
3747<a name="eslint-plugin-jsdoc-rules-check-syntax"></a>
3748### <code>check-syntax</code>
3749
3750Reports against syntax not encouraged for the mode (e.g., Google Closure
3751Compiler in "jsdoc" or "typescript" mode). Note that this rule will not check
3752for types that are wholly invalid for a given mode, as that is covered by
3753`valid-types`.
3754
3755Currently checks against:
3756
3757- Use of `=` in "jsdoc" or "typescript" mode
3758
3759Note that "jsdoc" actually allows Closure syntax, but with another
3760option available for optional parameters (enclosing the name in brackets), the
3761rule is enforced (except under "permissive" and "closure" modes).
3762
3763|||
3764|---|---|
3765|Context|everywhere|
3766|Tags|N/A|
3767|Recommended|false|
3768
3769The following patterns are considered problems:
3770
3771````js
3772/**
3773 * @param {string=} foo
3774 */
3775function quux (foo) {
3776
3777}
3778// Message: Syntax should not be Google Closure Compiler style.
3779````
3780
3781The following patterns are not considered problems:
3782
3783````js
3784/**
3785 * @param {string=} foo
3786 */
3787function quux (foo) {
3788
3789}
3790// Settings: {"jsdoc":{"mode":"closure"}}
3791
3792/**
3793 * @param {string} [foo]
3794 */
3795function quux (foo) {
3796
3797}
3798
3799/**
3800 *
3801 */
3802function quux (foo) {
3803
3804}
3805````
3806
3807
3808<a name="eslint-plugin-jsdoc-rules-check-tag-names"></a>
3809### <code>check-tag-names</code>
3810
3811Reports invalid block tag names.
3812
3813Valid [JSDoc 3 Block Tags](https://jsdoc.app/#block-tags) are:
3814
3815```
3816abstract
3817access
3818alias
3819async
3820augments
3821author
3822borrows
3823callback
3824class
3825classdesc
3826constant
3827constructs
3828copyright
3829default
3830deprecated
3831description
3832enum
3833event
3834example
3835exports
3836external
3837file
3838fires
3839function
3840generator
3841global
3842hideconstructor
3843ignore
3844implements
3845inheritdoc
3846inner
3847instance
3848interface
3849kind
3850lends
3851license
3852listens
3853member
3854memberof
3855memberof!
3856mixes
3857mixin
3858module
3859name
3860namespace
3861override
3862package
3863param
3864private
3865property
3866protected
3867public
3868readonly
3869requires
3870returns
3871see
3872since
3873static
3874summary
3875this
3876throws
3877todo
3878tutorial
3879type
3880typedef
3881variation
3882version
3883yields
3884```
3885
3886`modifies` is also supported (see [source](https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js#L594))
3887but is undocumented.
3888
3889The following synonyms are also recognized if you set them in
3890`tagNamePreference` as a key (or replacement):
3891
3892```
3893arg
3894argument
3895const
3896constructor
3897defaultvalue
3898desc
3899emits
3900exception
3901extends
3902fileoverview
3903func
3904host
3905method
3906overview
3907prop
3908return
3909var
3910virtual
3911yield
3912```
3913
3914If you wish to allow in certain cases both a primary tag name and its
3915alias(es), you can set a normally non-preferred tag name to itself to indicate
3916that you want to allow both the default tag (in this case `@returns`) and a
3917non-default (in this case `return`):
3918
3919```js
3920"tagNamePreference": {
3921 "return": "return",
3922}
3923```
3924
3925Because the tags indicated as replacements in
3926`settings.jsdoc.tagNamePreference` will automatically be considered as valid,
3927the above works.
3928
3929Likewise are the tag keys of `settings.jsdoc.structuredTags` automatically
3930considered as valid (as their defining an expected structure for tags implies
3931the tags may be used).
3932
3933For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
3934(or Closure), when `settings.jsdoc.mode` is set to `typescript` or `closure`,
3935one may also use the following:
3936
3937```
3938template
3939```
3940
3941And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler),
3942when `settings.jsdoc.mode` is set to `closure`, one may use the following (in
3943addition to the jsdoc and TypeScript tags–though replacing `returns` with
3944`return`):
3945
3946```
3947define (synonym of `const` per jsdoc source)
3948dict
3949export
3950externs
3951final
3952implicitCast (casing distinct from that recognized by jsdoc internally)
3953inheritDoc (casing distinct from that recognized by jsdoc internally)
3954noalias
3955nocollapse
3956nocompile
3957noinline
3958nosideeffects
3959polymer
3960polymerBehavior
3961preserve
3962record (synonym of `interface` per jsdoc source)
3963struct
3964suppress
3965unrestricted
3966```
3967
3968...and these undocumented tags which are only in [source](https://github.com/google/closure-compiler/blob/master/src/com/google/javascript/jscomp/parsing/Annotation.java):
3969
3970```
3971closurePrimitive
3972customElement
3973expose
3974hidden
3975idGenerator
3976meaning
3977mixinClass
3978mixinFunction
3979ngInject
3980owner
3981typeSummary
3982wizaction
3983```
3984
3985<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-6"></a>
3986#### Options
3987
3988<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-6-definedtags"></a>
3989##### <code>definedTags</code>
3990
3991Use an array of `definedTags` strings to configure additional, allowed tags.
3992The format is as follows:
3993
3994```json
3995{
3996 "definedTags": ["note", "record"]
3997}
3998```
3999
4000<a name="eslint-plugin-jsdoc-rules-check-tag-names-jsxtags"></a>
4001#### <code>jsxTags</code>
4002
4003If this is set to `true`, all of the following tags used to control JSX output are allowed:
4004
4005```
4006jsx
4007jsxFrag
4008jsxImportSource
4009jsxRuntime
4010```
4011
4012For more information, see the [babel documentation](https://babeljs.io/docs/en/babel-plugin-transform-react-jsx).
4013
4014
4015|||
4016|---|---|
4017|Context|everywhere|
4018|Tags|N/A|
4019|Recommended|true|
4020|Options|`definedTags`|
4021|Settings|`tagNamePreference`, `mode`|
4022
4023The following patterns are considered problems:
4024
4025````js
4026/** @typoo {string} */
4027let a;
4028// Message: Invalid JSDoc tag name "typoo".
4029
4030/** @typoo {string} */
4031let a;
4032// Settings: {"jsdoc":{"structuredTags":{"parameter":{"name":"namepath-referencing","required":["type","name"],"type":true}}}}
4033// Message: Invalid JSDoc tag name "typoo".
4034
4035/**
4036 * @Param
4037 */
4038function quux () {
4039
4040}
4041// Message: Invalid JSDoc tag name "Param".
4042
4043/**
4044 * @foo
4045 */
4046function quux () {
4047
4048}
4049// Message: Invalid JSDoc tag name "foo".
4050
4051/**
4052 * @arg foo
4053 */
4054function quux (foo) {
4055
4056}
4057// Message: Invalid JSDoc tag (preference). Replace "arg" JSDoc tag with "param".
4058
4059/**
4060 * @param foo
4061 */
4062function quux (foo) {
4063
4064}
4065// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
4066// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "arg".
4067
4068/**
4069 * @constructor foo
4070 */
4071function quux (foo) {
4072
4073}
4074// Settings: {"jsdoc":{"tagNamePreference":{"tag constructor":"cons"}}}
4075// Message: Invalid JSDoc tag (preference). Replace "constructor" JSDoc tag with "cons".
4076
4077/**
4078 * @arg foo
4079 */
4080function quux (foo) {
4081
4082}
4083// Settings: {"jsdoc":{"tagNamePreference":{"arg":"somethingDifferent"}}}
4084// Message: Invalid JSDoc tag (preference). Replace "arg" JSDoc tag with "somethingDifferent".
4085
4086/**
4087 * @param foo
4088 */
4089function quux (foo) {
4090
4091}
4092// Settings: {"jsdoc":{"tagNamePreference":{"param":"parameter"}}}
4093// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "parameter".
4094
4095/**
4096 * @bar foo
4097 */
4098function quux (foo) {
4099
4100}
4101// Message: Invalid JSDoc tag name "bar".
4102
4103/**
4104 * @baz @bar foo
4105 */
4106function quux (foo) {
4107
4108}
4109// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["bar"]}]
4110// Message: Invalid JSDoc tag name "baz".
4111
4112/**
4113 * @bar
4114 * @baz
4115 */
4116function quux (foo) {
4117
4118}
4119// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["bar"]}]
4120// Message: Invalid JSDoc tag name "baz".
4121
4122/**
4123 * @todo
4124 */
4125function quux () {
4126
4127}
4128// Settings: {"jsdoc":{"tagNamePreference":{"todo":false}}}
4129// Message: Blacklisted tag found (`@todo`)
4130
4131/**
4132 * @todo
4133 */
4134function quux () {
4135
4136}
4137// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please resolve to-dos or add to the tracker"}}}}
4138// Message: Please resolve to-dos or add to the tracker
4139
4140/**
4141 * @todo
4142 */
4143function quux () {
4144
4145}
4146// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
4147// Message: Please use x-todo instead of todo
4148
4149/**
4150 * @todo
4151 */
4152function quux () {
4153
4154}
4155// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
4156// Message: Please use x-todo instead of todo
4157
4158/**
4159 * @todo
4160 */
4161function quux () {
4162
4163}
4164// Settings: {"jsdoc":{"tagNamePreference":{"todo":55}}}
4165// Message: Invalid `settings.jsdoc.tagNamePreference`. Values must be falsy, a string, or an object.
4166
4167/**
4168 * @property {object} a
4169 * @prop {boolean} b
4170 */
4171function quux () {
4172
4173}
4174// Message: Invalid JSDoc tag (preference). Replace "prop" JSDoc tag with "property".
4175
4176/**
4177 * @abc foo
4178 * @abcd bar
4179 */
4180function quux () {
4181
4182}
4183// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
4184// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["abcd"]}]
4185// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
4186
4187/**
4188 * @abc
4189 * @abcd
4190 */
4191function quux () {
4192
4193}
4194// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
4195// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
4196
4197/**
4198 * @returns
4199 */
4200function quux (foo) {}
4201// Settings: {"jsdoc":{"mode":"closure"}}
4202// Message: Invalid JSDoc tag (preference). Replace "returns" JSDoc tag with "return".
4203
4204/**
4205 * @modifies
4206 * @abstract
4207 * @access
4208 * @alias
4209 * @async
4210 * @augments
4211 * @author
4212 * @borrows
4213 * @callback
4214 * @class
4215 * @classdesc
4216 * @constant
4217 * @constructs
4218 * @copyright
4219 * @default
4220 * @deprecated
4221 * @description
4222 * @enum
4223 * @event
4224 * @example
4225 * @exports
4226 * @external
4227 * @file
4228 * @fires
4229 * @function
4230 * @generator
4231 * @global
4232 * @hideconstructor
4233 * @ignore
4234 * @implements
4235 * @inheritdoc
4236 * @inheritDoc
4237 * @inner
4238 * @instance
4239 * @interface
4240 * @kind
4241 * @lends
4242 * @license
4243 * @listens
4244 * @member
4245 * @memberof
4246 * @memberof!
4247 * @mixes
4248 * @mixin
4249 * @module
4250 * @name
4251 * @namespace
4252 * @override
4253 * @package
4254 * @param
4255 * @private
4256 * @property
4257 * @protected
4258 * @public
4259 * @readonly
4260 * @requires
4261 * @returns
4262 * @see
4263 * @since
4264 * @static
4265 * @summary
4266 * @this
4267 * @throws
4268 * @todo
4269 * @tutorial
4270 * @type
4271 * @typedef
4272 * @variation
4273 * @version
4274 * @yields
4275 */
4276function quux (foo) {}
4277// Settings: {"jsdoc":{"mode":"badMode"}}
4278// Message: Unrecognized value `badMode` for `settings.jsdoc.mode`.
4279
4280/**
4281 * @modifies
4282 * @abstract
4283 * @access
4284 * @alias
4285 * @async
4286 * @augments
4287 * @author
4288 * @borrows
4289 * @callback
4290 * @class
4291 * @classdesc
4292 * @constant
4293 * @constructs
4294 * @copyright
4295 * @default
4296 * @deprecated
4297 * @description
4298 * @enum
4299 * @event
4300 * @example
4301 * @exports
4302 * @external
4303 * @file
4304 * @fires
4305 * @function
4306 * @generator
4307 * @global
4308 * @hideconstructor
4309 * @ignore
4310 * @implements
4311 * @inheritdoc
4312 * @inheritDoc
4313 * @inner
4314 * @instance
4315 * @interface
4316 * @kind
4317 * @lends
4318 * @license
4319 * @listens
4320 * @member
4321 * @memberof
4322 * @memberof!
4323 * @mixes
4324 * @mixin
4325 * @module
4326 * @name
4327 * @namespace
4328 * @override
4329 * @package
4330 * @param
4331 * @private
4332 * @property
4333 * @protected
4334 * @public
4335 * @readonly
4336 * @requires
4337 * @returns
4338 * @see
4339 * @since
4340 * @static
4341 * @summary
4342 * @this
4343 * @throws
4344 * @todo
4345 * @tutorial
4346 * @type
4347 * @typedef
4348 * @variation
4349 * @version
4350 * @yields
4351 * @template
4352 */
4353function quux (foo) {}
4354// Message: Invalid JSDoc tag name "template".
4355
4356/**
4357 * @externs
4358 */
4359function quux (foo) {}
4360// Message: Invalid JSDoc tag name "externs".
4361
4362/** @jsx h */
4363/** @jsxFrag Fragment */
4364/** @jsxImportSource preact */
4365/** @jsxRuntime automatic */
4366// Message: Invalid JSDoc tag name "jsx".
4367````
4368
4369The following patterns are not considered problems:
4370
4371````js
4372/**
4373 * @param foo
4374 */
4375function quux (foo) {
4376
4377}
4378
4379/**
4380 * @memberof! foo
4381 */
4382function quux (foo) {
4383
4384}
4385
4386/**
4387 * @arg foo
4388 */
4389function quux (foo) {
4390
4391}
4392// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
4393
4394/**
4395 * @parameter foo
4396 */
4397function quux (foo) {
4398
4399}
4400// Settings: {"jsdoc":{"structuredTags":{"parameter":{"name":"namepath-referencing","required":["type","name"],"type":true}}}}
4401
4402/**
4403 * @bar foo
4404 */
4405function quux (foo) {
4406
4407}
4408// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["bar"]}]
4409
4410/**
4411 * @baz @bar foo
4412 */
4413function quux (foo) {
4414
4415}
4416// "jsdoc/check-tag-names": ["error"|"warn", {"definedTags":["baz","bar"]}]
4417
4418/**
4419 * @baz @bar foo
4420 */
4421function quux (foo) {
4422
4423}
4424// Settings: {"jsdoc":{"tagNamePreference":{"param":"baz","returns":{"message":"Prefer `bar`","replacement":"bar"},"todo":false}}}
4425
4426/**
4427 * @returns
4428 */
4429function quux (foo) {}
4430
4431/**
4432 * @return
4433 */
4434function quux (foo) {}
4435// Settings: {"jsdoc":{"mode":"closure"}}
4436
4437/**
4438 * @modifies
4439 * @abstract
4440 * @access
4441 * @alias
4442 * @async
4443 * @augments
4444 * @author
4445 * @borrows
4446 * @callback
4447 * @class
4448 * @classdesc
4449 * @constant
4450 * @constructs
4451 * @copyright
4452 * @default
4453 * @deprecated
4454 * @description
4455 * @enum
4456 * @event
4457 * @example
4458 * @exports
4459 * @external
4460 * @file
4461 * @fires
4462 * @function
4463 * @generator
4464 * @global
4465 * @hideconstructor
4466 * @ignore
4467 * @implements
4468 * @inheritdoc
4469 * @inheritDoc
4470 * @inner
4471 * @instance
4472 * @interface
4473 * @kind
4474 * @lends
4475 * @license
4476 * @listens
4477 * @member
4478 * @memberof
4479 * @memberof!
4480 * @mixes
4481 * @mixin
4482 * @module
4483 * @name
4484 * @namespace
4485 * @override
4486 * @package
4487 * @param
4488 * @private
4489 * @property
4490 * @protected
4491 * @public
4492 * @readonly
4493 * @requires
4494 * @returns
4495 * @see
4496 * @since
4497 * @static
4498 * @summary
4499 * @this
4500 * @throws
4501 * @todo
4502 * @tutorial
4503 * @type
4504 * @typedef
4505 * @variation
4506 * @version
4507 * @yields
4508 */
4509function quux (foo) {}
4510
4511/**
4512 * @modifies
4513 * @abstract
4514 * @access
4515 * @alias
4516 * @async
4517 * @augments
4518 * @author
4519 * @borrows
4520 * @callback
4521 * @class
4522 * @classdesc
4523 * @constant
4524 * @constructs
4525 * @copyright
4526 * @default
4527 * @deprecated
4528 * @description
4529 * @enum
4530 * @event
4531 * @example
4532 * @exports
4533 * @external
4534 * @file
4535 * @fires
4536 * @function
4537 * @generator
4538 * @global
4539 * @hideconstructor
4540 * @ignore
4541 * @implements
4542 * @inheritdoc
4543 * @inheritDoc
4544 * @inner
4545 * @instance
4546 * @interface
4547 * @kind
4548 * @lends
4549 * @license
4550 * @listens
4551 * @member
4552 * @memberof
4553 * @memberof!
4554 * @mixes
4555 * @mixin
4556 * @module
4557 * @name
4558 * @namespace
4559 * @override
4560 * @package
4561 * @param
4562 * @private
4563 * @property
4564 * @protected
4565 * @public
4566 * @readonly
4567 * @requires
4568 * @returns
4569 * @see
4570 * @since
4571 * @static
4572 * @summary
4573 * @this
4574 * @throws
4575 * @todo
4576 * @tutorial
4577 * @type
4578 * @typedef
4579 * @variation
4580 * @version
4581 * @yields
4582 * @template
4583 */
4584function quux (foo) {}
4585// Settings: {"jsdoc":{"mode":"typescript"}}
4586
4587/**
4588 * @externs
4589 */
4590function quux (foo) {}
4591// Settings: {"jsdoc":{"mode":"closure"}}
4592
4593/**
4594 *
4595 */
4596function quux (foo) {
4597
4598}
4599
4600/**
4601 * @todo
4602 */
4603function quux () {
4604
4605}
4606
4607/**
4608 * @extends Foo
4609 */
4610function quux () {
4611
4612}
4613// Settings: {"jsdoc":{"tagNamePreference":{"augments":{"message":"@extends is to be used over @augments.","replacement":"extends"}}}}
4614
4615/**
4616 * (Set tag name preference to itself to get aliases to
4617 * work along with main tag name.)
4618 * @augments Bar
4619 * @extends Foo
4620 */
4621function quux () {
4622}
4623// Settings: {"jsdoc":{"tagNamePreference":{"extends":"extends"}}}
4624
4625/**
4626 * Registers the `target` class as a transient dependency; each time the dependency is resolved a new instance will be created.
4627 *
4628 * @param target - The class / constructor function to register as transient.
4629 *
4630 * @example ```ts
4631@transient()
4632class Foo { }
4633```
4634 * @param Time for a new tag
4635 */
4636export function transient<T>(target?: T): T {
4637 // ...
4638}
4639
4640/** @jsx h */
4641/** @jsxFrag Fragment */
4642/** @jsxImportSource preact */
4643/** @jsxRuntime automatic */
4644// "jsdoc/check-tag-names": ["error"|"warn", {"jsxTags":true}]
4645````
4646
4647
4648<a name="eslint-plugin-jsdoc-rules-check-types"></a>
4649### <code>check-types</code>
4650
4651Reports invalid types.
4652
4653By default, ensures that the casing of native types is the same as in this
4654list:
4655
4656```
4657undefined
4658null
4659boolean
4660number
4661bigint
4662string
4663symbol
4664object
4665Array
4666Function
4667Date
4668RegExp
4669```
4670
4671<a name="eslint-plugin-jsdoc-rules-check-types-options-7"></a>
4672#### Options
4673
4674`check-types` allows one option:
4675
4676- An option object:
4677 - with the key `noDefaults` to insist that only the supplied option type
4678 map is to be used, and that the default preferences (such as "string"
4679 over "String") will not be enforced. The option's default is `false`.
4680 - with the key `exemptTagContexts` which will avoid reporting when a
4681 bad type is found on a specified tag. Set to an array of objects with
4682 a key `tag` set to the tag to exempt, and a `types` key which can
4683 either be `true` to indicate that any types on that tag will be allowed,
4684 or to an array of strings which will only allow specific bad types.
4685 If an array of strings is given, these must match the type exactly,
4686 e.g., if you only allow `"object"`, it will not allow
4687 `"object<string, string>"`. Note that this is different from the
4688 behavior of `settings.jsdoc.preferredTypes`. This option is useful
4689 for normally restricting generic types like `object` with
4690 `preferredTypes`, but allowing `typedef` to indicate that its base
4691 type is `object`.
4692 - with the key `unifyParentAndChildTypeChecks` which will treat
4693 `settings.jsdoc.preferredTypes` keys such as `SomeType` as matching
4694 not only child types such as an unadorned `SomeType` but also
4695 `SomeType<aChildType>`, `SomeType.<aChildType>`, or if `SomeType` is
4696 `Array` (or `[]`), it will match `aChildType[]`. If this is `false` or
4697 unset, the former format will only apply to types which are not parent
4698 types/unions whereas the latter formats will only apply for parent
4699 types/unions. The special types `[]`, `.<>` (or `.`), and `<>`
4700 act only as parent types (and will not match a bare child type such as
4701 `Array` even when unified, though, as mentioned, `Array` will match
4702 say `string[]` or `Array.<string>` when unified). The special type
4703 `*` is only a child type. Note that there is no detection of parent
4704 and child type together, e.g., you cannot specify preferences for
4705 `string[]` specifically as distinct from say `number[]`, but you can
4706 target both with `[]` or the child types `number` or `string`.
4707
4708If a value is present both as a key and as a value, neither the key nor the
4709value will be reported. Thus one can use this fact to allow both `object`
4710and `Object`, for example. Note that in "typescript" mode, this is the default
4711behavior.
4712
4713See also the documentation on `settings.jsdoc.preferredTypes` which impacts
4714the behavior of `check-types`.
4715
4716Note that if there is an error [parsing](https://github.com/jsdoctypeparser/jsdoctypeparser)
4717types for a tag, the function will silently ignore that tag, leaving it to
4718the `valid-types` rule to report parsing errors.
4719
4720<a name="eslint-plugin-jsdoc-rules-check-types-why-not-capital-case-everything"></a>
4721#### Why not capital case everything?
4722
4723Why are `boolean`, `number` and `string` exempt from starting with a capital
4724letter? Let's take `string` as an example. In Javascript, everything is an
4725object. The string Object has prototypes for string functions such as
4726`.toUpperCase()`.
4727
4728Fortunately we don't have to write `new String()` everywhere in our code.
4729Javascript will automatically wrap string primitives into string Objects when
4730we're applying a string function to a string primitive. This way the memory
4731footprint is a tiny little bit smaller, and the
4732[GC](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)) has
4733less work to do.
4734
4735So in a sense, there two types of strings in Javascript; `{string}` literals,
4736also called primitives and `{String}` Objects. We use the primitives because
4737it's easier to write and uses less memory. `{String}` and `{string}` are
4738technically both valid, but they are not the same.
4739
4740```js
4741new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
4742'lard' // "lard"
4743new String('lard') === 'lard' // false
4744```
4745
4746To make things more confusing, there are also object literals and object
4747Objects. But object literals are still static Objects and object Objects are
4748instantiated Objects. So an object primitive is still an object Object.
4749
4750However, `Object.create(null)` objects are not `instanceof Object`, however, so
4751in the case of this Object we lower-case to indicate possible support for
4752these objects.
4753
4754Basically, for primitives, we want to define the type as a primitive, because
4755that's what we use in 99.9% of cases. For everything else, we use the type
4756rather than the primitive. Otherwise it would all just be `{object}`.
4757
4758In short: It's not about consistency, rather about the 99.9% use case. (And
4759some functions might not even support the objects if they are checking for
4760identity.)
4761
4762type name | `typeof` | check-types | testcase
4763--|--|--|--
4764**Array** | object | **Array** | `([]) instanceof Array` -> `true`
4765**Function** | function | **Function** | `(function f () {}) instanceof Function` -> `true`
4766**Date** | object | **Date** | `(new Date()) instanceof Date` -> `true`
4767**RegExp** | object | **RegExp** | `(new RegExp(/.+/)) instanceof RegExp` -> `true`
4768Object | **object** | **object** | `({}) instanceof Object` -> `true` but `Object.create(null) instanceof Object` -> `false`
4769Boolean | **boolean** | **boolean** | `(true) instanceof Boolean` -> **`false`**
4770Number | **number** | **number** | `(41) instanceof Number` -> **`false`**
4771String | **string** | **string** | `("test") instanceof String` -> **`false`**
4772
4773If you define your own tags and don't wish their bracketed portions checked
4774for types, you can use `settings.jsdoc.structuredTags` with a tag `type` of
4775`false`. If you set their `type` to an array, only those values will be
4776permitted.
4777
4778|||
4779|---|---|
4780|Context|everywhere|
4781|Tags|`augments`, `class`, `constant`, `enum`, `implements`, `member`, `module`, `namespace`, `param`, `property`, `returns`, `throws`, `type`, `typedef`, `yields`|
4782|Aliases|`constructor`, `const`, `extends`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
4783|Closure-only|`package`, `private`, `protected`, `public`, `static`|
4784|Recommended|true|
4785|Options|`noDefaults`, `exemptTagContexts`, `unifyParentAndChildTypeChecks`|
4786|Settings|`preferredTypes`, `mode`, `structuredTags`|
4787
4788The following patterns are considered problems:
4789
4790````js
4791/**
4792 * @param {abc} foo
4793 */
4794function quux (foo) {
4795
4796}
4797// Settings: {"jsdoc":{"preferredTypes":{"abc":100}}}
4798// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
4799
4800/**
4801 * @param {Number} foo
4802 */
4803function quux (foo) {
4804
4805}
4806// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
4807
4808/**
4809 * @arg {Number} foo
4810 */
4811function quux (foo) {
4812
4813}
4814// Message: Invalid JSDoc @arg "foo" type "Number"; prefer: "number".
4815
4816/**
4817 * @returns {Number} foo
4818 * @throws {Number} foo
4819 */
4820function quux () {
4821
4822}
4823// Message: Invalid JSDoc @returns type "Number"; prefer: "number".
4824
4825/**
4826 * @param {(Number | string | Boolean)=} foo
4827 */
4828function quux (foo, bar, baz) {
4829
4830}
4831// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
4832
4833/**
4834 * @param {Array.<Number | String>} foo
4835 */
4836function quux (foo, bar, baz) {
4837
4838}
4839// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
4840
4841/**
4842 * @param {(Number | String)[]} foo
4843 */
4844function quux (foo, bar, baz) {
4845
4846}
4847// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
4848
4849/**
4850 * @param {abc} foo
4851 */
4852function qux(foo) {
4853}
4854// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
4855// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
4856
4857/**
4858 * @param {abc} foo
4859 */
4860function qux(foo) {
4861}
4862// Settings: {"jsdoc":{"preferredTypes":{"abc":{"replacement":"Abc"},"string":"Str"}}}
4863// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
4864
4865/**
4866 * @param {abc} foo
4867 */
4868function qux(foo) {
4869}
4870// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"; prefer: \"Abc\".","replacement":"Abc"},"string":"Str"}}}
4871// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
4872
4873/**
4874 * @param {abc} foo
4875 * @param {cde} bar
4876 * @param {object} baz
4877 */
4878function qux(foo, bar, baz) {
4879}
4880// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"; prefer: \"Abc\".","replacement":"Abc"},"cde":{"message":"More messed up JSDoc @{{tagName}}{{tagValue}} type \"cde\"; prefer: \"Cde\".","replacement":"Cde"},"object":"Object"}}}
4881// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
4882
4883/**
4884 * @param {abc} foo
4885 */
4886function qux(foo) {
4887}
4888// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\".","replacement":false},"string":"Str"}}}
4889// Message: Messed up JSDoc @param "foo" type "abc".
4890
4891/**
4892 * @param {abc} foo
4893 */
4894function qux(foo) {
4895}
4896// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"."},"string":"Str"}}}
4897// Message: Messed up JSDoc @param "foo" type "abc".
4898
4899/**
4900 * @param {abc} foo
4901 * @param {Number} bar
4902 */
4903function qux(foo, bar) {
4904}
4905// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
4906// "jsdoc/check-types": ["error"|"warn", {"noDefaults":true}]
4907// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
4908
4909/**
4910 * @param {abc} foo
4911 * @param {Number} bar
4912 */
4913function qux(foo, bar) {
4914}
4915// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
4916// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
4917
4918/**
4919 * @param {abc} foo
4920 */
4921function qux(foo) {
4922}
4923// Settings: {"jsdoc":{"preferredTypes":{"abc":false,"string":"Str"}}}
4924// Message: Invalid JSDoc @param "foo" type "abc".
4925
4926/**
4927 * @param {abc} foo
4928 */
4929function qux(foo) {
4930}
4931// Settings: {"jsdoc":{"preferredTypes":{"abc":false}}}
4932// Message: Invalid JSDoc @param "foo" type "abc".
4933
4934/**
4935 * @param {*} baz
4936 */
4937function qux(baz) {
4938}
4939// Settings: {"jsdoc":{"preferredTypes":{"*":false,"abc":"Abc","string":"Str"}}}
4940// Message: Invalid JSDoc @param "baz" type "*".
4941
4942/**
4943 * @param {*} baz
4944 */
4945function qux(baz) {
4946}
4947// Settings: {"jsdoc":{"preferredTypes":{"*":"aaa","abc":"Abc","string":"Str"}}}
4948// Message: Invalid JSDoc @param "baz" type "*"; prefer: "aaa".
4949
4950/**
4951 * @param {abc} foo
4952 * @param {Number} bar
4953 */
4954function qux(foo, bar) {
4955}
4956// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
4957// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
4958
4959/**
4960 * @param {Array} foo
4961 */
4962function quux (foo) {
4963
4964}
4965// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
4966// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
4967
4968/**
4969 * @param {Array} foo
4970 */
4971function quux (foo) {
4972
4973}
4974// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray","Array.<>":"GenericArray"}}}
4975// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
4976
4977/**
4978 * @param {Array.<string>} foo
4979 */
4980function quux (foo) {
4981
4982}
4983// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"GenericArray"}}}
4984// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
4985
4986/**
4987 * @param {Array<string>} foo
4988 */
4989function quux (foo) {
4990
4991}
4992// Settings: {"jsdoc":{"preferredTypes":{"Array<>":"GenericArray"}}}
4993// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
4994
4995/**
4996 * @param {string[]} foo
4997 */
4998function quux (foo) {
4999
5000}
5001// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
5002// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "SpecialTypeArray".
5003
5004/**
5005 * @param {string[]} foo
5006 */
5007function quux (foo) {
5008
5009}
5010// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
5011// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5012// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "SpecialTypeArray".
5013
5014/**
5015 * @param {string[]} foo
5016 */
5017function quux (foo) {
5018
5019}
5020// Settings: {"jsdoc":{"preferredTypes":{"Array":"SpecialTypeArray"}}}
5021// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5022// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "SpecialTypeArray".
5023
5024/**
5025 * @param {object} foo
5026 */
5027function quux (foo) {
5028
5029}
5030// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5031// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5032
5033/**
5034 * @param {object} foo
5035 */
5036function quux (foo) {
5037
5038}
5039// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject","object.<>":"GenericObject"}}}
5040// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5041
5042/**
5043 * @param {object} foo
5044 */
5045function quux (foo) {
5046
5047}
5048// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject","object<>":"GenericObject"}}}
5049// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5050
5051/**
5052 * @param {object.<string>} foo
5053 */
5054function quux (foo) {
5055
5056}
5057// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
5058// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5059
5060/**
5061 * @param {object<string>} foo
5062 */
5063function quux (foo) {
5064
5065}
5066// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
5067// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5068
5069/**
5070 * @param {object.<string, number>} foo
5071 */
5072function quux (foo) {
5073
5074}
5075// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
5076// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5077
5078/**
5079 * @param {object<string, number>} foo
5080 */
5081function quux (foo) {
5082
5083}
5084// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
5085// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5086
5087/**
5088 * @param {object.<string>} foo
5089 */
5090function quux (foo) {
5091
5092}
5093// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5094// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5095// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5096
5097/**
5098 * @param {object<string>} foo
5099 */
5100function quux (foo) {
5101
5102}
5103// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5104// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5105// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5106
5107/**
5108 * @param {object} foo
5109 */
5110function quux (foo) {
5111
5112}
5113// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5114// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5115// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5116
5117/**
5118 * @param {object} foo
5119 */
5120function quux (foo) {
5121
5122}
5123// Settings: {"jsdoc":{"preferredTypes":{"object":false}}}
5124// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5125// Message: Invalid JSDoc @param "foo" type "object".
5126
5127/**
5128 * @param {object} foo
5129 */
5130function quux (foo) {
5131
5132}
5133// Settings: {"jsdoc":{"preferredTypes":{"object":false}}}
5134// Message: Invalid JSDoc @param "foo" type "object".
5135
5136/**
5137 * @param {object.<string, number>} foo
5138 */
5139function quux (foo) {
5140
5141}
5142// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5143// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5144// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5145
5146/**
5147 * @param {object<string, number>} foo
5148 */
5149function quux (foo) {
5150
5151}
5152// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5153// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5154// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
5155
5156/**
5157 *
5158 * @param {string[][]} foo
5159 */
5160function quux (foo) {
5161
5162}
5163// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array."}}}
5164// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array.".
5165
5166/**
5167 *
5168 * @param {string[][]} foo
5169 */
5170function quux (foo) {
5171
5172}
5173// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array.<>"}}}
5174// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array.<>".
5175
5176/**
5177 *
5178 * @param {string[][]} foo
5179 */
5180function quux (foo) {
5181
5182}
5183// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array<>"}}}
5184// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array<>".
5185
5186/**
5187 *
5188 * @param {object.<string, object.<string, string>>} foo
5189 */
5190function quux (foo) {
5191
5192}
5193// Settings: {"jsdoc":{"preferredTypes":{"object.":"Object"}}}
5194// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object".
5195
5196/**
5197 *
5198 * @param {object.<string, object.<string, string>>} foo
5199 */
5200function quux (foo) {
5201
5202}
5203// Settings: {"jsdoc":{"preferredTypes":{"object.":"Object<>"}}}
5204// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object<>".
5205
5206/**
5207 *
5208 * @param {object<string, object<string, string>>} foo
5209 */
5210function quux (foo) {
5211
5212}
5213// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object."}}}
5214// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object.".
5215
5216/**
5217 *
5218 * @param {Array.<Array.<string>>} foo
5219 */
5220function quux (foo) {
5221
5222}
5223// Settings: {"jsdoc":{"preferredTypes":{"Array.":"[]"}}}
5224// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
5225
5226/**
5227 *
5228 * @param {Array.<Array.<string>>} foo
5229 */
5230function quux (foo) {
5231
5232}
5233// Settings: {"jsdoc":{"preferredTypes":{"Array.":"Array<>"}}}
5234// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array<>".
5235
5236/**
5237 *
5238 * @param {Array.<Array.<string>>} foo
5239 */
5240function quux (foo) {
5241
5242}
5243// Settings: {"jsdoc":{"preferredTypes":{"Array.":"<>"}}}
5244// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "<>".
5245
5246/**
5247 *
5248 * @param {Array.<MyArray.<string>>} foo
5249 */
5250function quux (foo) {
5251
5252}
5253// Settings: {"jsdoc":{"preferredTypes":{"Array.":"<>"}}}
5254// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "<>".
5255
5256/**
5257 *
5258 * @param {Array.<MyArray.<string>>} foo
5259 */
5260function quux (foo) {
5261
5262}
5263// Settings: {"jsdoc":{"preferredTypes":{"MyArray.":"<>"}}}
5264// Message: Invalid JSDoc @param "foo" type "MyArray"; prefer: "<>".
5265
5266/**
5267 *
5268 * @param {Array<Array<string>>} foo
5269 */
5270function quux (foo) {
5271
5272}
5273// Settings: {"jsdoc":{"preferredTypes":{"<>":"Array."}}}
5274// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array.".
5275
5276/**
5277 *
5278 * @param {Array<Array<string>>} foo
5279 */
5280function quux (foo) {
5281
5282}
5283// Settings: {"jsdoc":{"preferredTypes":{"Array":"Array."}}}
5284// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5285// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array.".
5286
5287/**
5288 *
5289 * @param {Array<Array<string>>} foo
5290 */
5291function quux (foo) {
5292
5293}
5294// Settings: {"jsdoc":{"preferredTypes":{"<>":"[]"}}}
5295// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
5296
5297/** @typedef {String} foo */
5298// Message: Invalid JSDoc @typedef "foo" type "String"; prefer: "string".
5299
5300/**
5301 * @this {array}
5302 */
5303function quux () {}
5304// Settings: {"jsdoc":{"mode":"closure"}}
5305// Message: Invalid JSDoc @this type "array"; prefer: "Array".
5306
5307/**
5308 * @export {array}
5309 */
5310function quux () {}
5311// Settings: {"jsdoc":{"mode":"closure"}}
5312// Message: Invalid JSDoc @export type "array"; prefer: "Array".
5313
5314/**
5315 * @typedef {object} foo
5316 * @property {object} bar
5317 */
5318// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
5319// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":true}]}]
5320// Message: Invalid JSDoc @property "bar" type "object"; prefer: "Object".
5321
5322/** @typedef {object} foo */
5323// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
5324// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["array"]}]}]
5325// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object".
5326
5327/**
5328 * @typedef {object} foo
5329 * @property {object} bar
5330 */
5331// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
5332// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["object"]}]}]
5333// Message: Invalid JSDoc @property "bar" type "object"; prefer: "Object".
5334
5335/** @typedef {object<string, string>} foo */
5336// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object<>"}}}
5337// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["object"]}]}]
5338// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object<>".
5339
5340/**
5341 * @param {Array<number | undefined>} foo
5342 */
5343function quux (foo) {
5344
5345}
5346// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"[]","Array<>":"[]"}}}
5347// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
5348
5349/**
5350 * @typedef {object} foo
5351 */
5352function a () {}
5353
5354/**
5355 * @typedef {Object} foo
5356 */
5357function b () {}
5358// Settings: {"jsdoc":{"mode":"typescript","preferredTypes":{"object":"Object"}}}
5359// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object".
5360
5361/**
5362 * @aCustomTag {Number} foo
5363 */
5364// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":true}}}}
5365// Message: Invalid JSDoc @aCustomTag "foo" type "Number"; prefer: "number".
5366
5367/**
5368 * @aCustomTag {Number} foo
5369 */
5370// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
5371// Message: Invalid JSDoc @aCustomTag "foo" type "Number"; prefer: ["otherType","anotherType"].
5372````
5373
5374The following patterns are not considered problems:
5375
5376````js
5377/**
5378 * @param {number} foo
5379 * @param {Bar} bar
5380 * @param {*} baz
5381 */
5382function quux (foo, bar, baz) {
5383
5384}
5385
5386/**
5387 * @arg {number} foo
5388 * @arg {Bar} bar
5389 * @arg {*} baz
5390 */
5391function quux (foo, bar, baz) {
5392
5393}
5394
5395/**
5396 * @param {(number | string | boolean)=} foo
5397 */
5398function quux (foo, bar, baz) {
5399
5400}
5401
5402/**
5403 * @param {typeof bar} foo
5404 */
5405function qux(foo) {
5406}
5407
5408/**
5409 * @param {import('./foo').bar.baz} foo
5410 */
5411function qux(foo) {
5412}
5413
5414/**
5415 * @param {(x: number, y: string) => string} foo
5416 */
5417function qux(foo) {
5418}
5419
5420/**
5421 * @param {() => string} foo
5422 */
5423function qux(foo) {
5424}
5425
5426/**
5427 * @returns {Number} foo
5428 * @throws {Number} foo
5429 */
5430function quux () {
5431
5432}
5433// "jsdoc/check-types": ["error"|"warn", {"noDefaults":true}]
5434
5435/**
5436 * @param {Object} foo
5437 */
5438function quux (foo) {
5439
5440}
5441// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
5442
5443/**
5444 * @param {Array} foo
5445 */
5446function quux (foo) {
5447
5448}
5449
5450/**
5451 * @param {Array.<string>} foo
5452 */
5453function quux (foo) {
5454
5455}
5456// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
5457
5458/**
5459 * @param {Array<string>} foo
5460 */
5461function quux (foo) {
5462
5463}
5464// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
5465
5466/**
5467 * @param {string[]} foo
5468 */
5469function quux (foo) {
5470
5471}
5472// Settings: {"jsdoc":{"preferredTypes":{"Array":"SpecialTypeArray","Array.<>":"SpecialTypeArray","Array<>":"SpecialTypeArray"}}}
5473
5474/**
5475 * @param {string[]} foo
5476 */
5477function quux (foo) {
5478
5479}
5480// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"SpecialTypeArray","Array<>":"SpecialTypeArray"}}}
5481// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5482
5483/**
5484 * @param {Array} foo
5485 */
5486function quux (foo) {
5487
5488}
5489// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
5490
5491/**
5492 * @param {Array} foo
5493 */
5494function quux (foo) {
5495
5496}
5497// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
5498// "jsdoc/check-types": ["error"|"warn", {"unifyParentAndChildTypeChecks":true}]
5499
5500/**
5501 * @param {Array} foo
5502 */
5503function quux (foo) {
5504
5505}
5506// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"GenericArray"}}}
5507
5508/**
5509 * @param {Array} foo
5510 */
5511function quux (foo) {
5512
5513}
5514// Settings: {"jsdoc":{"preferredTypes":{"Array<>":"GenericArray"}}}
5515
5516/**
5517 * @param {object} foo
5518 */
5519function quux (foo) {
5520
5521}
5522
5523/**
5524 * @param {object.<string>} foo
5525 */
5526function quux (foo) {
5527
5528}
5529// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5530
5531/**
5532 * @param {object<string>} foo
5533 */
5534function quux (foo) {
5535
5536}
5537// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5538
5539/**
5540 * @param {object.<string, number>} foo
5541 */
5542function quux (foo) {
5543
5544}
5545// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5546
5547/**
5548 * @param {object<string, number>} foo
5549 */
5550function quux (foo) {
5551
5552}
5553// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
5554
5555/**
5556 * @param {object} foo
5557 */
5558function quux (foo) {
5559
5560}
5561// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
5562
5563/**
5564 * @param {object} foo
5565 */
5566function quux (foo) {
5567
5568}
5569// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
5570
5571/**
5572 * @param {Number<} Ignore the error as not a validating rule
5573 */
5574function quux (foo) {
5575
5576}
5577
5578/** @param {function(...)} callback The function to invoke. */
5579var subscribe = function(callback) {};
5580
5581/**
5582 * @this {Array}
5583 */
5584function quux () {}
5585// Settings: {"jsdoc":{"mode":"closure"}}
5586
5587/**
5588 * @export {Array}
5589 */
5590function quux () {}
5591// Settings: {"jsdoc":{"mode":"closure"}}
5592
5593/** @type {new() => EntityBase} */
5594
5595/** @typedef {object} foo */
5596// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
5597// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":true}]}]
5598
5599/** @typedef {object<string, string>} foo */
5600// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
5601
5602/** @typedef {object<string, string>} foo */
5603// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object<>"}}}
5604// "jsdoc/check-types": ["error"|"warn", {"exemptTagContexts":[{"tag":"typedef","types":["object<string, string>"]}]}]
5605
5606/**
5607 * @typedef {object} foo
5608 */
5609
5610 /**
5611 * @typedef {Object} foo
5612 */
5613// Settings: {"jsdoc":{"preferredTypes":{"object":"Object","Object":"object"}}}
5614
5615/**
5616 * @typedef {object} foo
5617 */
5618function a () {}
5619
5620/**
5621 * @typedef {Object} foo
5622 */
5623function b () {}
5624// Settings: {"jsdoc":{"preferredTypes":{"object":"Object","Object":"object"}}}
5625
5626/**
5627 * @typedef {object} foo
5628 */
5629function a () {}
5630
5631/**
5632 * @typedef {Object} foo
5633 */
5634function b () {}
5635// Settings: {"jsdoc":{"mode":"typescript"}}
5636
5637/**
5638 * @aCustomTag {Number} foo
5639 */
5640// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":false}}}}
5641
5642/**
5643 * @aCustomTag {otherType} foo
5644 */
5645// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
5646
5647/**
5648 * @aCustomTag {anotherType|otherType} foo
5649 */
5650// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["otherType","anotherType"]}}}}
5651
5652/**
5653 * Bad types handled by `valid-types` instead.
5654 * @param {str(} foo
5655 */
5656function quux (foo) {
5657
5658}
5659````
5660
5661
5662<a name="eslint-plugin-jsdoc-rules-check-values"></a>
5663### <code>check-values</code>
5664
5665This rule checks the values for a handful of tags:
5666
56671. `@version` - Checks that there is a present and valid
5668 [semver](https://semver.org/) version value.
56692. `@since` - As with `@version`
56703. `@license` - Checks that there is a present and valid SPDX identifier
5671 or is present within an `allowedLicenses` option.
56724. `@author` - Checks that there is a value present, and if the option
5673 `allowedAuthors` is present, ensure that the author value is one
5674 of these array items.
56755. `@variation` - If `numericOnlyVariation` is set, will checks that there
5676 is a value present, and that it is an integer (otherwise, jsdoc allows any
5677 value).
5678
5679<a name="eslint-plugin-jsdoc-rules-check-values-options-8"></a>
5680#### Options
5681
5682<a name="eslint-plugin-jsdoc-rules-check-values-options-8-allowedauthors"></a>
5683##### <code>allowedAuthors</code>
5684
5685An array of allowable author values. If absent, only non-whitespace will
5686be checked for.
5687
5688<a name="eslint-plugin-jsdoc-rules-check-values-options-8-allowedlicenses"></a>
5689##### <code>allowedLicenses</code>
5690
5691An array of allowable license values or `true` to allow any license text.
5692If present as an array, will be used in place of SPDX identifiers.
5693
5694<a name="eslint-plugin-jsdoc-rules-check-values-options-8-licensepattern"></a>
5695##### <code>licensePattern</code>
5696
5697A string to be converted into a `RegExp` (with `u` flag) and whose first
5698parenthetical grouping, if present, will match the portion of the license
5699description to check (if no grouping is present, then the whole portion
5700matched will be used). Defaults to `/([^\n]*)/gu`, i.e., the SPDX expression
5701is expected before any line breaks.
5702
5703Note that the `/` delimiters are optional, but necessary to add flags.
5704
5705Defaults to using the `u` flag, so to add your own flags, encapsulate
5706your expression as a string, but like a literal, e.g., `/^mit$/ui`.
5707
5708<a name="eslint-plugin-jsdoc-rules-check-values-options-8-numericonlyvariation"></a>
5709##### <code>numericOnlyVariation</code>
5710
5711Whether to enable validation that `@variation` must be a number. Defaults to
5712`false`.
5713
5714|||
5715|---|---|
5716|Context|everywhere|
5717|Tags|`@version`, `@since`, `@license`, `@author`, `@variation`|
5718|Recommended|true|
5719|Options|`allowedAuthors`, `allowedLicenses`, `licensePattern`|
5720|Settings|`tagNamePreference`|
5721
5722The following patterns are considered problems:
5723
5724````js
5725/**
5726 * @version
5727 */
5728function quux (foo) {
5729
5730}
5731// Message: Missing JSDoc @version value.
5732
5733/**
5734 * @version 3.1
5735 */
5736function quux (foo) {
5737
5738}
5739// Message: Invalid JSDoc @version: "3.1".
5740
5741/**
5742 * @variation -3
5743 */
5744function quux (foo) {
5745
5746}
5747// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
5748// Message: Invalid JSDoc @variation: "-3".
5749
5750/**
5751 * @since
5752 */
5753function quux (foo) {
5754
5755}
5756// Message: Missing JSDoc @since value.
5757
5758/**
5759 * @since 3.1
5760 */
5761function quux (foo) {
5762
5763}
5764// Message: Invalid JSDoc @since: "3.1".
5765
5766/**
5767 * @license
5768 */
5769function quux (foo) {
5770
5771}
5772// Message: Missing JSDoc @license value.
5773
5774/**
5775 * @license FOO
5776 */
5777function quux (foo) {
5778
5779}
5780// Message: Invalid JSDoc @license: "FOO"; expected SPDX expression: https://spdx.org/licenses/.
5781
5782/**
5783 * @license FOO
5784 */
5785function quux (foo) {
5786
5787}
5788// "jsdoc/check-values": ["error"|"warn", {"allowedLicenses":["BAR","BAX"]}]
5789// Message: Invalid JSDoc @license: "FOO"; expected one of BAR, BAX.
5790
5791/**
5792 * @license MIT-7
5793 * Some extra text...
5794 */
5795function quux (foo) {
5796
5797}
5798// Message: Invalid JSDoc @license: "MIT-7"; expected SPDX expression: https://spdx.org/licenses/.
5799
5800/**
5801 * @license (MIT OR GPL-2.5)
5802 */
5803function quux (foo) {
5804
5805}
5806// Message: Invalid JSDoc @license: "(MIT OR GPL-2.5)"; expected SPDX expression: https://spdx.org/licenses/.
5807
5808/**
5809 * @license MIT
5810 * Some extra text
5811 */
5812function quux (foo) {
5813
5814}
5815// "jsdoc/check-values": ["error"|"warn", {"licensePattern":"[\\s\\S]*"}]
5816// Message: Invalid JSDoc @license: "MIT
5817Some extra text"; expected SPDX expression: https://spdx.org/licenses/.
5818
5819/**
5820 * @author
5821 */
5822function quux (foo) {
5823
5824}
5825// Message: Missing JSDoc @author value.
5826
5827/**
5828 * @author Brett Zamir
5829 */
5830function quux (foo) {
5831
5832}
5833// "jsdoc/check-values": ["error"|"warn", {"allowedAuthors":["Gajus Kuizinas","golopot"]}]
5834// Message: Invalid JSDoc @author: "Brett Zamir"; expected one of Gajus Kuizinas, golopot.
5835
5836/**
5837 * @variation
5838 */
5839function quux (foo) {
5840
5841}
5842// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
5843// Message: Missing JSDoc @variation value.
5844
5845/**
5846 * @variation 5.2
5847 */
5848function quux (foo) {
5849
5850}
5851// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
5852// Message: Invalid JSDoc @variation: "5.2".
5853````
5854
5855The following patterns are not considered problems:
5856
5857````js
5858/**
5859 * @version 3.4.1
5860 */
5861function quux (foo) {
5862
5863}
5864
5865/**
5866 * @version 3.4.1
5867 */
5868function quux (foo) {
5869
5870}
5871
5872/**
5873 * @since 3.4.1
5874 */
5875function quux (foo) {
5876
5877}
5878
5879/**
5880 * @since 3.4.1
5881 */
5882function quux (foo) {
5883
5884}
5885
5886/**
5887 * @license MIT
5888 */
5889function quux (foo) {
5890
5891}
5892
5893/**
5894 * @license MIT
5895 * Some extra text...
5896 */
5897function quux (foo) {
5898
5899}
5900
5901/**
5902 * @license (MIT OR GPL-2.0)
5903 */
5904function quux (foo) {
5905
5906}
5907
5908/**
5909 * @license FOO
5910 */
5911function quux (foo) {
5912
5913}
5914// "jsdoc/check-values": ["error"|"warn", {"allowedLicenses":["FOO","BAR","BAX"]}]
5915
5916/**
5917 * @license FOO
5918 */
5919function quux (foo) {
5920
5921}
5922// "jsdoc/check-values": ["error"|"warn", {"allowedLicenses":true}]
5923
5924/**
5925 * @license MIT
5926 * Some extra text
5927 */
5928function quux (foo) {
5929
5930}
5931// "jsdoc/check-values": ["error"|"warn", {"licensePattern":"[^\n]*"}]
5932
5933/**
5934 * @author Gajus Kuizinas
5935 */
5936function quux (foo) {
5937
5938}
5939
5940/**
5941 * @author Brett Zamir
5942 */
5943function quux (foo) {
5944
5945}
5946// "jsdoc/check-values": ["error"|"warn", {"allowedAuthors":["Gajus Kuizinas","golopot","Brett Zamir"]}]
5947
5948/**
5949 * @variation 3
5950 */
5951function quux (foo) {
5952
5953}
5954// "jsdoc/check-values": ["error"|"warn", {"numericOnlyVariation":true}]
5955
5956/**
5957 * @variation abc
5958 */
5959function quux (foo) {
5960
5961}
5962````
5963
5964
5965<a name="eslint-plugin-jsdoc-rules-empty-tags"></a>
5966### <code>empty-tags</code>
5967
5968Expects the following tags to be empty of any content:
5969
5970- `@abstract`
5971- `@async`
5972- `@generator`
5973- `@global`
5974- `@hideconstructor`
5975- `@ignore`
5976- `@inheritdoc`
5977- `@inner`
5978- `@instance`
5979- `@internal` (used by TypeScript)
5980- `@override`
5981- `@readonly`
5982
5983The following will also be expected to be empty unless `settings.jsdoc.mode`
5984is set to "closure" (which allows types).
5985
5986- `@package`
5987- `@private`
5988- `@protected`
5989- `@public`
5990- `@static`
5991
5992Note that `@private` will still be checked for content by this rule even with
5993`settings.jsdoc.ignorePrivate` set to `true` (a setting which normally
5994causes rules not to take effect).
5995
5996Similarly, `@internal` will still be checked for content by this rule even with
5997`settings.jsdoc.ignoreInternal` set to `true`.
5998
5999<a name="eslint-plugin-jsdoc-rules-empty-tags-options-9"></a>
6000#### Options
6001
6002<a name="eslint-plugin-jsdoc-rules-empty-tags-options-9-tags-1"></a>
6003##### <code>tags</code>
6004
6005If you want additional tags to be checked for their descriptions, you may
6006add them within this option.
6007
6008```js
6009{
6010 'jsdoc/empty-tags': ['error', {tags: ['event']}]
6011}
6012```
6013
6014|||
6015|---|---|
6016|Context|everywhere|
6017|Tags| `abstract`, `async`, `generator`, `global`, `hideconstructor`, `ignore`, `inheritdoc`, `inner`, `instance`, `internal`, `override`, `readonly`, `package`, `private`, `protected`, `public`, `static` and others added by `tags`|
6018|Recommended|true|
6019|Options|`tags`|
6020The following patterns are considered problems:
6021
6022````js
6023/**
6024 * @abstract extra text
6025 */
6026function quux () {
6027
6028}
6029// Message: @abstract should be empty.
6030
6031class Test {
6032 /**
6033 * @abstract extra text
6034 */
6035 quux () {
6036
6037 }
6038}
6039// Message: @abstract should be empty.
6040
6041/**
6042 * @abstract extra text
6043 * @inheritdoc
6044 * @async out of place
6045 */
6046function quux () {
6047
6048}
6049// Message: @abstract should be empty.
6050
6051/**
6052 * @event anEvent
6053 */
6054function quux () {
6055
6056}
6057// "jsdoc/empty-tags": ["error"|"warn", {"tags":["event"]}]
6058// Message: @event should be empty.
6059
6060/**
6061 * @private {someType}
6062 */
6063function quux () {
6064
6065}
6066// Message: @private should be empty.
6067
6068/**
6069 * @internal {someType}
6070 */
6071function quux () {
6072
6073}
6074// Message: @internal should be empty.
6075
6076/**
6077 * @private {someType}
6078 */
6079function quux () {
6080
6081}
6082// Settings: {"jsdoc":{"ignorePrivate":true}}
6083// Message: @private should be empty.
6084````
6085
6086The following patterns are not considered problems:
6087
6088````js
6089/**
6090 * @abstract
6091 */
6092function quux () {
6093
6094}
6095
6096/**
6097 *
6098 */
6099function quux () {
6100
6101}
6102
6103/**
6104 * @param aName
6105 */
6106function quux () {
6107
6108}
6109
6110/**
6111 * @abstract
6112 * @inheritdoc
6113 * @async
6114 */
6115function quux () {
6116
6117}
6118
6119/**
6120 * @private {someType}
6121 */
6122function quux () {
6123
6124}
6125// Settings: {"jsdoc":{"mode":"closure"}}
6126
6127/**
6128 * @private
6129 */
6130function quux () {
6131
6132}
6133
6134/**
6135 * @internal
6136 */
6137function quux () {
6138
6139}
6140
6141/**
6142 * Create an array.
6143 *
6144 * @private
6145 *
6146 * @param {string[]} [elem] - Elements to make an array of.
6147 * @param {boolean} [clone] - Optionally clone nodes.
6148 * @returns {string[]} The array of nodes.
6149 */
6150function quux () {}
6151````
6152
6153
6154<a name="eslint-plugin-jsdoc-rules-implements-on-classes"></a>
6155### <code>implements-on-classes</code>
6156
6157Reports an issue with any non-constructor function using `@implements`.
6158
6159Constructor functions, whether marked with `@class`, `@constructs`, or being
6160an ES6 class constructor, will not be flagged.
6161
6162To indicate that a function follows another function's signature, one might
6163instead use `@type` to indicate the `@function` or `@callback` to which the
6164function is adhering.
6165
6166<a name="eslint-plugin-jsdoc-rules-implements-on-classes-options-10"></a>
6167#### Options
6168
6169<a name="eslint-plugin-jsdoc-rules-implements-on-classes-options-10-contexts"></a>
6170##### <code>contexts</code>
6171
6172Set this to an array of strings representing the AST context (or an object with
6173`context` and `comment` properties) where you wish the rule to be applied.
6174
6175Overrides the default contexts (see below). Set to `"any"` if you want
6176the rule to apply to any jsdoc block throughout your files (as is necessary
6177for finding function blocks not attached to a function declaration or
6178expression, i.e., `@callback` or `@function` (or its aliases `@func` or
6179`@method`) (including those associated with an `@interface`).
6180
6181See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
6182section of our README for more on the expected format.
6183
6184|||
6185|---|---|
6186|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6187|Tags|`implements` (prevented)|
6188|Recommended|true|
6189|Options|`contexts`|
6190
6191The following patterns are considered problems:
6192
6193````js
6194/**
6195 * @implements {SomeClass}
6196 */
6197function quux () {
6198
6199}
6200// Message: @implements used on a non-constructor function
6201
6202/**
6203 * @implements {SomeClass}
6204 */
6205function quux () {
6206
6207}
6208// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
6209// Message: @implements used on a non-constructor function
6210
6211/**
6212 * @function
6213 * @implements {SomeClass}
6214 */
6215function quux () {
6216
6217}
6218// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
6219// Message: @implements used on a non-constructor function
6220
6221/**
6222 * @callback
6223 * @implements {SomeClass}
6224 */
6225// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
6226// Message: @implements used on a non-constructor function
6227
6228/**
6229 * @implements {SomeClass}
6230 */
6231function quux () {
6232
6233}
6234// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
6235// Message: Unexpected tag `@implements`
6236
6237class Foo {
6238 /**
6239 * @implements {SomeClass}
6240 */
6241 constructor() {}
6242
6243 /**
6244 * @implements {SomeClass}
6245 */
6246 bar() {}
6247}
6248// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["MethodDefinition"]}]
6249// Message: @implements used on a non-constructor function
6250
6251class Foo {
6252 /**
6253 * @implements {SomeClass}
6254 */
6255 constructor() {}
6256
6257 /**
6258 * @implements {SomeClass}
6259 */
6260 bar() {}
6261}
6262// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
6263// Message: @implements used on a non-constructor function
6264````
6265
6266The following patterns are not considered problems:
6267
6268````js
6269/**
6270 * @implements {SomeClass}
6271 * @class
6272 */
6273function quux () {
6274
6275}
6276
6277/**
6278 * @implements {SomeClass}
6279 * @class
6280 */
6281function quux () {
6282
6283}
6284// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
6285
6286/**
6287 * @implements {SomeClass}
6288 */
6289// "jsdoc/implements-on-classes": ["error"|"warn", {"contexts":["any"]}]
6290
6291/**
6292 * @implements {SomeClass}
6293 * @constructor
6294 */
6295function quux () {
6296
6297}
6298
6299/**
6300 *
6301 */
6302class quux {
6303 /**
6304 * @implements {SomeClass}
6305 */
6306 constructor () {
6307
6308 }
6309}
6310
6311/**
6312 *
6313 */
6314const quux = class {
6315 /**
6316 * @implements {SomeClass}
6317 */
6318 constructor () {
6319
6320 }
6321}
6322
6323/**
6324 *
6325 */
6326function quux () {
6327
6328}
6329
6330/**
6331 *
6332 */
6333function quux () {
6334
6335}
6336// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
6337
6338/**
6339 * @function
6340 * @implements {SomeClass}
6341 */
6342
6343/**
6344 * @callback
6345 * @implements {SomeClass}
6346 */
6347````
6348
6349
6350<a name="eslint-plugin-jsdoc-rules-match-description"></a>
6351### <code>match-description</code>
6352
6353Enforces a regular expression pattern on descriptions.
6354
6355The default is this basic expression to match English sentences (Support
6356for Unicode upper case may be added in a future version when it can be handled
6357by our supported Node versions):
6358
6359``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$``
6360
6361Applies to the jsdoc block description and `@description` (or `@desc`)
6362by default but the `tags` option (see below) may be used to match other tags.
6363
6364The default (and all regex options) defaults to using (only) the `u` flag, so
6365to add your own flags, encapsulate your expression as a string, but like a
6366literal, e.g., `/[A-Z].*\\./ui`.
6367
6368Note that `/` delimiters are optional, but necessary to add flags (besides
6369`u`).
6370
6371Also note that the default or optional regular expressions is *not*
6372case-insensitive unless one opts in to add the `i` flag.
6373
6374You can add the `s` flag if you want `.` to match newlines. Note, however,
6375that the trailing newlines of a description will not be matched.
6376
6377<a name="eslint-plugin-jsdoc-rules-match-description-options-11"></a>
6378#### Options
6379
6380<a name="eslint-plugin-jsdoc-rules-match-description-options-11-matchdescription"></a>
6381##### <code>matchDescription</code>
6382
6383You can supply your own expression to override the default, passing a
6384`matchDescription` string on the options object.
6385
6386```js
6387{
6388 'jsdoc/match-description': ['error', {matchDescription: '[A-Z].*\\.'}]
6389}
6390```
6391
6392<a name="eslint-plugin-jsdoc-rules-match-description-options-11-tags-2"></a>
6393##### <code>tags</code>
6394
6395If you want different regular expressions to apply to tags, you may use
6396the `tags` option object:
6397
6398```js
6399{
6400 'jsdoc/match-description': ['error', {tags: {
6401 param: '\\- [A-Z].*\\.',
6402 returns: '[A-Z].*\\.'
6403 }}]
6404}
6405```
6406
6407In place of a string, you can also add `true` to indicate that a particular
6408tag should be linted with the `matchDescription` value (or the default).
6409
6410```js
6411{
6412 'jsdoc/match-description': ['error', {tags: {
6413 param: true,
6414 returns: true
6415 }}]
6416}
6417```
6418
6419The tags `@param`/`@arg`/`@argument` and `@property`/`@prop` will be properly
6420parsed to ensure that the matched "description" text includes only the text
6421after the name.
6422
6423All other tags will treat the text following the tag name, a space, and
6424an optional curly-bracketed type expression (and another space) as part of
6425its "description" (e.g., for `@returns {someType} some description`, the
6426description is `some description` while for `@some-tag xyz`, the description
6427is `xyz`).
6428
6429<a name="eslint-plugin-jsdoc-rules-match-description-options-11-maindescription"></a>
6430##### <code>mainDescription</code>
6431
6432If you wish to override the main function description without changing the
6433default `match-description`, you may use `mainDescription`:
6434
6435```js
6436{
6437 'jsdoc/match-description': ['error', {
6438 mainDescription: '[A-Z].*\\.',
6439 tags: {
6440 param: true,
6441 returns: true
6442 }
6443 }]
6444}
6445```
6446
6447There is no need to add `mainDescription: true`, as by default, the main
6448function (and only the main function) is linted, though you may disable
6449checking it by setting it to `false`.
6450
6451<a name="eslint-plugin-jsdoc-rules-match-description-options-11-contexts-1"></a>
6452##### <code>contexts</code>
6453
6454Set this to an array of strings representing the AST context (or an object with
6455`context` and `comment` properties) where you wish the rule to be applied.
6456(e.g., `ClassDeclaration` for ES6
6457classes). Overrides the default contexts (see below). Set to `"any"` if you
6458want the rule to apply to any jsdoc block throughout your files.
6459
6460See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
6461section of our README for more on the expected format.
6462
6463|||
6464|---|---|
6465|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6466|Tags|docblock and `@description` by default but more with `tags`|
6467|Aliases|`@desc`|
6468|Recommended|false|
6469|Settings||
6470|Options|`contexts`, `tags` (accepts tags with names and optional type such as 'param', 'arg', 'argument', 'property', and 'prop', and accepts arbitrary list of other tags with an optional type (but without names), e.g., 'returns', 'return'), `mainDescription`, `matchDescription`|
6471
6472The following patterns are considered problems:
6473
6474````js
6475/**
6476 * foo.
6477 */
6478const q = class {
6479
6480}
6481// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassExpression"]}]
6482// Message: JSDoc description does not satisfy the regex pattern.
6483
6484/**
6485 * foo.
6486 */
6487// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"]}]
6488// Message: JSDoc description does not satisfy the regex pattern.
6489
6490/**
6491 * foo.
6492 */
6493// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"]}]
6494// Message: JSDoc description does not satisfy the regex pattern.
6495
6496/**
6497 * foo.
6498 */
6499const q = {
6500
6501};
6502// "jsdoc/match-description": ["error"|"warn", {"contexts":["ObjectExpression"]}]
6503// Message: JSDoc description does not satisfy the regex pattern.
6504
6505/**
6506 * foo.
6507 */
6508function quux () {
6509
6510}
6511// Message: JSDoc description does not satisfy the regex pattern.
6512
6513/**
6514 * Foo)
6515 */
6516function quux () {
6517
6518}
6519// Message: JSDoc description does not satisfy the regex pattern.
6520
6521/**
6522 * тест.
6523 */
6524function quux () {
6525
6526}
6527// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"[А-Я][А-я]+\\."}]
6528// Message: JSDoc description does not satisfy the regex pattern.
6529
6530/**
6531 * Abc.
6532 */
6533function quux () {
6534
6535}
6536// "jsdoc/match-description": ["error"|"warn", {"mainDescription":"[А-Я][А-я]+\\.","tags":{"param":true}}]
6537// Message: JSDoc description does not satisfy the regex pattern.
6538
6539/**
6540 * Foo
6541 */
6542function quux () {
6543
6544}
6545// Message: JSDoc description does not satisfy the regex pattern.
6546
6547/**
6548 * Foo.
6549 *
6550 * @param foo foo.
6551 */
6552function quux (foo) {
6553
6554}
6555// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
6556// Message: JSDoc description does not satisfy the regex pattern.
6557
6558/**
6559 * Foo.
6560 *
6561 * @template Abc, Def foo.
6562 */
6563function quux (foo) {
6564
6565}
6566// "jsdoc/match-description": ["error"|"warn", {"tags":{"template":true}}]
6567// Message: JSDoc description does not satisfy the regex pattern.
6568
6569/**
6570 * Foo.
6571 *
6572 * @prop foo foo.
6573 */
6574function quux (foo) {
6575
6576}
6577// "jsdoc/match-description": ["error"|"warn", {"tags":{"prop":true}}]
6578// Message: JSDoc description does not satisfy the regex pattern.
6579
6580/**
6581 * Foo.
6582 *
6583 * @summary foo.
6584 */
6585function quux () {
6586
6587}
6588// "jsdoc/match-description": ["error"|"warn", {"tags":{"summary":true}}]
6589// Message: JSDoc description does not satisfy the regex pattern.
6590
6591/**
6592 * Foo.
6593 *
6594 * @author
6595 */
6596function quux () {
6597
6598}
6599// "jsdoc/match-description": ["error"|"warn", {"tags":{"author":".+"}}]
6600// Message: JSDoc description does not satisfy the regex pattern.
6601
6602/**
6603 * Foo.
6604 *
6605 * @x-tag
6606 */
6607function quux () {
6608
6609}
6610// "jsdoc/match-description": ["error"|"warn", {"tags":{"x-tag":".+"}}]
6611// Message: JSDoc description does not satisfy the regex pattern.
6612
6613/**
6614 * Foo.
6615 *
6616 * @description foo foo.
6617 */
6618function quux (foo) {
6619
6620}
6621// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
6622// Message: JSDoc description does not satisfy the regex pattern.
6623
6624/**
6625 * Foo
6626 *
6627 * @param foo foo.
6628 */
6629function quux (foo) {
6630
6631}
6632// "jsdoc/match-description": ["error"|"warn", {"mainDescription":"^[a-zA-Z]*$","tags":{"param":true}}]
6633// Message: JSDoc description does not satisfy the regex pattern.
6634
6635/**
6636 * Foo
6637 *
6638 * @param foo foo.
6639 */
6640function quux (foo) {
6641
6642}
6643// "jsdoc/match-description": ["error"|"warn", {"mainDescription":false,"tags":{"param":true}}]
6644// Message: JSDoc description does not satisfy the regex pattern.
6645
6646/**
6647 * Foo.
6648 *
6649 * @param foo bar
6650 */
6651function quux (foo) {
6652
6653}
6654// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
6655// Message: JSDoc description does not satisfy the regex pattern.
6656
6657/**
6658 * {@see Foo.bar} buz
6659 */
6660function quux (foo) {
6661
6662}
6663// Message: JSDoc description does not satisfy the regex pattern.
6664
6665/**
6666 * Foo.
6667 *
6668 * @returns {number} foo
6669 */
6670function quux (foo) {
6671
6672}
6673// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
6674// Message: JSDoc description does not satisfy the regex pattern.
6675
6676/**
6677 * Foo.
6678 *
6679 * @returns foo.
6680 */
6681function quux (foo) {
6682
6683}
6684// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
6685// Message: JSDoc description does not satisfy the regex pattern.
6686
6687/**
6688 * lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
6689 * iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
6690 * tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
6691 * vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
6692 * proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
6693 * consequat auctor magna. duis pharetra purus in porttitor mollis.
6694 */
6695function longDescription (foo) {
6696
6697}
6698// Message: JSDoc description does not satisfy the regex pattern.
6699
6700/**
6701 * @arg {number} foo - Foo
6702 */
6703function quux (foo) {
6704
6705}
6706// "jsdoc/match-description": ["error"|"warn", {"tags":{"arg":true}}]
6707// Message: JSDoc description does not satisfy the regex pattern.
6708
6709/**
6710 * @argument {number} foo - Foo
6711 */
6712function quux (foo) {
6713
6714}
6715// "jsdoc/match-description": ["error"|"warn", {"tags":{"argument":true}}]
6716// Message: JSDoc description does not satisfy the regex pattern.
6717
6718/**
6719 * @return {number} foo
6720 */
6721function quux (foo) {
6722
6723}
6724// "jsdoc/match-description": ["error"|"warn", {"tags":{"return":true}}]
6725// Message: JSDoc description does not satisfy the regex pattern.
6726
6727/**
6728 * Returns bar.
6729 *
6730 * @return {number} bar
6731 */
6732function quux (foo) {
6733
6734}
6735// "jsdoc/match-description": ["error"|"warn", {"tags":{"return":true}}]
6736// Message: JSDoc description does not satisfy the regex pattern.
6737
6738/**
6739 * @param notRet
6740 * @returns Тест.
6741 */
6742function quux () {
6743
6744}
6745// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":"[А-Я][А-я]+\\."}}]
6746// Message: JSDoc description does not satisfy the regex pattern.
6747
6748/**
6749 * @description notRet
6750 * @returns Тест.
6751 */
6752function quux () {
6753
6754}
6755// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":"[А-Я][А-я]+\\."}}]
6756// Message: JSDoc description does not satisfy the regex pattern.
6757
6758/**
6759 * foo.
6760 */
6761class quux {
6762
6763}
6764// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
6765// Message: JSDoc description does not satisfy the regex pattern.
6766
6767class MyClass {
6768 /**
6769 * Abc
6770 */
6771 myClassField = 1
6772}
6773// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassProperty"]}]
6774// Message: JSDoc description does not satisfy the regex pattern.
6775
6776/**
6777 * foo.
6778 */
6779interface quux {
6780
6781}
6782// "jsdoc/match-description": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"]}]
6783// Message: JSDoc description does not satisfy the regex pattern.
6784
6785const myObject = {
6786 /**
6787 * Bad description
6788 */
6789 myProp: true
6790};
6791// "jsdoc/match-description": ["error"|"warn", {"contexts":["Property"]}]
6792// Message: JSDoc description does not satisfy the regex pattern.
6793
6794/**
6795 * @param foo Foo bar
6796 */
6797function quux (foo) {
6798
6799}
6800// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6801// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
6802// Message: JSDoc description does not satisfy the regex pattern.
6803
6804/**
6805 * Foo bar
6806 */
6807function quux (foo) {
6808
6809}
6810// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6811// Message: JSDoc description does not satisfy the regex pattern.
6812````
6813
6814The following patterns are not considered problems:
6815
6816````js
6817/**
6818 *
6819 */
6820
6821/**
6822 *
6823 */
6824 function quux () {
6825
6826 }
6827
6828/**
6829 * @param foo - Foo.
6830 */
6831function quux () {
6832
6833}
6834// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
6835
6836/**
6837 * Foo.
6838 */
6839function quux () {
6840
6841}
6842
6843/**
6844 * Foo.
6845 * Bar.
6846 */
6847function quux () {
6848
6849}
6850
6851/**
6852 * Foo.
6853 *
6854 * Bar.
6855 */
6856function quux () {
6857
6858}
6859
6860/**
6861 * Тест.
6862 */
6863function quux () {
6864
6865}
6866// "jsdoc/match-description": ["error"|"warn", {"matchDescription":"[А-Я][А-я]+\\."}]
6867
6868/**
6869 * @param notRet
6870 * @returns Тест.
6871 */
6872function quux () {
6873
6874}
6875// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":"[А-Я][А-я]+\\."}}]
6876
6877/**
6878 * @param notRet
6879 * @description Тест.
6880 */
6881function quux () {
6882
6883}
6884// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":"[А-Я][А-я]+\\."}}]
6885
6886/**
6887 * Foo
6888 * bar.
6889 */
6890function quux () {
6891
6892}
6893
6894/**
6895 * @returns Foo bar.
6896 */
6897function quux () {
6898
6899}
6900// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
6901
6902/**
6903 * @returns {type1} Foo bar.
6904 */
6905function quux () {
6906
6907}
6908// "jsdoc/match-description": ["error"|"warn", {"tags":{"returns":true}}]
6909
6910/**
6911 * @description Foo bar.
6912 */
6913function quux () {
6914
6915}
6916// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
6917
6918/**
6919 * @description Foo
6920 * bar.
6921 * @param
6922 */
6923function quux () {
6924
6925}
6926// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
6927
6928/** @description Foo bar. */
6929function quux () {
6930
6931}
6932// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
6933
6934/**
6935 * @description Foo
6936 * bar.
6937 */
6938function quux () {
6939
6940}
6941// "jsdoc/match-description": ["error"|"warn", {"tags":{"description":true}}]
6942
6943/**
6944 * Foo. {@see Math.sin}.
6945 */
6946function quux () {
6947
6948}
6949
6950/**
6951 * Foo {@see Math.sin} bar.
6952 */
6953function quux () {
6954
6955}
6956
6957/**
6958 * Foo?
6959 *
6960 * Bar!
6961 *
6962 * Baz:
6963 * 1. Foo.
6964 * 2. Bar.
6965 */
6966function quux () {
6967
6968}
6969
6970/**
6971 * Hello:
6972 * World.
6973 */
6974function quux () {
6975
6976}
6977
6978/**
6979 * Hello: world.
6980 */
6981function quux () {
6982
6983}
6984
6985/**
6986 * Foo
6987 * Bar.
6988 */
6989function quux () {
6990
6991}
6992
6993/**
6994 * Foo.
6995 *
6996 * foo.
6997 */
6998function quux () {
6999
7000}
7001
7002/**
7003 * foo.
7004 */
7005function quux () {
7006
7007}
7008// "jsdoc/match-description": ["error"|"warn", {"mainDescription":false}]
7009
7010/**
7011 * foo.
7012 */
7013class quux {
7014
7015}
7016
7017/**
7018 * foo.
7019 */
7020class quux {
7021
7022}
7023// "jsdoc/match-description": ["error"|"warn", {"mainDescription":true}]
7024
7025class MyClass {
7026 /**
7027 * Abc.
7028 */
7029 myClassField = 1
7030}
7031// "jsdoc/match-description": ["error"|"warn", {"contexts":["ClassProperty"]}]
7032
7033/**
7034 * Foo.
7035 */
7036interface quux {
7037
7038}
7039// "jsdoc/match-description": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"]}]
7040
7041const myObject = {
7042 /**
7043 * Bad description
7044 */
7045 myProp: true
7046};
7047// "jsdoc/match-description": ["error"|"warn", {"contexts":[]}]
7048
7049/**
7050 * foo.
7051 */
7052const q = class {
7053
7054}
7055// "jsdoc/match-description": ["error"|"warn", {"contexts":[]}]
7056
7057/**
7058 * foo.
7059 */
7060const q = {
7061
7062};
7063// "jsdoc/match-description": ["error"|"warn", {"contexts":[]}]
7064
7065/**
7066 * @description foo.
7067 */
7068function quux () {
7069
7070}
7071// "jsdoc/match-description": ["error"|"warn", {"tags":{"param":true}}]
7072
7073/**
7074 * Foo.
7075 *
7076 * @summary Foo.
7077 */
7078function quux () {
7079
7080}
7081// "jsdoc/match-description": ["error"|"warn", {"tags":{"summary":true}}]
7082
7083/**
7084 * Foo.
7085 *
7086 * @author Somebody
7087 */
7088function quux () {
7089
7090}
7091// "jsdoc/match-description": ["error"|"warn", {"tags":{"author":".+"}}]
7092
7093/**
7094 * Foo.
7095 *
7096 * @x-tag something
7097 */
7098function quux () {
7099
7100}
7101// "jsdoc/match-description": ["error"|"warn", {"tags":{"x-tag":".+"}}]
7102
7103/**
7104 * Foo.
7105 *
7106 * @prop foo Foo.
7107 */
7108function quux (foo) {
7109
7110}
7111// "jsdoc/match-description": ["error"|"warn", {"tags":{"prop":true}}]
7112
7113/**
7114 * @param foo Foo bar.
7115 */
7116function quux (foo) {
7117
7118}
7119// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
7120
7121/**
7122 *
7123 */
7124function quux () {
7125
7126}
7127// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
7128
7129/**
7130 * Foo.
7131 *
7132 * @template Abc, Def Foo.
7133 */
7134function quux (foo) {
7135
7136}
7137// "jsdoc/match-description": ["error"|"warn", {"tags":{"template":true}}]
7138
7139/**
7140 * Enable or disable plugin.
7141 *
7142 * When enabling with this function, the script will be attached to the `document` if:.
7143 * - the script runs in browser context.
7144 * - the `document` doesn't have the script already attached.
7145 * - the `loadScript` option is set to `true`.
7146 * @param enabled `true` to enable, `false` to disable. Default: `true`.
7147 */
7148// "jsdoc/match-description": ["error"|"warn", {"contexts":["any"],"mainDescription":"/^[A-Z`-].*\\.$/us","matchDescription":"^([A-Z`-].*(\\.|:)|-\\s.*)$","tags":{"param":true,"returns":true}}]
7149````
7150
7151
7152<a name="eslint-plugin-jsdoc-rules-multiline-blocks"></a>
7153### <code>multiline-blocks</code>
7154
7155Controls how and whether jsdoc blocks can be expressed as single or multiple
7156line blocks.
7157
7158Note that if you set `noSingleLineBlocks` and `noMultilineBlocks` to `true`
7159and configure them in a certain manner, you might effectively be prohibiting
7160all jsdoc blocks!
7161
7162Also allows for preventing text at the very beginning or very end of blocks.
7163
7164<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12"></a>
7165#### Options
7166
7167A single options object with the following properties.
7168
7169<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-nozerolinetext-defaults-to-true"></a>
7170##### <code>noZeroLineText</code> (defaults to <code>true</code>)
7171
7172For multiline blocks, any non-whitespace text immediately after the `/**` and
7173space will be reported. (Text after a newline is not reported.)
7174
7175`noMultilineBlocks` will have priority over this rule if it applies.
7176
7177<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-nofinallinetext-defaults-to-true"></a>
7178##### <code>noFinalLineText</code> (defaults to <code>true</code>)
7179
7180For multiline blocks, any non-whitespace text preceding the `*/` on the final
7181line will be reported. (Text preceding a newline is not reported.)
7182
7183`noMultilineBlocks` will have priority over this rule if it applies.
7184
7185<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-nosinglelineblocks-defaults-to-false"></a>
7186##### <code>noSingleLineBlocks</code> (defaults to <code>false</code>)
7187
7188If this is `true`, any single line blocks will be reported, except those which
7189are whitelisted in `singleLineTags`.
7190
7191<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-singlelinetags-defaults-to-lends-type"></a>
7192##### <code>singleLineTags</code> (defaults to <code>[&#39;lends&#39;, &#39;type&#39;]</code>)
7193
7194An array of tags which can nevertheless be allowed as single line blocks when
7195`noSingleLineBlocks` is set. You may set this to a empty array to
7196cause all single line blocks to be reported. If `'*'` is present, then
7197the presence of a tag will allow single line blocks (but not if a tag is
7198missing).
7199
7200<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-nomultilineblocks-defaults-to-false"></a>
7201##### <code>noMultilineBlocks</code> (defaults to <code>false</code>)
7202
7203Requires that jsdoc blocks are restricted to single lines only unless impacted
7204by the options `minimumLengthForMultiline`, `multilineTags`, or
7205`allowMultipleTags`.
7206
7207<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-minimumlengthformultiline-defaults-to-not-being-in-effect"></a>
7208##### <code>minimumLengthForMultiline</code> (defaults to not being in effect)
7209
7210If `noMultilineBlocks` is set with this numeric option, multiline blocks will
7211be permitted if containing at least the given amount of text.
7212
7213If not set, multiline blocks will not be permitted regardless of length unless
7214a relevant tag is present and `multilineTags` is set.
7215
7216<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-multilinetags-defaults-to"></a>
7217##### <code>multilineTags</code> (defaults to <code>[&#39;*&#39;]</code>)
7218
7219If `noMultilineBlocks` is set with this option, multiline blocks may be allowed
7220regardless of length as long as a tag or a tag of a certain type is present.
7221
7222If `*` is included in the array, the presence of a tags will allow for
7223multiline blocks (but not when without any tags unless the amount of text is
7224over an amount specified by `minimumLengthForMultiline`).
7225
7226If the array does not include `*` but lists certain tags, the presence of
7227such a tag will cause multiline blocks to be allowed.
7228
7229You may set this to an empty array to prevent any tag from permitting multiple
7230lines.
7231
7232<a name="eslint-plugin-jsdoc-rules-multiline-blocks-options-12-allowmultipletags-defaults-to-true"></a>
7233##### <code>allowMultipleTags</code> (defaults to <code>true</code>)
7234
7235If `noMultilineBlocks` is set to `true` with this option and multiple tags are
7236found in a block, an error will not be reported.
7237
7238Since multiple-tagged lines cannot be collapsed into a single line, this option
7239prevents them from being reported. Set to `false` if you really want to report
7240any blocks.
7241
7242This option will also be applied when there is a block description and a single
7243tag (since a description cannot precede a tag on a single line, and also
7244cannot be reliably added after the tag either).
7245
7246|||
7247|---|---|
7248|Context|everywhere|
7249|Tags|Any (though `singleLineTags` and `multilineTags` control the application)|
7250|Recommended|true|
7251|Settings||
7252|Options|`noZeroLineText`, `noSingleLineBlocks`, `singleLineTags`, `noMultilineBlocks`, `minimumLengthForMultiline`, `multilineTags`, `allowMultipleTags`, `noFinalLineText`|
7253
7254The following patterns are considered problems:
7255
7256````js
7257/** Reported up here
7258 * because the rest is multiline
7259 */
7260// Message: Should have no text on the "0th" line (after the `/**`).
7261
7262/** Reported up here
7263 * because the rest is multiline
7264 */
7265// "jsdoc/multiline-blocks": ["error"|"warn", {"noZeroLineText":true}]
7266// Message: Should have no text on the "0th" line (after the `/**`).
7267
7268/** @abc {aType} aName Reported up here
7269 * because the rest is multiline
7270 */
7271// "jsdoc/multiline-blocks": ["error"|"warn", {"noZeroLineText":true}]
7272// Message: Should have no text on the "0th" line (after the `/**`).
7273
7274/** @tag */
7275// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
7276// Message: Single line blocks are not permitted by your configuration.
7277
7278/** @tag {someType} */
7279// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
7280// Message: Single line blocks are not permitted by your configuration.
7281
7282/** @tag {someType} aName */
7283// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
7284// Message: Single line blocks are not permitted by your configuration.
7285
7286/** @tag */
7287// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["someOtherTag"]}]
7288// Message: Single line blocks are not permitted by your configuration.
7289
7290/** desc */
7291// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["*"]}]
7292// Message: Single line blocks are not permitted by your configuration.
7293
7294/**
7295 * Desc.
7296 */
7297// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
7298// Message: Multiline jsdoc blocks are prohibited by your configuration.
7299
7300/** desc
7301 *
7302 */
7303// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
7304// Message: Multiline jsdoc blocks are prohibited by your configuration.
7305
7306/** desc
7307 *
7308 */
7309// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
7310// Message: Multiline jsdoc blocks are prohibited by your configuration but fixing would result in a single line block which you have prohibited with `noSingleLineBlocks`.
7311
7312/**
7313 *
7314 */
7315// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
7316// Message: Multiline jsdoc blocks are prohibited by your configuration.
7317
7318/**
7319 * This is not long enough to be permitted.
7320 */
7321// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":100,"noMultilineBlocks":true}]
7322// Message: Multiline jsdoc blocks are prohibited by your configuration.
7323
7324/**
7325 * This is not long enough to be permitted.
7326 */
7327// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":true,"minimumLengthForMultiline":100,"noMultilineBlocks":true}]
7328// Message: Multiline jsdoc blocks are prohibited by your configuration.
7329
7330/**
7331 * This has the wrong tags so is not permitted.
7332 * @notTheRightTag
7333 */
7334// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":["onlyThisIsExempted"],"noMultilineBlocks":true}]
7335// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has a description with a tag.
7336
7337/**
7338 * This has too many tags so cannot be fixed ot a single line.
7339 * @oneTag
7340 * @anotherTag
7341 */
7342// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":[],"noMultilineBlocks":true}]
7343// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has multiple tags.
7344
7345/**
7346 * This has a tag and description so cannot be fixed ot a single line.
7347 * @oneTag
7348 */
7349// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":[],"noMultilineBlocks":true}]
7350// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has a description with a tag.
7351
7352/**
7353 * This has no tags so is not permitted.
7354 */
7355// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":["*"],"noMultilineBlocks":true}]
7356// Message: Multiline jsdoc blocks are prohibited by your configuration.
7357
7358/**
7359 * This has the wrong tags so is not permitted.
7360 * @notTheRightTag
7361 */
7362// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"minimumLengthForMultiline":500,"multilineTags":["onlyThisIsExempted"],"noMultilineBlocks":true}]
7363// Message: Multiline jsdoc blocks are prohibited by your configuration but the block has a description with a tag.
7364
7365/**
7366 * @lends This can be safely fixed to a single line.
7367 */
7368// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true,"noSingleLineBlocks":true}]
7369// Message: Multiline jsdoc blocks are prohibited by your configuration.
7370
7371/**
7372 * @type {aType} This can be safely fixed to a single line.
7373 */
7374// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true,"noSingleLineBlocks":true}]
7375// Message: Multiline jsdoc blocks are prohibited by your configuration.
7376
7377/**
7378 * @aTag
7379 */
7380// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}]
7381// Message: Multiline jsdoc blocks are prohibited by your configuration.
7382
7383/**
7384 * This is a problem when single and multiline are blocked.
7385 */
7386// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
7387// Message: Multiline jsdoc blocks are prohibited by your configuration but fixing would result in a single line block which you have prohibited with `noSingleLineBlocks`.
7388
7389/** This comment is bad
7390 * It should not have text on line zero
7391 */
7392// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true,"noZeroLineText":true}]
7393// Message: Should have no text on the "0th" line (after the `/**`).
7394
7395/**
7396 * @lends This can be safely fixed
7397 * to a single
7398 * line. */
7399// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}]
7400// Message: Multiline jsdoc blocks are prohibited by your configuration.
7401
7402/**
7403 * @someTag {aType} with Description */
7404// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineBlocks":true}]
7405// Message: Should have no text on the final line (before the `*/`).
7406
7407/**
7408 * Description */
7409// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineBlocks":true}]
7410// Message: Should have no text on the final line (before the `*/`).
7411````
7412
7413The following patterns are not considered problems:
7414
7415````js
7416/** Not reported */
7417
7418/**
7419 * Not reported
7420 */
7421
7422/** Reported up here
7423 * because the rest is multiline
7424 */
7425// "jsdoc/multiline-blocks": ["error"|"warn", {"noZeroLineText":false}]
7426
7427/** @tag */
7428
7429/** @lends */
7430// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true}]
7431
7432/** @tag */
7433// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["tag"]}]
7434
7435/** @tag */
7436// "jsdoc/multiline-blocks": ["error"|"warn", {"noSingleLineBlocks":true,"singleLineTags":["*"]}]
7437
7438/**
7439 *
7440 */
7441
7442/**
7443 *
7444 */
7445// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":false}]
7446
7447/** Test */
7448// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true}]
7449
7450/**
7451 * This is long enough to be permitted by our config.
7452 */
7453// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":25,"noMultilineBlocks":true}]
7454
7455/**
7456 * This is long enough to be permitted by our config.
7457 */
7458// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":50,"noMultilineBlocks":true}]
7459
7460/**
7461 * This has the right tag so is permitted.
7462 * @theRightTag
7463 */
7464// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":["theRightTag"],"noMultilineBlocks":true}]
7465
7466/** This has no tags but is single line so is not permitted. */
7467// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":["*"],"noMultilineBlocks":true}]
7468
7469/**
7470 * This has the wrong tags so is not permitted.
7471 * @notTheRightTag
7472 */
7473// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":10,"multilineTags":["onlyThisIsExempted"],"noMultilineBlocks":true}]
7474
7475/**
7476 * This has the wrong tags so is not permitted.
7477 * @theRightTag
7478 */
7479// "jsdoc/multiline-blocks": ["error"|"warn", {"minimumLengthForMultiline":500,"multilineTags":["theRightTag"],"noMultilineBlocks":true}]
7480
7481/** tag */
7482
7483/**
7484 * @lends This is ok per multiline
7485 */
7486// "jsdoc/multiline-blocks": ["error"|"warn", {"noMultilineBlocks":true,"noSingleLineBlocks":true}]
7487
7488/**
7489 * This has too many tags so cannot be fixed ot a single line.
7490 * @oneTag
7491 * @anotherTag
7492 */
7493// "jsdoc/multiline-blocks": ["error"|"warn", {"multilineTags":[],"noMultilineBlocks":true}]
7494
7495/**
7496 * This has too many tags so cannot be fixed ot a single line.
7497 * @oneTag
7498 * @anotherTag
7499 */
7500// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":true,"multilineTags":[],"noMultilineBlocks":true}]
7501
7502/**
7503 * This has a tag and description so cannot be fixed ot a single line.
7504 * @oneTag
7505 */
7506// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":true,"multilineTags":[],"noMultilineBlocks":true}]
7507
7508/**
7509 * This has a tag and description so cannot be fixed ot a single line.
7510 * @oneTag
7511 */
7512// "jsdoc/multiline-blocks": ["error"|"warn", {"allowMultipleTags":false,"multilineTags":["oneTag"],"noMultilineBlocks":true}]
7513
7514/** @someTag with Description */
7515// "jsdoc/multiline-blocks": ["error"|"warn", {"noFinalLineBlocks":true}]
7516````
7517
7518
7519<a name="eslint-plugin-jsdoc-rules-newline-after-description"></a>
7520### <code>newline-after-description</code>
7521
7522Enforces a consistent padding of the block description.
7523
7524<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-13"></a>
7525#### Options
7526
7527This rule allows one optional string argument. If it is `"always"` then a
7528problem is raised when there is no newline after the description. If it is
7529`"never"` then a problem is raised when there is a newline after the
7530description. The default value is `"always"`.
7531
7532|||
7533|---|---|
7534|Context|everywhere|
7535|Tags|N/A (doc block)|
7536|Options|(a string matching `"always" or "never"`)|
7537|Recommended|true|
7538
7539The following patterns are considered problems:
7540
7541````js
7542/**
7543 * Foo.
7544 *
7545 * Foo.
7546 * @foo
7547 */
7548function quux () {
7549
7550}
7551// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7552// Message: There must be a newline after the description of the JSDoc block.
7553
7554/**
7555 * Foo.
7556 * @foo
7557 *
7558 * Foo.
7559 */
7560function quux () {
7561
7562}
7563// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7564// Message: There must be a newline after the description of the JSDoc block.
7565
7566/**
7567 * Foo.
7568 *
7569 * Foo.
7570 * @foo
7571 */
7572function quux () {
7573
7574}
7575// Message: There must be a newline after the description of the JSDoc block.
7576
7577/**
7578 * Bar.
7579 *
7580 * Bar.
7581 *
7582 * @bar
7583 */
7584function quux () {
7585
7586}
7587// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7588// Message: There must be no newline after the description of the JSDoc block.
7589
7590/**
7591 * Bar.
7592 *
7593 * @bar
7594 *
7595 * Bar.
7596 */
7597function quux () {
7598
7599}
7600// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7601// Message: There must be no newline after the description of the JSDoc block.
7602
7603
7604 /**
7605 * Bar.
7606 *
7607 * Bar.
7608 *
7609 * @bar
7610 */
7611 function quux () {
7612
7613 }
7614// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7615// Message: There must be no newline after the description of the JSDoc block.
7616
7617/**
7618 * A.
7619 *
7620 * @typedef {object} A
7621 * @prop {boolean} a A.
7622 */
7623// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7624// Message: There must be no newline after the description of the JSDoc block.
7625
7626/**
7627 * A.
7628 * @typedef {object} A
7629 * @prop {boolean} a A.
7630 */
7631// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7632// Message: There must be a newline after the description of the JSDoc block.
7633
7634
7635 /**
7636 * Service for fetching symbols.
7637 * @param {object} $http - Injected http helper.
7638 * @param {object} $q - Injected Promise api helper.
7639 * @param {object} $location - Injected window location object.
7640 * @param {object} REPORT_DIALOG_CONSTANTS - Injected handle.
7641 */
7642// Message: There must be a newline after the description of the JSDoc block.
7643
7644/** An example function.
7645 *
7646 * @returns {number} An example number.
7647 */
7648function example() {
7649 return 42;
7650}
7651// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7652// Message: There must be no newline after the description of the JSDoc block.
7653
7654/** An example function.
7655 * @returns {number} An example number.
7656 */
7657function example() {
7658 return 42;
7659}
7660// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7661// Message: There must be a newline after the description of the JSDoc block.
7662````
7663
7664The following patterns are not considered problems:
7665
7666````js
7667/**
7668 * Foo.
7669 */
7670function quux () {
7671
7672}
7673// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7674
7675/**
7676 * Bar.
7677 */
7678function quux () {
7679
7680}
7681// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7682
7683/**
7684 * Foo.
7685 *
7686 * @foo
7687 */
7688function quux () {
7689
7690}
7691// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7692
7693/**
7694 * Bar.
7695 * @bar
7696 */
7697function quux () {
7698
7699}
7700// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7701
7702
7703 /**
7704 * @foo
7705 * Test 
7706 * abc 
7707 * @bar 
7708 */
7709
7710
7711 /**
7712 *
7713 * @foo
7714 * Test 
7715 * abc 
7716 * @bar 
7717 */
7718
7719/***
7720 *
7721 */
7722function quux () {
7723
7724}
7725// "jsdoc/newline-after-description": ["error"|"warn", "always"]
7726
7727/**
7728 * Parses query string to object containing URL parameters
7729 *
7730 * @param queryString
7731 * Input string
7732 *
7733 * @returns
7734 * Object containing URL parameters
7735 */
7736export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails
7737
7738}
7739
7740/** An example function.
7741 *
7742 * @returns {number} An example number.
7743 */
7744function example() {
7745 return 42;
7746}
7747
7748/** An example function.
7749 * @returns {number} An example number.
7750 */
7751function example() {
7752 return 42;
7753}
7754// "jsdoc/newline-after-description": ["error"|"warn", "never"]
7755````
7756
7757
7758<a name="eslint-plugin-jsdoc-rules-no-bad-blocks"></a>
7759### <code>no-bad-blocks</code>
7760
7761This rule checks for multi-line-style comments which fail to meet the
7762criteria of a jsdoc block, namely that it should begin with two and only two
7763asterisks, but which appear to be intended as jsdoc blocks due to the presence
7764of whitespace followed by whitespace or asterisks, and
7765an at-sign (`@`) and some non-whitespace (as with a jsdoc block tag).
7766
7767<a name="eslint-plugin-jsdoc-rules-no-bad-blocks-options-14"></a>
7768#### Options
7769
7770Takes an optional options object with the following.
7771
7772<a name="eslint-plugin-jsdoc-rules-no-bad-blocks-options-14-ignore"></a>
7773##### <code>ignore</code>
7774
7775An array of directives that will not be reported if present at the beginning of
7776a multi-comment block and at-sign `/* @`.
7777
7778Defaults to `['ts-check', 'ts-expect-error', 'ts-ignore', 'ts-nocheck']`
7779(some directives [used by TypeScript](https://www.typescriptlang.org/docs/handbook/intro-to-js-ts.html#ts-check)).
7780
7781<a name="eslint-plugin-jsdoc-rules-no-bad-blocks-options-14-preventallmultiasteriskblocks"></a>
7782##### <code>preventAllMultiAsteriskBlocks</code>
7783
7784A boolean (defaulting to `false`) which if `true` will prevent all
7785multi-asterisked blocks even those without apparent tag content.
7786
7787|||
7788|---|---|
7789|Context|Everywhere|
7790|Tags|N/A|
7791|Recommended|false|
7792|Options|`ignore`, `preventAllMultiAsteriskBlocks`|
7793
7794The following patterns are considered problems:
7795
7796````js
7797/*
7798 * @param foo
7799 */
7800function quux (foo) {
7801
7802}
7803// Message: Expected JSDoc-like comment to begin with two asterisks.
7804
7805/*
7806 * @property foo
7807 */
7808// Message: Expected JSDoc-like comment to begin with two asterisks.
7809
7810function quux() {
7811
7812}
7813// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
7814// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
7815
7816/* @ts-ignore */
7817// "jsdoc/no-bad-blocks": ["error"|"warn", {"ignore":[]}]
7818// Message: Expected JSDoc-like comment to begin with two asterisks.
7819
7820/*
7821 * Some description.
7822 *
7823 * @returns {string} Some string
7824 */
7825function echo() {
7826 return 'Something';
7827}
7828// Message: Expected JSDoc-like comment to begin with two asterisks.
7829
7830/***
7831 * @param foo
7832 */
7833function quux (foo) {
7834
7835}
7836// Message: Expected JSDoc-like comment to begin with two asterisks.
7837
7838/***
7839 *
7840 */
7841function quux (foo) {
7842
7843}
7844// "jsdoc/no-bad-blocks": ["error"|"warn", {"preventAllMultiAsteriskBlocks":true}]
7845// Message: Expected JSDoc-like comment to begin with two asterisks.
7846````
7847
7848The following patterns are not considered problems:
7849
7850````js
7851/**
7852 * @property foo
7853 */
7854
7855/**
7856 * @param foo
7857 */
7858 function quux () {
7859
7860 }
7861
7862function quux () {
7863
7864}
7865
7866/* This could just be intended as a regular multiline comment,
7867 so don't report this */
7868function quux () {
7869
7870}
7871
7872/* Just a regular multiline comment with an `@` but not appearing
7873 like a tag in a jsdoc-block, so don't report */
7874function quux () {
7875
7876}
7877
7878/* @ts-check */
7879
7880/* @ts-expect-error */
7881
7882/* @ts-ignore */
7883
7884/* @ts-nocheck */
7885
7886/* */
7887
7888/* @custom */
7889// "jsdoc/no-bad-blocks": ["error"|"warn", {"ignore":["custom"]}]
7890
7891/***
7892 * This is not JSDoc because of the 3 asterisks, but
7893 * is allowed without `preventAllMultiAsteriskBlocks`, as
7894 * some might wish normal multiline comments.
7895 */
7896function quux (foo) {
7897
7898}
7899````
7900
7901
7902<a name="eslint-plugin-jsdoc-rules-no-defaults"></a>
7903### <code>no-defaults</code>
7904
7905This rule reports defaults being used on the relevant portion of `@param`
7906or `@default`. It also optionally reports the presence of the
7907square-bracketed optional arguments at all.
7908
7909The rule is intended to prevent the indication of defaults on tags where
7910this would be redundant with ES6 default parameters (or for `@default`,
7911where it would be redundant with the context to which the `@default`
7912tag is attached).
7913
7914Unless your `@default` is on a function, you will need to set `contexts`
7915to an appropriate context, including, if you wish, "any".
7916
7917<a name="eslint-plugin-jsdoc-rules-no-defaults-options-15"></a>
7918#### Options
7919
7920<a name="eslint-plugin-jsdoc-rules-no-defaults-options-15-nooptionalparamnames"></a>
7921##### <code>noOptionalParamNames</code>
7922
7923Set this to `true` to report the presence of optional parameters. May be
7924used if the project is insisting on optionality being indicated by
7925the presence of ES6 default parameters (bearing in mind that such
7926"defaults" are only applied when the supplied value is missing or
7927`undefined` but not for `null` or other "falsey" values).
7928
7929<a name="eslint-plugin-jsdoc-rules-no-defaults-options-15-contexts-2"></a>
7930##### <code>contexts</code>
7931
7932Set this to an array of strings representing the AST context (or an object with
7933`context` and `comment` properties) where you wish the rule to be applied.
7934Overrides the default contexts (see below). Set to `"any"` if you want
7935the rule to apply to any jsdoc block throughout your files (as is necessary
7936for finding function blocks not attached to a function declaration or
7937expression, i.e., `@callback` or `@function` (or its aliases `@func` or
7938`@method`) (including those associated with an `@interface`).
7939
7940See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
7941section of our README for more on the expected format.
7942
7943|||
7944|---|---|
7945|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
7946|Tags|`param`, `default`|
7947|Aliases|`arg`, `argument`, `defaultvalue`|
7948|Recommended|false|
7949|Options|`contexts`, `noOptionalParamNames`|
7950
7951The following patterns are considered problems:
7952
7953````js
7954/**
7955 * @param {number} [foo="7"]
7956 */
7957function quux (foo) {
7958
7959}
7960// Message: Defaults are not permitted on @param.
7961
7962class Test {
7963 /**
7964 * @param {number} [foo="7"]
7965 */
7966 quux (foo) {
7967
7968 }
7969}
7970// Message: Defaults are not permitted on @param.
7971
7972/**
7973 * @param {number} [foo="7"]
7974 */
7975function quux (foo) {
7976
7977}
7978// "jsdoc/no-defaults": ["error"|"warn", {"noOptionalParamNames":true}]
7979// Message: Optional param names are not permitted on @param.
7980
7981/**
7982 * @arg {number} [foo="7"]
7983 */
7984function quux (foo) {
7985
7986}
7987// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
7988// Message: Defaults are not permitted on @arg.
7989
7990/**
7991 * @param {number} [foo="7"]
7992 */
7993function quux (foo) {
7994
7995}
7996// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
7997// Message: Defaults are not permitted on @param.
7998
7999/**
8000 * @function
8001 * @param {number} [foo="7"]
8002 */
8003// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
8004// Message: Defaults are not permitted on @param.
8005
8006/**
8007 * @callback
8008 * @param {number} [foo="7"]
8009 */
8010// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
8011// Message: Defaults are not permitted on @param.
8012
8013/**
8014 * @default {}
8015 */
8016const a = {};
8017// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
8018// Message: Default values are not permitted on @default.
8019
8020/**
8021 * @defaultvalue {}
8022 */
8023const a = {};
8024// Settings: {"jsdoc":{"tagNamePreference":{"default":"defaultvalue"}}}
8025// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
8026// Message: Default values are not permitted on @defaultvalue.
8027````
8028
8029The following patterns are not considered problems:
8030
8031````js
8032/**
8033 * @param foo
8034 */
8035function quux (foo) {
8036
8037}
8038
8039/**
8040 * @param {number} foo
8041 */
8042function quux (foo) {
8043
8044}
8045
8046/**
8047 * @param foo
8048 */
8049// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
8050
8051/**
8052 * @function
8053 * @param {number} foo
8054 */
8055
8056/**
8057 * @callback
8058 * @param {number} foo
8059 */
8060
8061/**
8062 * @param {number} foo
8063 */
8064function quux (foo) {
8065
8066}
8067// "jsdoc/no-defaults": ["error"|"warn", {"noOptionalParamNames":true}]
8068
8069/**
8070 * @default
8071 */
8072const a = {};
8073// "jsdoc/no-defaults": ["error"|"warn", {"contexts":["any"]}]
8074````
8075
8076
8077<a name="eslint-plugin-jsdoc-rules-no-missing-syntax"></a>
8078### <code>no-missing-syntax</code>
8079
8080This rule lets you report when certain comment structures are always expected.
8081This rule might be especially useful with [`overrides`](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
8082where you need only require tags and/or types within specific directories
8083(e.g., to enforce that a plugins or locale directory always has a certain form
8084of export).
8085
8086This (along with `no-restricted-syntax`) is a bit similar to Schematron for
8087XML or jsontron for JSON--you can validate expectations of there being
8088arbitrary structures.
8089
8090This differs from the rule of the same name in [`eslint-plugin-query`](https://github.com/brettz9/eslint-plugin-query)
8091in that this always looks for a comment above a structure (whether or not
8092you have a `comment` condition).
8093
8094In addition to being generally useful for precision in requiring contexts,
8095it is hoped that the ability to specify required tags on structures can
8096be used for requiring `@type` or other types for a minimalist yet adequate
8097specification of types which can be used to compile JavaScript+JSDoc (JJ)
8098to WebAssembly (e.g., by converting it to TypeSscript and then using
8099AssemblyScript to convert to WebAssembly). (It may be possible that one
8100will need to require types with certain structures beyond function
8101declarations and the like, as well as optionally requiring specification
8102of number types.)
8103
8104Note that you can use selectors which make use of negators like `:not()`
8105including with asterisk, e.g., `*:not(FunctionDeclaration)` to indicate types
8106which are not adequate to satisfy a condition, e.g.,
8107`FunctionDeclaration:not(FunctionDeclaration[id.name="ignoreMe"])` would
8108not report if there were only a function declaration of the name "ignoreMe"
8109(though it would report by function declarations of other names).
8110
8111<a name="eslint-plugin-jsdoc-rules-no-missing-syntax-options-16"></a>
8112#### Options
8113
8114<a name="eslint-plugin-jsdoc-rules-no-missing-syntax-options-16-contexts-3"></a>
8115##### <code>contexts</code>
8116
8117Set this to an array of strings representing the AST context (or an object with
8118`context` and `comment` properties) where you wish the rule to be applied.
8119
8120Use the `minimum` property (defaults to 1) to indicate how many are required
8121for the rule to be reported.
8122
8123Use the `message` property to indicate the specific error to be shown when an
8124error is reported for that context being found missing. You may use
8125`{{context}}` and `{{comment}}` with such messages.
8126
8127Set to `"any"` if you want the rule to apply to any jsdoc block throughout
8128your files (as is necessary for finding function blocks not attached to a
8129function declaration or expression, i.e., `@callback` or `@function` (or its
8130aliases `@func` or `@method`) (including those associated with an `@interface`).
8131
8132See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
8133section of our README for more on the expected format.
8134
8135|||
8136|---|---|
8137|Context|None except those indicated by `contexts`|
8138|Tags|Any if indicated by AST|
8139|Recommended|false|
8140|Options|`contexts`|
8141
8142The following patterns are considered problems:
8143
8144````js
8145/**
8146 * @implements {Bar|Foo}
8147 */
8148function quux () {
8149
8150}
8151// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
8152// Message: Syntax is required: FunctionDeclaration with JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Foo"]:nth-child(1))
8153
8154/**
8155 * @implements {Bar|Foo}
8156 */
8157function quux () {
8158
8159}
8160// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration","message":"Problematically missing function syntax: `{{context}}` with `{{comment}}`."}]}]
8161// Message: Problematically missing function syntax: `FunctionDeclaration` with `JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Foo"]:nth-child(1))`.
8162
8163/**
8164 * @implements {Bar|Foo}
8165 */
8166function quux () {
8167
8168}
8169// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
8170// Message: Syntax is required: FunctionDeclaration
8171
8172/**
8173 * @implements {Bar|Foo}
8174 */
8175function quux () {
8176
8177}
8178// Message: Rule `no-restricted-syntax` is missing a `context` option.
8179
8180/**
8181 * @implements {Bar|Foo}
8182 */
8183function quux () {
8184
8185}
8186// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration","minimum":2}]}]
8187// Message: Syntax is required: FunctionDeclaration with JsdocBlock[postDelimiter=""]:has(JsdocTypeUnion > JsdocTypeName[value="Bar"]:nth-child(1))
8188
8189/**
8190 * @param ab
8191 * @param cd
8192 */
8193// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
8194// Message: Require names matching `/^opt_/i`.
8195
8196/**
8197 * @param ab
8198 * @param cd
8199 */
8200function quux () {}
8201// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
8202// Message: Require names matching `/^opt_/i`.
8203````
8204
8205The following patterns are not considered problems:
8206
8207````js
8208/**
8209 * @implements {Bar|Foo}
8210 */
8211function quux () {
8212
8213}
8214// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
8215
8216/**
8217 * @implements {Bar|Foo}
8218 */
8219function quux () {
8220
8221}
8222
8223/**
8224 * @implements {Bar|Foo}
8225 */
8226function bar () {
8227
8228}
8229
8230/**
8231 * @implements {Bar|Foo}
8232 */
8233function baz () {
8234
8235}
8236// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration","minimum":2}]}]
8237
8238/**
8239 * @param opt_a
8240 * @param opt_b
8241 */
8242// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
8243
8244/**
8245 * @param opt_a
8246 * @param opt_b
8247 */
8248function quux () {}
8249// "jsdoc/no-missing-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Require names matching `/^opt_/i`."}]}]
8250````
8251
8252
8253<a name="eslint-plugin-jsdoc-rules-no-multi-asterisks"></a>
8254### <code>no-multi-asterisks</code>
8255
8256Prevents use of multiple asterisks at the beginning of lines.
8257
8258Note that if you wish to prevent multiple asterisks at the very beginning of
8259the jsdoc block, you should use `no-bad-blocks` (as that is not proper jsdoc
8260and that rule is for catching blocks which only seem like jsdoc).
8261
8262<a name="eslint-plugin-jsdoc-rules-no-multi-asterisks-options-17"></a>
8263#### Options
8264
8265<a name="eslint-plugin-jsdoc-rules-no-multi-asterisks-options-17-preventatmiddlelines-defaults-to-true"></a>
8266##### <code>preventAtMiddleLines</code> (defaults to <code>true</code>)
8267
8268Prevent the likes of this:
8269
8270```js
8271/**
8272 *
8273 **
8274 */
8275```
8276
8277<a name="eslint-plugin-jsdoc-rules-no-multi-asterisks-options-17-preventatend-defaults-to-true"></a>
8278##### <code>preventAtEnd</code> (defaults to <code>true</code>)
8279
8280Prevent the likes of this:
8281
8282```js
8283/**
8284 *
8285 *
8286 **/
8287```
8288
8289|||
8290|---|---|
8291|Context|everywhere|
8292|Tags|(any)|
8293|Recommended|true|
8294|Settings||
8295|Options|`preventAtEnd`, `preventAtMiddleLines`|
8296
8297The following patterns are considered problems:
8298
8299````js
8300/**
8301 *
8302 **
8303 */
8304// Message: Should be no multiple asterisks on middle lines.
8305
8306/**
8307 *
8308 **
8309 */
8310// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtMiddleLines":true}]
8311// Message: Should be no multiple asterisks on middle lines.
8312
8313/**
8314 *
8315 **
8316 */
8317// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":false}]
8318// Message: Should be no multiple asterisks on middle lines.
8319
8320/**
8321 * With a description
8322 * @tag {SomeType} and a tag with details
8323 **
8324 */
8325// Message: Should be no multiple asterisks on middle lines.
8326
8327/**
8328 **
8329 *
8330 */
8331// Message: Should be no multiple asterisks on middle lines.
8332
8333/**
8334 * Desc.
8335 *
8336 **/
8337// Message: Should be no multiple asterisks on end lines.
8338
8339/**
8340 * Desc.
8341 *
8342 **/
8343// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":true}]
8344// Message: Should be no multiple asterisks on end lines.
8345
8346/**
8347 * Desc.
8348 *
8349 abc * **/
8350// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":true}]
8351// Message: Should be no multiple asterisks on end lines.
8352
8353/**
8354 * Desc.
8355 *
8356 **/
8357// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtMiddleLines":false}]
8358// Message: Should be no multiple asterisks on end lines.
8359
8360/** Desc. **/
8361// Message: Should be no multiple asterisks on end lines.
8362
8363/** @someTag name desc. **/
8364// Message: Should be no multiple asterisks on end lines.
8365
8366/** abc * */
8367// Message: Should be no multiple asterisks on end lines.
8368
8369/**
8370 * Preserve user's whitespace when fixing (though one may also
8371 * use an align rule)
8372 *
8373 * */
8374// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":true}]
8375// Message: Should be no multiple asterisks on end lines.
8376````
8377
8378The following patterns are not considered problems:
8379
8380````js
8381/**
8382 *
8383 * Desc. ***
8384 */
8385
8386/**
8387 * Desc. ***
8388 *
8389 */
8390
8391/**
8392 * Desc.
8393 *
8394 * sth */
8395
8396/**
8397 **
8398 *
8399 */
8400// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtMiddleLines":false}]
8401
8402/**
8403 *
8404 *
8405 **/
8406// "jsdoc/no-multi-asterisks": ["error"|"warn", {"preventAtEnd":false}]
8407
8408/**
8409 * With a desc.
8410 * and ***
8411 */
8412
8413/**
8414 * and ***
8415 * With a desc.
8416 */
8417
8418/**
8419 * With a desc.
8420 * With a desc.
8421 * Desc. */
8422
8423/**
8424 * With a description
8425 * @tag {SomeType} and a tag with details
8426 *
8427 */
8428
8429/** abc */
8430function foo() {
8431 //
8432}
8433
8434/** foo */
8435function foo(): void {
8436 //
8437}
8438
8439/** @aTag abc */
8440function foo() {
8441 //
8442}
8443````
8444
8445
8446<a name="eslint-plugin-jsdoc-rules-no-restricted-syntax"></a>
8447### <code>no-restricted-syntax</code>
8448
8449Reports when certain comment structures are present.
8450
8451Note that this rule differs from ESLint's [no-restricted-syntax](https://eslint.org/docs/rules/no-restricted-syntax)
8452rule in expecting values within a single options object's
8453`contexts` property, and with the property `context` being used in place of
8454`selector` (as well as allowing for `comment`). The format also differs from
8455the format expected by [`eslint-plugin-query`](https://github.com/brettz9/eslint-plugin-query).
8456
8457Unlike those rules, this is specific to finding comments attached to
8458structures, (whether or not you add a specific `comment` condition).
8459
8460Note that if your parser supports comment AST (as [jsdoc-eslint-parser/](https://github.com/brettz9/jsdoc-eslint-parser/) is designed to do), you can just use ESLint's
8461rule.
8462
8463<a name="eslint-plugin-jsdoc-rules-no-restricted-syntax-options-18"></a>
8464#### Options
8465
8466<a name="eslint-plugin-jsdoc-rules-no-restricted-syntax-options-18-contexts-4"></a>
8467##### <code>contexts</code>
8468
8469Set this to an array of strings representing the AST context (or an object with
8470`context` and `comment` properties) where you wish the rule to be applied.
8471
8472Use the `message` property to indicate the specific error to be shown when an
8473error is reported for that context being found.
8474
8475Set to `"any"` if you want the rule to apply to any jsdoc block throughout
8476your files (as is necessary for finding function blocks not attached to a
8477function declaration or expression, i.e., `@callback` or `@function` (or its
8478aliases `@func` or `@method`) (including those associated with an `@interface`).
8479
8480See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
8481section of our README for more on the expected format.
8482
8483|||
8484|---|---|
8485|Context|None except those indicated by `contexts`|
8486|Tags|Any if indicated by AST|
8487|Recommended|false|
8488|Options|`contexts`|
8489
8490The following patterns are considered problems:
8491
8492````js
8493/**
8494 *
8495 */
8496function quux () {
8497
8498}
8499// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
8500// Message: Syntax is restricted: FunctionDeclaration.
8501
8502/**
8503 *
8504 */
8505function quux () {
8506
8507}
8508// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"context":"FunctionDeclaration","message":"Oops: `{{context}}`."}]}]
8509// Message: Oops: `FunctionDeclaration`.
8510
8511/**
8512 * @implements {Bar|Foo}
8513 */
8514function quux () {
8515
8516}
8517// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
8518// Message: Syntax is restricted: FunctionDeclaration.
8519
8520/**
8521 * @implements {Bar|Foo}
8522 */
8523function quux () {
8524
8525}
8526// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration","message":"The foo one: {{context}}."},{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"FunctionDeclaration","message":"The bar one: {{context}}."}]}]
8527// Message: The bar one: FunctionDeclaration.
8528
8529/**
8530 * @implements {Bar|Foo}
8531 */
8532function quux () {
8533
8534}
8535// Message: Rule `no-restricted-syntax` is missing a `context` option.
8536
8537/**
8538 * @param opt_a
8539 * @param opt_b
8540 */
8541function a () {}
8542// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"FunctionDeclaration","message":"Only allowing names not matching `/^opt_/i`."}]}]
8543// Message: Only allowing names not matching `/^opt_/i`.
8544
8545/**
8546 * @param opt_a
8547 * @param opt_b
8548 */
8549function a () {}
8550// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
8551// Message: Only allowing names not matching `/^opt_/i`.
8552
8553/**
8554 * @param opt_a
8555 * @param opt_b
8556 */
8557function a () {}
8558// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/not-this/])","context":"any","message":"Only allowing names not matching `/^not-this/i`."},{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
8559// Message: Only allowing names not matching `/^opt_/i`.
8560
8561/**
8562 * @param opt_a
8563 * @param opt_b
8564 */
8565// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
8566// Message: Only allowing names not matching `/^opt_/i`.
8567````
8568
8569The following patterns are not considered problems:
8570
8571````js
8572/**
8573 *
8574 */
8575function quux () {
8576
8577}
8578// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":["FunctionExpression"]}]
8579
8580/**
8581 * @implements {Bar|Foo}
8582 */
8583function quux () {
8584
8585}
8586// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Foo\"]:nth-child(1))","context":"FunctionDeclaration"}]}]
8587
8588/**
8589 * @param ab
8590 * @param cd
8591 */
8592function a () {}
8593// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
8594
8595/**
8596 * @param ab
8597 * @param cd
8598 */
8599// "jsdoc/no-restricted-syntax": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock:has(JsdocTag[name=/opt_/])","context":"any","message":"Only allowing names not matching `/^opt_/i`."}]}]
8600````
8601
8602
8603<a name="eslint-plugin-jsdoc-rules-no-types"></a>
8604### <code>no-types</code>
8605
8606This rule reports types being used on `@param` or `@returns`.
8607
8608The rule is intended to prevent the indication of types on tags where
8609the type information would be redundant with TypeScript.
8610
8611<a name="eslint-plugin-jsdoc-rules-no-types-options-19"></a>
8612#### Options
8613
8614<a name="eslint-plugin-jsdoc-rules-no-types-options-19-contexts-5"></a>
8615##### <code>contexts</code>
8616
8617Set this to an array of strings representing the AST context (or an object with
8618`context` and `comment` properties) where you wish the rule to be applied.
8619Overrides the default contexts (see below). Set to `"any"` if you want
8620the rule to apply to any jsdoc block throughout your files (as is necessary
8621for finding function blocks not attached to a function declaration or
8622expression, i.e., `@callback` or `@function` (or its aliases `@func` or
8623`@method`) (including those associated with an `@interface`).
8624
8625See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
8626section of our README for more on the expected format.
8627
8628|||
8629|---|---|
8630|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8631|Tags|`param`, `returns`|
8632|Aliases|`arg`, `argument`, `return`|
8633|Recommended|false|
8634|Options|`contexts`|
8635
8636The following patterns are considered problems:
8637
8638````js
8639/**
8640 * @param {number} foo
8641 */
8642function quux (foo) {
8643
8644}
8645// Message: Types are not permitted on @param.
8646
8647class quux {
8648 /**
8649 * @param {number} foo
8650 */
8651 bar (foo) {
8652
8653 }
8654}
8655// Message: Types are not permitted on @param.
8656
8657/**
8658 * @param {number} foo
8659 */
8660function quux (foo) {
8661
8662}
8663// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
8664// Message: Types are not permitted on @param.
8665
8666class quux {
8667 /**
8668 * @param {number} foo
8669 */
8670 quux (foo) {
8671
8672 }
8673}
8674// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
8675// Message: Types are not permitted on @param.
8676
8677/**
8678 * @function
8679 * @param {number} foo
8680 */
8681// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
8682// Message: Types are not permitted on @param.
8683
8684/**
8685 * @callback
8686 * @param {number} foo
8687 */
8688// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
8689// Message: Types are not permitted on @param.
8690
8691/**
8692 * @returns {number}
8693 */
8694function quux () {
8695
8696}
8697// Message: Types are not permitted on @returns.
8698
8699/**
8700 * Beep
8701 * Boop
8702 *
8703 * @returns {number}
8704 */
8705function quux () {
8706
8707}
8708// Message: Types are not permitted on @returns.
8709````
8710
8711The following patterns are not considered problems:
8712
8713````js
8714/**
8715 * @param foo
8716 */
8717function quux (foo) {
8718
8719}
8720
8721/**
8722 * @param foo
8723 */
8724// "jsdoc/no-types": ["error"|"warn", {"contexts":["any"]}]
8725
8726/**
8727 * @function
8728 * @param {number} foo
8729 */
8730
8731/**
8732 * @callback
8733 * @param {number} foo
8734 */
8735````
8736
8737
8738<a name="eslint-plugin-jsdoc-rules-no-undefined-types"></a>
8739### <code>no-undefined-types</code>
8740
8741Checks that types in jsdoc comments are defined. This can be used to check
8742unimported types.
8743
8744When enabling this rule, types in jsdoc comments will resolve as used
8745variables, i.e. will not be marked as unused by `no-unused-vars`.
8746
8747In addition to considering globals found in code (or in ESLint-indicated
8748`globals`) as defined, the following tags will also be checked for
8749name(path) definitions to also serve as a potential "type" for checking
8750the tag types in the table below:
8751
8752`@callback`, `@class` (or `@constructor`), `@constant` (or `@const`),
8753`@event`, `@external` (or `@host`), `@function` (or `@func` or `@method`),
8754`@interface`, `@member` (or `@var`), `@mixin`, `@name`, `@namespace`,
8755`@template` (for "closure" or "typescript" `settings.jsdoc.mode` only),
8756`@typedef`.
8757
8758The following tags will also be checked but only when the mode is `closure`:
8759
8760`@package`, `@private`, `@protected`, `@public`, `@static`
8761
8762The following types are always considered defined.
8763
8764- `null`, `undefined`, `void`, `string`, `boolean`, `object`,
8765 `function`, `symbol`
8766- `number`, `bigint`, `NaN`, `Infinity`
8767- `any`, `*`
8768- `this`, `true`, `false`
8769- `Array`, `Object`, `RegExp`, `Date`, `Function`
8770
8771Note that preferred types indicated within `settings.jsdoc.preferredTypes` will
8772also be assumed to be defined.
8773
8774Also note that if there is an error [parsing](https://github.com/jsdoctypeparser/jsdoctypeparser)
8775types for a tag, the function will silently ignore that tag, leaving it to
8776the `valid-types` rule to report parsing errors.
8777
8778If you define your own tags, you can use `settings.jsdoc.structuredTags`
8779to indicate that a tag's `name` is "namepath-defining" (and should prevent
8780reporting on use of that namepath elsewhere) and/or that a tag's `type` is
8781`false` (and should not be checked for types). If the `type` is an array, that
8782array's items will be considered as defined for the purposes of that tag.
8783
8784<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-20"></a>
8785#### Options
8786
8787An option object may have the following key:
8788
8789- `definedTypes` - This array can be populated to indicate other types which
8790 are automatically considered as defined (in addition to globals, etc.).
8791 Defaults to an empty array.
8792
8793|||
8794|---|---|
8795|Context|everywhere|
8796|Tags|`augments`, `class`, `constant`, `enum`, `implements`, `member`, `module`, `namespace`, `param`, `property`, `returns`, `throws`, `type`, `typedef`, `yields`|
8797|Aliases|`constructor`, `const`, `extends`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
8798|Closure-only|`package`, `private`, `protected`, `public`, `static`|
8799|Recommended|true|
8800|Options|`definedTypes`|
8801|Settings|`preferredTypes`, `mode`, `structuredTags`|
8802
8803The following patterns are considered problems:
8804
8805````js
8806/**
8807 * @param {HerType} baz - Foo.
8808 */
8809function quux(foo, bar, baz) {
8810
8811}
8812// Settings: {"jsdoc":{"preferredTypes":{"HerType":1000}}}
8813// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
8814
8815/**
8816 * @param {HerType} baz - Foo.
8817 */
8818function quux(foo, bar, baz) {
8819
8820}
8821// Settings: {"jsdoc":{"preferredTypes":{"HerType":false}}}
8822// Message: The type 'HerType' is undefined.
8823
8824/**
8825 * @param {strnig} foo - Bar.
8826 */
8827function quux(foo) {
8828
8829}
8830// Message: The type 'strnig' is undefined.
8831
8832/**
8833 * @param {MyType} foo - Bar.
8834 * @param {HisType} bar - Foo.
8835 */
8836function quux(foo, bar) {
8837
8838}
8839// "jsdoc/no-undefined-types": ["error"|"warn", {"definedTypes":["MyType"]}]
8840// Message: The type 'HisType' is undefined.
8841
8842/**
8843 * @param {MyType} foo - Bar.
8844 * @param {HisType} bar - Foo.
8845 * @param {HerType} baz - Foo.
8846 */
8847function quux(foo, bar, baz) {
8848
8849}
8850// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"}}}}
8851// "jsdoc/no-undefined-types": ["error"|"warn", {"definedTypes":["MyType"]}]
8852// Message: The type 'HisType' is undefined.
8853
8854 /**
8855 * @param {MyType} foo - Bar.
8856 * @param {HisType} bar - Foo.
8857 * @param {HerType} baz - Foo.
8858 */
8859function quux(foo, bar, baz) {
8860
8861}
8862// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":false},"histype":"HisType"}}}
8863// "jsdoc/no-undefined-types": ["error"|"warn", {"definedTypes":["MyType"]}]
8864// Message: The type 'HerType' is undefined.
8865
8866/**
8867 * @template TEMPLATE_TYPE
8868 * @param {WRONG_TEMPLATE_TYPE} bar
8869 */
8870function foo (bar) {
8871};
8872// Settings: {"jsdoc":{"mode":"closure"}}
8873// Message: The type 'WRONG_TEMPLATE_TYPE' is undefined.
8874
8875class Foo {
8876 /**
8877 * @return {TEMPLATE_TYPE}
8878 */
8879 bar () {
8880 }
8881}
8882// Message: The type 'TEMPLATE_TYPE' is undefined.
8883
8884class Foo {
8885 /**
8886 * @return {TEMPLATE_TYPE}
8887 */
8888 invalidTemplateReference () {
8889 }
8890}
8891
8892/**
8893 * @template TEMPLATE_TYPE
8894 */
8895class Bar {
8896 /**
8897 * @return {TEMPLATE_TYPE}
8898 */
8899 validTemplateReference () {
8900 }
8901}
8902// Settings: {"jsdoc":{"mode":"typescript"}}
8903// Message: The type 'TEMPLATE_TYPE' is undefined.
8904
8905/**
8906 * @type {strnig}
8907 */
8908var quux = {
8909
8910};
8911// Message: The type 'strnig' is undefined.
8912
8913/**
8914 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
8915 */
8916class Foo {
8917 /**
8918 * @param {TEMPLATE_TYPE_A} baz
8919 * @return {TEMPLATE_TYPE_B}
8920 */
8921 bar (baz) {
8922 }
8923}
8924// Message: The type 'TEMPLATE_TYPE_A' is undefined.
8925
8926/**
8927 * @param {...VAR_TYPE} varargs
8928 */
8929function quux (varargs) {
8930}
8931// Message: The type 'VAR_TYPE' is undefined.
8932
8933/**
8934 * @this {Navigator}
8935 */
8936function quux () {}
8937// Settings: {"jsdoc":{"mode":"closure"}}
8938// Message: The type 'Navigator' is undefined.
8939
8940/**
8941 * @export {SomeType}
8942 */
8943function quux () {}
8944// Settings: {"jsdoc":{"mode":"closure"}}
8945// Message: The type 'SomeType' is undefined.
8946
8947/**
8948 * @aCustomTag {SomeType}
8949 */
8950function quux () {}
8951// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":true}}}}
8952// Message: The type 'SomeType' is undefined.
8953
8954/**
8955 * @aCustomTag {SomeType}
8956 */
8957function quux () {}
8958// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["aType","anotherType"]}}}}
8959// Message: The type 'SomeType' is undefined.
8960
8961/**
8962 * @namepathDefiner SomeType
8963 */
8964/**
8965 * @type {SomeType}
8966 */
8967// Settings: {"jsdoc":{"structuredTags":{"namepathDefiner":{"name":"namepath-referencing"}}}}
8968// Message: The type 'SomeType' is undefined.
8969
8970/**
8971 * @namepathDefiner SomeType
8972 */
8973/**
8974 * @type {SomeType}
8975 */
8976// Message: The type 'SomeType' is undefined.
8977
8978/**
8979 * @template abc TEMPLATE_TYPE
8980 * @param {TEMPLATE_TYPE} bar
8981 */
8982function foo (bar) {
8983};
8984// Settings: {"jsdoc":{"mode":"closure"}}
8985// Message: The type 'TEMPLATE_TYPE' is undefined.
8986````
8987
8988The following patterns are not considered problems:
8989
8990````js
8991/**
8992 * @param {string} foo - Bar.
8993 */
8994function quux(foo) {
8995
8996}
8997
8998/**
8999 * @param {Promise} foo - Bar.
9000 */
9001function quux(foo) {
9002
9003}
9004
9005class MyClass {}
9006
9007/**
9008 * @param {MyClass} foo - Bar.
9009 */
9010function quux(foo) {
9011 console.log(foo);
9012}
9013
9014quux(0);
9015
9016const MyType = require('my-library').MyType;
9017
9018/**
9019 * @param {MyType} foo - Bar.
9020 */
9021 function quux(foo) {
9022
9023}
9024
9025const MyType = require('my-library').MyType;
9026
9027/**
9028 * @param {MyType} foo - Bar.
9029 */
9030 function quux(foo) {
9031
9032}
9033
9034const MyType = require('my-library').MyType;
9035
9036/**
9037 * @param {MyType} foo - Bar.
9038 */
9039 function quux(foo) {
9040
9041}
9042
9043import {MyType} from 'my-library';
9044
9045/**
9046 * @param {MyType} foo - Bar.
9047 * @param {object<string, number>} foo
9048 * @param {Array<string>} baz
9049 */
9050 function quux(foo, bar, baz) {
9051
9052}
9053
9054/*globals MyType*/
9055
9056/**
9057 * @param {MyType} foo - Bar.
9058 * @param {HisType} bar - Foo.
9059 */
9060 function quux(foo, bar) {
9061
9062}
9063
9064/**
9065 * @typedef {object} hello
9066 * @property {string} a - a.
9067 */
9068
9069/**
9070 * @param {hello} foo
9071 */
9072function quux(foo) {
9073
9074}
9075
9076/**
9077 * @param {Array<syntaxError} foo
9078 */
9079function quux(foo) {
9080
9081}
9082
9083/**
9084 * Callback test.
9085 *
9086 * @callback addStuffCallback
9087 * @param {String} sum - An test integer.
9088 */
9089/**
9090 * Test Eslint.
9091 *
9092 * @param {addStuffCallback} callback - A callback to run.
9093 */
9094function testFunction(callback) {
9095 callback();
9096}
9097
9098/**
9099 *
9100 *
9101 */
9102function foo () {
9103
9104}
9105
9106/**
9107 *
9108 *
9109 */
9110function foo () {
9111
9112}
9113
9114/**
9115 * @param {MyType} foo - Bar.
9116 * @param {HisType} bar - Foo.
9117 */
9118function quux(foo, bar) {
9119
9120}
9121// "jsdoc/no-undefined-types": ["error"|"warn", {"definedTypes":["MyType","HisType"]}]
9122
9123/**
9124 * @param {MyType} foo - Bar.
9125 * @param {HisType} bar - Foo.
9126 * @param {HerType} baz - Foo.
9127 */
9128function quux(foo, bar, baz) {
9129
9130}
9131// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"},"histype":"HisType"}}}
9132// "jsdoc/no-undefined-types": ["error"|"warn", {"definedTypes":["MyType"]}]
9133
9134/**
9135 * @param {MyType} foo - Bar.
9136 * @param {HisType} bar - Foo.
9137 * @param {HerType} baz - Foo.
9138 */
9139function quux(foo, bar, baz) {
9140
9141}
9142// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType<>"},"histype":"HisType.<>"}}}
9143// "jsdoc/no-undefined-types": ["error"|"warn", {"definedTypes":["MyType"]}]
9144
9145/**
9146 * @template TEMPLATE_TYPE
9147 * @param {TEMPLATE_TYPE} bar
9148 * @return {TEMPLATE_TYPE}
9149 */
9150function foo (bar) {
9151};
9152// Settings: {"jsdoc":{"mode":"closure"}}
9153
9154/**
9155 * @template TEMPLATE_TYPE
9156 */
9157class Foo {
9158 /**
9159 * @return {TEMPLATE_TYPE}
9160 */
9161 bar () {
9162 }
9163}
9164// Settings: {"jsdoc":{"mode":"closure"}}
9165
9166/**
9167 * @template TEMPLATE_TYPE
9168 */
9169class Foo {
9170 /**
9171 * @return {TEMPLATE_TYPE}
9172 */
9173 bar () {}
9174
9175 /**
9176 * @return {TEMPLATE_TYPE}
9177 */
9178 baz () {}
9179}
9180// Settings: {"jsdoc":{"mode":"closure"}}
9181
9182/**
9183 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
9184 */
9185class Foo {
9186 /**
9187 * @param {TEMPLATE_TYPE_A} baz
9188 * @return {TEMPLATE_TYPE_B}
9189 */
9190 bar (baz) {
9191 }
9192}
9193// Settings: {"jsdoc":{"mode":"closure"}}
9194
9195/**
9196 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B - Some description
9197 */
9198class Foo {
9199 /**
9200 * @param {TEMPLATE_TYPE_A} baz
9201 * @return {TEMPLATE_TYPE_B}
9202 */
9203 bar (baz) {
9204 }
9205}
9206// Settings: {"jsdoc":{"mode":"closure"}}
9207
9208/****/
9209
9210/**
9211 *
9212 */
9213function quux () {
9214
9215}
9216
9217/**
9218 * @typedef {object} BaseObject
9219 */
9220/**
9221 * Run callback when hooked method is called.
9222 *
9223 * @template {BaseObject} T
9224 * @param {T} obj - object whose method should be hooked.
9225 * @param {string} method - method which should be hooked.
9226 * @param {(sender: T) => void} callback - callback which should
9227 * be called when the hooked method was invoked.
9228 */
9229function registerEvent(obj, method, callback) {
9230
9231}
9232// Settings: {"jsdoc":{"mode":"typescript"}}
9233
9234 /**
9235 * @param {...} varargs
9236 */
9237function quux (varargs) {
9238}
9239
9240/**
9241 * @param {...number} varargs
9242 */
9243function quux (varargs) {
9244}
9245
9246class Navigator {}
9247/**
9248 * @this {Navigator}
9249 */
9250function quux () {}
9251// Settings: {"jsdoc":{"mode":"closure"}}
9252
9253class SomeType {}
9254/**
9255 * @export {SomeType}
9256 */
9257function quux () {}
9258// Settings: {"jsdoc":{"mode":"closure"}}
9259
9260/**
9261 * @template T
9262 * @param {T} arg
9263 */
9264function example(arg) {
9265
9266 /** @param {T} */
9267 function inner(x) {
9268 }
9269}
9270// Settings: {"jsdoc":{"mode":"closure"}}
9271
9272const init = () => {
9273 /**
9274 * Makes request
9275 * @returns {Promise}
9276 */
9277 function request() {
9278 return Promise.resolve('success');
9279 }
9280};
9281
9282/** Gets a Promise resolved with a given value.
9283 *
9284 * @template ValueType
9285 * @param {ValueType} value Value to resolve.
9286 * @returns {Promise<ValueType>} Promise resolved with value.
9287 */
9288exports.resolve1 = function resolve1(value) {
9289 return Promise.resolve(value);
9290};
9291// Settings: {"jsdoc":{"mode":"typescript"}}
9292
9293/**
9294 * A function returning the same type as its argument.
9295 *
9296 * @template ValueType
9297 * @typedef {ValueType} ValueFunc
9298 */
9299// Settings: {"jsdoc":{"mode":"typescript"}}
9300
9301/**
9302 * @aCustomTag {SomeType}
9303 */
9304function quux () {}
9305// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":false}}}}
9306
9307/**
9308 * @aCustomTag {SomeType}
9309 */
9310function quux () {}
9311// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":["aType","SomeType"]}}}}
9312
9313/**
9314 * @namepathDefiner SomeType
9315 */
9316/**
9317 * @type {SomeType}
9318 */
9319// Settings: {"jsdoc":{"structuredTags":{"namepathDefiner":{"name":"namepath-defining"}}}}
9320
9321class Test {
9322 /**
9323 * Method.
9324 *
9325 * @returns {this} Return description.
9326 */
9327 method (): this {
9328 return this;
9329 }
9330}
9331
9332/**
9333 * Bad types ignored here and handled instead by `valid-types`.
9334 * @param {string(} foo - Bar.
9335 */
9336function quux(foo) {
9337
9338}
9339````
9340
9341
9342<a name="eslint-plugin-jsdoc-rules-require-asterisk-prefix"></a>
9343### <code>require-asterisk-prefix</code>
9344
9345Requires that each JSDoc line starts with an `*`.
9346
9347<a name="eslint-plugin-jsdoc-rules-require-asterisk-prefix-options-21"></a>
9348#### Options
9349
9350This rule allows an optional string argument. If it is `"always"` then a
9351problem is raised when there is no asterisk prefix on a given jsdoc line. If
9352it is `"never"` then a problem is raised when there is an asterisk present.
9353The default value is `"always"`. You may also set the default to `"any"`
9354and use the `tags` option to apply to specific tags only.
9355
9356After the string option, one may add an object with the following.
9357
9358<a name="eslint-plugin-jsdoc-rules-require-asterisk-prefix-options-21-tags-3"></a>
9359##### <code>tags</code>
9360
9361If you want different values to apply to specific tags, you may use
9362the `tags` option object. The keys are `always`, `never`, or `any` and
9363the values are arrays of tag names or the special value `*description`
9364which applies to the main jsdoc block description.
9365
9366```js
9367{
9368 'jsdoc/require-asterisk-prefix': ['error', 'always', {
9369 tags: {
9370 always: ['*description'],
9371 any: ['example', 'license'],
9372 never: ['copyright']
9373 }
9374 }]
9375}
9376```
9377
9378|||
9379|---|---|
9380|Context|everywhere|
9381|Tags|All or as limited by the `tags` option|
9382|Options|(a string matching `"always"|"never"` and optional object with `tags`)|
9383
9384The following patterns are considered problems:
9385
9386````js
9387
9388/**
9389 @param {Number} foo
9390 */
9391function quux (foo) {
9392 // with spaces
9393}
9394// Message: Expected JSDoc line to have the prefix.
9395
9396
9397/**
9398 @param {Number} foo
9399 */
9400function quux (foo) {
9401 // with spaces
9402}
9403// "jsdoc/require-asterisk-prefix": ["error"|"warn", "any",{"tags":{"always":["param"]}}]
9404// Message: Expected JSDoc line to have the prefix.
9405
9406
9407/**
9408 * Desc
9409
9410 */
9411function quux (foo) {
9412 // with spaces
9413}
9414// Message: Expected JSDoc line to have the prefix.
9415
9416
9417/**
9418 *
9419 Desc
9420 */
9421function quux (foo) {
9422 // with spaces
9423}
9424// Message: Expected JSDoc line to have the prefix.
9425
9426
9427/**
9428 * Desc
9429 *
9430 */
9431function quux (foo) {
9432 // with spaces
9433}
9434// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never"]
9435// Message: Expected JSDoc line to have no prefix.
9436
9437
9438/**
9439 @param {Number} foo
9440 */
9441function quux (foo) {
9442 // with spaces
9443}
9444// "jsdoc/require-asterisk-prefix": ["error"|"warn", "always",{"tags":{"any":["someOtherTag"]}}]
9445// Message: Expected JSDoc line to have the prefix.
9446
9447
9448/**
9449 * @param {Number} foo
9450 */
9451function quux (foo) {
9452 // with spaces
9453}
9454// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never",{"tags":{"always":["someOtherTag"]}}]
9455// Message: Expected JSDoc line to have no prefix.
9456
9457
9458/**
9459 * @param {Number} foo
9460 */
9461function quux (foo) {
9462 // with spaces
9463}
9464// "jsdoc/require-asterisk-prefix": ["error"|"warn", "always",{"tags":{"never":["param"]}}]
9465// Message: Expected JSDoc line to have no prefix.
9466
9467
9468/**
9469 @param {Number} foo
9470 */
9471function quux (foo) {
9472 // with spaces
9473}
9474// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never",{"tags":{"always":["param"]}}]
9475// Message: Expected JSDoc line to have the prefix.
9476
9477/**
9478 @param {Number} foo
9479 */function quux (foo) {
9480 // with spaces
9481}
9482// Message: Expected JSDoc line to have the prefix.
9483
9484
9485/**
9486 * @param {Number} foo
9487 */
9488function quux (foo) {
9489 // with spaces
9490}
9491// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never"]
9492// Message: Expected JSDoc line to have no prefix.
9493
9494/**
9495 *@param {Number} foo
9496 */function quux (foo) {
9497 // with spaces
9498}
9499// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never"]
9500// Message: Expected JSDoc line to have no prefix.
9501````
9502
9503The following patterns are not considered problems:
9504
9505````js
9506/**
9507 * Desc
9508 *
9509 * @param {Number} foo
9510 * This is more comment.
9511 */
9512function quux (foo) {
9513
9514}
9515
9516/**
9517 * Desc
9518 *
9519 * @param {{
9520 * foo: Bar,
9521 * bar: Baz
9522 * }} foo
9523 *
9524 */
9525function quux (foo) {
9526
9527}
9528
9529/* <- JSDoc must start with 2 stars.
9530 So this is unchecked.
9531 */
9532function quux (foo) {}
9533
9534/** @param {Number} foo */
9535function quux (foo) {
9536 // with spaces
9537}
9538
9539
9540/**
9541 @param {Number} foo
9542 */
9543function quux (foo) {
9544 // with spaces
9545}
9546// "jsdoc/require-asterisk-prefix": ["error"|"warn", "always",{"tags":{"any":["param"]}}]
9547
9548
9549/**
9550 * @param {Number} foo
9551 */
9552function quux (foo) {
9553 // with spaces
9554}
9555// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never",{"tags":{"always":["param"]}}]
9556
9557
9558/**
9559 * @param {Number} foo
9560 */
9561function quux (foo) {
9562 // with spaces
9563}
9564// "jsdoc/require-asterisk-prefix": ["error"|"warn", "always",{"tags":{"never":["someOtherTag"]}}]
9565
9566
9567/**
9568 @param {Number} foo
9569 */
9570function quux (foo) {
9571 // with spaces
9572}
9573// "jsdoc/require-asterisk-prefix": ["error"|"warn", "always",{"tags":{"never":["param"]}}]
9574
9575
9576/**
9577 @param {Number} foo
9578 */
9579function quux (foo) {
9580 // with spaces
9581}
9582// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never",{"tags":{"always":["someOtherTag"]}}]
9583
9584
9585/**
9586 * Desc
9587 *
9588 */
9589function quux (foo) {
9590 // with spaces
9591}
9592// "jsdoc/require-asterisk-prefix": ["error"|"warn", "never",{"tags":{"any":["*description"]}}]
9593
9594
9595/**
9596 * Desc
9597
9598 */
9599function quux (foo) {
9600 // with spaces
9601}
9602// "jsdoc/require-asterisk-prefix": ["error"|"warn", "always",{"tags":{"any":["*description"]}}]
9603
9604
9605/**
9606 @param {Number} foo
9607 */
9608function quux (foo) {
9609 // with spaces
9610}
9611// "jsdoc/require-asterisk-prefix": ["error"|"warn", "any",{"tags":{"always":["someOtherTag"]}}]
9612````
9613
9614
9615<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence"></a>
9616### <code>require-description-complete-sentence</code>
9617
9618Requires that block description, explicit `@description`, and
9619`@param`/`@returns` tag descriptions are written in complete sentences, i.e.,
9620
9621* Description must start with an uppercase alphabetical character.
9622* Paragraphs must start with an uppercase alphabetical character.
9623* Sentences must end with a period.
9624* Every line in a paragraph (except the first) which starts with an uppercase
9625 character must be preceded by a line ending with a period.
9626* A colon or semi-colon followed by two line breaks is still part of the
9627 containing paragraph (unlike normal dual line breaks).
9628* Text within inline tags `{...}` are not checked for sentence divisions.
9629* Periods after items within the `abbreviations` option array are not treated
9630 as sentence endings.
9631
9632<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-22"></a>
9633#### Options
9634
9635<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-22-tags-4"></a>
9636##### <code>tags</code>
9637
9638If you want additional tags to be checked for their descriptions, you may
9639add them within this option.
9640
9641```js
9642{
9643 'jsdoc/require-description-complete-sentence': ['error', {
9644 tags: ['see', 'copyright']
9645 }]
9646}
9647```
9648
9649The tags `@param`/`@arg`/`@argument` and `@property`/`@prop` will be properly
9650parsed to ensure that the checked "description" text includes only the text
9651after the name.
9652
9653All other tags will treat the text following the tag name, a space, and
9654an optional curly-bracketed type expression (and another space) as part of
9655its "description" (e.g., for `@returns {someType} some description`, the
9656description is `some description` while for `@some-tag xyz`, the description
9657is `xyz`).
9658
9659<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-22-abbreviations"></a>
9660##### <code>abbreviations</code>
9661
9662You can provide an `abbreviations` options array to avoid such strings of text
9663being treated as sentence endings when followed by dots. The `.` is not
9664necessary at the end of the array items.
9665
9666<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-22-newlinebeforecapsassumesbadsentenceend"></a>
9667##### <code>newlineBeforeCapsAssumesBadSentenceEnd</code>
9668
9669When `false` (the new default), we will not assume capital letters after
9670newlines are an incorrect way to end the sentence (they may be proper
9671nouns, for example).
9672
9673|||
9674|---|---|
9675|Context|everywhere|
9676|Tags|doc block, `param`, `returns`, `description`, `property`, `summary`, `file`, `classdesc`, `todo`, `deprecated`, `throws`, 'yields' and others added by `tags`|
9677|Aliases|`arg`, `argument`, `return`, `desc`, `prop`, `fileoverview`, `overview`, `exception`, `yield`|
9678|Recommended|false|
9679|Options|`tags`, `abbreviations`, `newlineBeforeCapsAssumesBadSentenceEnd`|
9680The following patterns are considered problems:
9681
9682````js
9683/**
9684 * foo.
9685 */
9686function quux () {
9687
9688}
9689// Message: Sentence should start with an uppercase character.
9690
9691/**
9692 * foo?
9693 */
9694function quux () {
9695
9696}
9697// Message: Sentence should start with an uppercase character.
9698
9699/**
9700 * @description foo.
9701 */
9702function quux () {
9703
9704}
9705// Message: Sentence should start with an uppercase character.
9706
9707/**
9708 * Foo)
9709 */
9710function quux () {
9711
9712}
9713// Message: Sentence must end with a period.
9714
9715/**
9716 * `foo` is a variable
9717 */
9718function quux () {
9719
9720}
9721// Message: Sentence must end with a period.
9722
9723/**
9724 * Foo.
9725 *
9726 * foo.
9727 */
9728function quux () {
9729
9730}
9731// Message: Sentence should start with an uppercase character.
9732
9733/**
9734 * тест.
9735 */
9736function quux () {
9737
9738}
9739// Message: Sentence should start with an uppercase character.
9740
9741/**
9742 * Foo
9743 */
9744function quux () {
9745
9746}
9747// Message: Sentence must end with a period.
9748
9749/**
9750 * Foo
9751 * Bar.
9752 */
9753function quux () {
9754
9755}
9756// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"newlineBeforeCapsAssumesBadSentenceEnd":true}]
9757// Message: A line of text is started with an uppercase character, but preceding line does not end the sentence.
9758
9759/**
9760 * Foo.
9761 *
9762 * @param foo foo.
9763 */
9764function quux (foo) {
9765
9766}
9767// Message: Sentence should start with an uppercase character.
9768
9769/**
9770 * Foo.
9771 *
9772 * @param foo bar
9773 */
9774function quux (foo) {
9775
9776}
9777// Message: Sentence should start with an uppercase character.
9778
9779/**
9780 * {@see Foo.bar} buz
9781 */
9782function quux (foo) {
9783
9784}
9785// Message: Sentence should start with an uppercase character.
9786
9787/**
9788 * Foo.
9789 *
9790 * @returns {number} foo
9791 */
9792function quux (foo) {
9793
9794}
9795// Message: Sentence should start with an uppercase character.
9796
9797/**
9798 * Foo.
9799 *
9800 * @returns foo.
9801 */
9802function quux (foo) {
9803
9804}
9805// Message: Sentence should start with an uppercase character.
9806
9807/**
9808 * lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
9809 * iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
9810 * tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
9811 * vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
9812 * proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
9813 * consequat auctor magna. duis pharetra purus in porttitor mollis.
9814 */
9815function longDescription (foo) {
9816
9817}
9818// Message: Sentence should start with an uppercase character.
9819
9820/**
9821 * @arg {number} foo - Foo
9822 */
9823function quux (foo) {
9824
9825}
9826// Message: Sentence must end with a period.
9827
9828/**
9829 * @argument {number} foo - Foo
9830 */
9831function quux (foo) {
9832
9833}
9834// Message: Sentence must end with a period.
9835
9836/**
9837 * @return {number} foo
9838 */
9839function quux (foo) {
9840
9841}
9842// Message: Sentence should start with an uppercase character.
9843
9844/**
9845 * Returns bar.
9846 *
9847 * @return {number} bar
9848 */
9849function quux (foo) {
9850
9851}
9852// Message: Sentence should start with an uppercase character.
9853
9854/**
9855 * @throws {object} Hello World
9856 * hello world
9857*/
9858// Message: Sentence must end with a period.
9859
9860/**
9861 * @summary Foo
9862 */
9863function quux () {
9864
9865}
9866// Message: Sentence must end with a period.
9867
9868/**
9869 * @throws {SomeType} Foo
9870 */
9871function quux () {
9872
9873}
9874// Message: Sentence must end with a period.
9875
9876/**
9877 * @see Foo
9878 */
9879function quux () {
9880
9881}
9882// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["see"]}]
9883// Message: Sentence must end with a period.
9884
9885/**
9886 * @param foo Foo bar
9887 */
9888function quux (foo) {
9889
9890}
9891// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
9892// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["param"]}]
9893// Message: Sentence must end with a period.
9894
9895/**
9896 * Sorry, but this isn't a complete sentence, Mr.
9897 */
9898function quux () {
9899
9900}
9901// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr"]}]
9902// Message: Sentence must end with a period.
9903
9904/**
9905 * Sorry, but this isn't a complete sentence Mr.
9906 */
9907function quux () {
9908
9909}
9910// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr."]}]
9911// Message: Sentence must end with a period.
9912
9913/**
9914 * Sorry, but this isn't a complete sentence Mr.
9915 */
9916function quux () {
9917
9918}
9919// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr"]}]
9920// Message: Sentence must end with a period.
9921
9922/**
9923 * Sorry, but this isn't a complete sentence Mr. and Mrs.
9924 */
9925function quux () {
9926
9927}
9928// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr","Mrs"]}]
9929// Message: Sentence must end with a period.
9930
9931/**
9932 * This is a complete sentence. But this isn't, Mr.
9933 */
9934function quux () {
9935
9936}
9937// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr"]}]
9938// Message: Sentence must end with a period.
9939
9940/**
9941 * This is a complete Mr. sentence. But this isn't, Mr.
9942 */
9943function quux () {
9944
9945}
9946// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr"]}]
9947// Message: Sentence must end with a period.
9948
9949/**
9950 * This is a complete Mr. sentence.
9951 */
9952function quux () {
9953
9954}
9955// Message: Sentence should start with an uppercase character.
9956
9957/**
9958 * This is fun, i.e. enjoyable, but not superlatively so, e.g. not
9959 * super, wonderful, etc..
9960 */
9961function quux () {
9962
9963}
9964// Message: Sentence should start with an uppercase character.
9965
9966/**
9967 * Do not have dynamic content; e.g. homepage. Here a simple unique id
9968 * suffices.
9969 */
9970 function quux () {
9971
9972 }
9973// Message: Sentence should start with an uppercase character.
9974
9975/**
9976 * Implements support for the
9977 * Swahili voice synthesizer.
9978 */
9979function speak() {
9980}
9981// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"newlineBeforeCapsAssumesBadSentenceEnd":true}]
9982// Message: A line of text is started with an uppercase character, but preceding line does not end the sentence.
9983
9984/**
9985 * Foo.
9986 *
9987 * @template TempA, TempB foo.
9988 */
9989function quux (foo) {
9990
9991}
9992// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["template"]}]
9993// Message: Sentence should start with an uppercase character.
9994````
9995
9996The following patterns are not considered problems:
9997
9998````js
9999/**
10000 * @param foo - Foo.
10001 */
10002function quux () {
10003
10004}
10005
10006/**
10007 * Foo.
10008 */
10009function quux () {
10010
10011}
10012
10013/**
10014 * Foo.
10015 * Bar.
10016 */
10017function quux () {
10018
10019}
10020
10021/**
10022 * Foo.
10023 *
10024 * Bar.
10025 */
10026function quux () {
10027
10028}
10029
10030/**
10031 * Тест.
10032 */
10033function quux () {
10034
10035}
10036
10037/**
10038 * Foo
10039 * bar.
10040 */
10041function quux () {
10042
10043}
10044
10045/**
10046 * @returns Foo bar.
10047 */
10048function quux () {
10049
10050}
10051
10052/**
10053 * Foo. {@see Math.sin}.
10054 */
10055function quux () {
10056
10057}
10058
10059/**
10060 * Foo {@see Math.sin} bar.
10061 */
10062function quux () {
10063
10064}
10065
10066/**
10067 * Foo?
10068 *
10069 * Bar!
10070 *
10071 * Baz:
10072 * 1. Foo.
10073 * 2. Bar.
10074 */
10075function quux () {
10076
10077}
10078
10079/**
10080 * Hello:
10081 * World.
10082 */
10083function quux () {
10084
10085}
10086
10087/**
10088 * Hello: world.
10089 */
10090function quux () {
10091
10092}
10093
10094/**
10095 *
10096 */
10097function quux () {
10098
10099}
10100
10101/**
10102 * @description Foo.
10103 */
10104function quux () {
10105
10106}
10107
10108/**
10109 * `foo` is a variable.
10110 */
10111function quux () {
10112
10113}
10114
10115/**
10116 * Foo.
10117 *
10118 * `foo`.
10119 */
10120function quux () {
10121
10122}
10123
10124/**
10125 * @param foo - `bar`.
10126 */
10127function quux () {
10128
10129}
10130
10131/**
10132 * @returns {number} `foo`.
10133 */
10134function quux () {
10135
10136}
10137
10138/**
10139 * Foo
10140 * `bar`.
10141 */
10142function quux () {
10143
10144}
10145
10146/**
10147 * @example Foo
10148 */
10149function quux () {
10150
10151}
10152
10153/**
10154 * @see Foo
10155 */
10156function quux () {
10157
10158}
10159
10160/**
10161 * Foo.
10162 *
10163 * @param foo Foo.
10164 */
10165function quux (foo) {
10166
10167}
10168
10169/**
10170 * Foo.
10171 *
10172 * @param foo Foo.
10173 */
10174function quux (foo) {
10175
10176}
10177// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["param"]}]
10178
10179/**
10180 * @param foo Foo bar.
10181 */
10182function quux (foo) {
10183
10184}
10185// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
10186// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"tags":["param"]}]
10187
10188/**
10189 *
10190 */
10191function quux (foo) {
10192
10193}
10194// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
10195
10196/**
10197* We stop loading Items when we have loaded:
10198*
10199* 1) The main Item;
10200* 2) All its variants.
10201*/
10202
10203/**
10204 * This method is working on 2 steps.
10205 *
10206 * | Step | Comment |
10207 * |------|-------------|
10208 * | 1 | do it |
10209 * | 2 | do it again |
10210 */
10211
10212/**
10213 * This is something that
10214 * I want to test.
10215 */
10216function quux () {
10217
10218}
10219
10220/**
10221 * When making HTTP requests, the
10222 * URL is super important.
10223 */
10224function quux () {
10225
10226}
10227
10228/**
10229 * Sorry, but this isn't a complete sentence, Mr.
10230 */
10231function quux () {
10232
10233}
10234
10235/**
10236 * Sorry, but this isn't a complete sentence Mr..
10237 */
10238function quux () {
10239
10240}
10241// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr."]}]
10242
10243/**
10244 * Sorry, but this isn't a complete sentence Mr.
10245 */
10246function quux () {
10247
10248}
10249
10250/**
10251 * Sorry, but this isn't a complete sentence Mr. and Mrs..
10252 */
10253function quux () {
10254
10255}
10256// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr","Mrs"]}]
10257
10258/**
10259 * This is a complete sentence aMr.
10260 */
10261function quux () {
10262
10263}
10264// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr"]}]
10265
10266/**
10267 * This is a complete sentence. But this isn't, Mr.
10268 */
10269function quux () {
10270
10271}
10272
10273/**
10274 * This is a complete Mr. Sentence. But this isn't, Mr.
10275 */
10276function quux () {
10277
10278}
10279
10280/**
10281 * This is a complete Mr. sentence.
10282 */
10283function quux () {
10284
10285}
10286// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["Mr"]}]
10287
10288/**
10289 * This is fun, i.e. enjoyable, but not superlatively so, e.g. not
10290 * super, wonderful, etc..
10291 */
10292function quux () {
10293
10294}
10295// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["etc","e.g.","i.e."]}]
10296
10297
10298**
10299* Do not have dynamic content; e.g. homepage. Here a simple unique id
10300* suffices.
10301*/
10302function quux () {
10303
10304}
10305// "jsdoc/require-description-complete-sentence": ["error"|"warn", {"abbreviations":["etc","e.g.","i.e."]}]
10306
10307/**
10308 * Implements support for the
10309 * Swahili voice synthesizer.
10310 */
10311function speak() {
10312}
10313
10314/**
10315 * @param foo
10316 *
10317 * @returns {void}
10318 */
10319export default (foo) => {
10320 foo()
10321}
10322````
10323
10324
10325<a name="eslint-plugin-jsdoc-rules-require-description"></a>
10326### <code>require-description</code>
10327
10328Requires that all functions have a description.
10329
10330* All functions must have an implicit description (e.g., text above tags) or
10331 have the option `descriptionStyle` set to `tag` (requiring `@description`
10332 (or `@desc` if that is set as your preferred tag name)).
10333* Every jsdoc block description (or `@description` tag if `descriptionStyle`
10334 is `"tag"`) must have a non-empty description that explains the purpose of
10335 the method.
10336
10337<a name="eslint-plugin-jsdoc-rules-require-description-options-23"></a>
10338#### Options
10339
10340An options object may have any of the following properties:
10341
10342- `contexts` - Set to an array of strings representing the AST context
10343 where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6
10344 classes). Overrides the default contexts (see below). Set to `"any"` if
10345 you want the rule to apply to any jsdoc block throughout your files.
10346- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
10347 document block avoids the need for a `@description`. Defaults to an
10348 array with `inheritdoc`. If you set this array, it will overwrite the
10349 default, so be sure to add back `inheritdoc` if you wish its presence
10350 to cause exemption of the rule.
10351- `descriptionStyle` - Whether to accept implicit descriptions (`"body"`) or
10352 `@description` tags (`"tag"`) as satisfying the rule. Set to `"any"` to
10353 accept either style. Defaults to `"body"`.
10354- `checkConstructors` - A value indicating whether `constructor`s should be
10355 checked. Defaults to `true`.
10356- `checkGetters` - A value indicating whether getters should be checked.
10357 Defaults to `true`.
10358- `checkSetters` - A value indicating whether setters should be checked.
10359 Defaults to `true`.
10360
10361| | |
10362| -------- | ------------------------------------------------------------------------------------------------------------- |
10363| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
10364| Tags | `description` or jsdoc block |
10365| Aliases | `desc` |
10366| Recommended | false |
10367| Options | `contexts`, `exemptedBy`, `descriptionStyle`, `checkConstructors`, `checkGetters`, `checkSetters` |
10368| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` |
10369
10370The following patterns are considered problems:
10371
10372````js
10373/**
10374 *
10375 */
10376function quux () {
10377
10378}
10379// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10380// Message: Missing JSDoc @description declaration.
10381
10382/**
10383 *
10384 */
10385function quux () {
10386
10387}
10388// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"any"}]
10389// Message: Missing JSDoc block description or @description declaration.
10390
10391/**
10392 *
10393 */
10394function quux () {
10395
10396}
10397// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"body"}]
10398// Message: Missing JSDoc block description.
10399
10400/**
10401 * @desc Not a blank description
10402 */
10403function quux () {
10404
10405}
10406// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"body"}]
10407// Message: Remove the @desc tag to leave a plain block description or add additional description text above the @desc line.
10408
10409/**
10410 * @description Not a blank description
10411 */
10412function quux () {
10413
10414}
10415// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"body"}]
10416// Message: Remove the @description tag to leave a plain block description or add additional description text above the @description line.
10417
10418/**
10419 *
10420 */
10421class quux {
10422
10423}
10424// "jsdoc/require-description": ["error"|"warn", {"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
10425// Message: Missing JSDoc @description declaration.
10426
10427/**
10428 *
10429 */
10430// "jsdoc/require-description": ["error"|"warn", {"contexts":["any"],"descriptionStyle":"tag"}]
10431// Message: Missing JSDoc @description declaration.
10432
10433/**
10434 *
10435 */
10436class quux {
10437
10438}
10439// "jsdoc/require-description": ["error"|"warn", {"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
10440// Message: Missing JSDoc @description declaration.
10441
10442/**
10443 *
10444 */
10445class quux {
10446
10447}
10448// "jsdoc/require-description": ["error"|"warn", {"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
10449// Message: Missing JSDoc @description declaration.
10450
10451/**
10452 * @description
10453 */
10454function quux () {
10455
10456}
10457// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10458// Message: Missing JSDoc @description description.
10459
10460/**
10461 *
10462 */
10463interface quux {
10464
10465}
10466// "jsdoc/require-description": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"],"descriptionStyle":"tag"}]
10467// Message: Missing JSDoc @description declaration.
10468
10469/**
10470 *
10471 */
10472var quux = class {
10473
10474};
10475// "jsdoc/require-description": ["error"|"warn", {"contexts":["ClassExpression"],"descriptionStyle":"tag"}]
10476// Message: Missing JSDoc @description declaration.
10477
10478/**
10479 *
10480 */
10481var quux = {
10482
10483};
10484// "jsdoc/require-description": ["error"|"warn", {"contexts":["ObjectExpression"],"descriptionStyle":"tag"}]
10485// Message: Missing JSDoc @description declaration.
10486
10487/**
10488 * @someDesc
10489 */
10490function quux () {
10491
10492}
10493// Settings: {"jsdoc":{"tagNamePreference":{"description":{"message":"Please avoid `{{tagName}}`; use `{{replacement}}` instead","replacement":"someDesc"}}}}
10494// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10495// Message: Missing JSDoc @someDesc description.
10496
10497/**
10498 * @description
10499 */
10500function quux () {
10501
10502}
10503// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
10504// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10505// Message: Unexpected tag `@description`
10506
10507/**
10508 * @description
10509 */
10510function quux () {
10511
10512}
10513// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
10514// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"any"}]
10515// Message: Missing JSDoc block description or @description declaration.
10516
10517/**
10518 *
10519 */
10520function quux () {
10521}
10522// "jsdoc/require-description": ["error"|"warn", {"exemptedBy":["notPresent"]}]
10523// Message: Missing JSDoc block description.
10524
10525class TestClass {
10526 /**
10527 *
10528 */
10529 constructor() { }
10530}
10531// Message: Missing JSDoc block description.
10532
10533class TestClass {
10534 /**
10535 *
10536 */
10537 constructor() { }
10538}
10539// "jsdoc/require-description": ["error"|"warn", {"checkConstructors":true}]
10540// Message: Missing JSDoc block description.
10541
10542class TestClass {
10543 /**
10544 *
10545 */
10546 get Test() { }
10547}
10548// Message: Missing JSDoc block description.
10549
10550class TestClass {
10551 /**
10552 *
10553 */
10554 get Test() { }
10555}
10556// "jsdoc/require-description": ["error"|"warn", {"checkGetters":true}]
10557// Message: Missing JSDoc block description.
10558
10559class TestClass {
10560 /**
10561 *
10562 */
10563 set Test(value) { }
10564}
10565// Message: Missing JSDoc block description.
10566
10567class TestClass {
10568 /**
10569 *
10570 */
10571 set Test(value) { }
10572}
10573// "jsdoc/require-description": ["error"|"warn", {"checkSetters":true}]
10574// Message: Missing JSDoc block description.
10575
10576/**
10577 *
10578 */
10579class Foo {
10580 /**
10581 *
10582 */
10583 constructor() {}
10584
10585 /**
10586 *
10587 */
10588 bar() {}
10589}
10590// "jsdoc/require-description": ["error"|"warn", {"checkConstructors":false,"contexts":["MethodDefinition"]}]
10591// Message: Missing JSDoc block description.
10592
10593/**
10594 * @implements {Bar}
10595 */
10596class quux {
10597
10598}
10599// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
10600// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[rawType=\"Bar\"])","context":"ClassDeclaration"}],"descriptionStyle":"tag"}]
10601// Message: Missing JSDoc @description declaration.
10602
10603/**
10604 * Has some
10605 * description already.
10606 * @implements {Bar}
10607 */
10608class quux {
10609
10610}
10611// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
10612// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[rawType=\"Bar\"])","context":"ClassDeclaration"}],"descriptionStyle":"tag"}]
10613// Message: Missing JSDoc @description declaration.
10614
10615/**
10616 * @implements {Bar
10617 * | Foo}
10618 */
10619class quux {
10620
10621}
10622// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
10623// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTypeUnion > JsdocTypeName[value=\"Bar\"]:nth-child(1))","context":"ClassDeclaration"}],"descriptionStyle":"tag"}]
10624// Message: Missing JSDoc @description declaration.
10625
10626/**
10627 * @implements {Bar}
10628 */
10629class quux {
10630
10631}
10632// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
10633// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[tag=\"implements\"])","context":"ClassDeclaration"}],"descriptionStyle":"tag"}]
10634// Message: Missing JSDoc @description declaration.
10635
10636/**
10637 * @implements {Bar}
10638 */
10639class quux {
10640
10641}
10642// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
10643// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[tag=\"implements\"])","context":"any"}],"descriptionStyle":"tag"}]
10644// Message: Missing JSDoc @description declaration.
10645````
10646
10647The following patterns are not considered problems:
10648
10649````js
10650/**
10651 *
10652 */
10653
10654/**
10655 * @description
10656 * // arbitrary description content
10657 */
10658function quux () {
10659
10660}
10661// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10662
10663/**
10664 * @description
10665 * quux(); // does something useful
10666 */
10667function quux () {
10668
10669}
10670// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10671
10672/**
10673 * @description <caption>Valid usage</caption>
10674 * quux(); // does something useful
10675 *
10676 * @description <caption>Invalid usage</caption>
10677 * quux('random unwanted arg'); // results in an error
10678 */
10679function quux () {
10680
10681}
10682// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10683
10684/**
10685 *
10686 */
10687class quux {
10688
10689}
10690// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10691
10692/**
10693 *
10694 */
10695function quux () {
10696
10697}
10698// "jsdoc/require-description": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
10699
10700/**
10701 * @type {MyCallback}
10702 */
10703function quux () {
10704
10705}
10706// "jsdoc/require-description": ["error"|"warn", {"exemptedBy":["type"]}]
10707
10708/**
10709 *
10710 */
10711interface quux {
10712
10713}
10714// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10715
10716interface quux {
10717 /**
10718 * If the thing should be checked.
10719 */
10720 checked?: boolean
10721}
10722// "jsdoc/require-description": ["error"|"warn", {"contexts":["TSPropertySignature"]}]
10723
10724/**
10725 *
10726 */
10727var quux = class {
10728
10729};
10730// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10731
10732/**
10733 *
10734 */
10735var quux = {
10736
10737};
10738// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10739
10740/**
10741 * Has an implicit description
10742 */
10743function quux () {
10744
10745}
10746// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"body"}]
10747
10748/**
10749 * Has an implicit description
10750 */
10751function quux () {
10752
10753}
10754
10755/**
10756 * Has an implicit description
10757 */
10758function quux () {
10759
10760}
10761// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"any"}]
10762
10763/**
10764 * @description Has an explicit description
10765 */
10766function quux () {
10767
10768}
10769// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"any"}]
10770
10771/**
10772 *
10773 */
10774function quux () {
10775
10776}
10777// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
10778
10779class TestClass {
10780 /**
10781 * Test.
10782 */
10783 constructor() { }
10784}
10785
10786class TestClass {
10787 /**
10788 *
10789 */
10790 constructor() { }
10791}
10792// "jsdoc/require-description": ["error"|"warn", {"checkConstructors":false}]
10793
10794class TestClass {
10795 /**
10796 * Test.
10797 */
10798 get Test() { }
10799}
10800
10801class TestClass {
10802 /**
10803 *
10804 */
10805 get Test() { }
10806}
10807// "jsdoc/require-description": ["error"|"warn", {"checkGetters":false}]
10808
10809class TestClass {
10810 /**
10811 * Test.
10812 */
10813 set Test(value) { }
10814}
10815
10816class TestClass {
10817 /**
10818 *
10819 */
10820 set Test(value) { }
10821}
10822// "jsdoc/require-description": ["error"|"warn", {"checkSetters":false}]
10823
10824/**
10825 * Multi
10826 * line
10827 */
10828function quux () {
10829
10830}
10831
10832/** Single line */
10833function quux () {
10834
10835}
10836
10837/** @description something */
10838function quux () {
10839
10840}
10841// "jsdoc/require-description": ["error"|"warn", {"descriptionStyle":"tag"}]
10842
10843/**
10844 * @implements {Bar}
10845 */
10846class quux {
10847
10848}
10849// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
10850// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=/\\s{4}/]:has(JsdocTag[rawType=\"class\"])","context":"ClassDeclaration"}],"descriptionStyle":"tag"}]
10851
10852/**
10853 * Has some
10854 * description already.
10855 */
10856class quux {
10857
10858}
10859// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[rawType=\"{Bar}\"])","context":"ClassDeclaration"}],"descriptionStyle":"tag"}]
10860
10861/**
10862 * Has some
10863 * description already.
10864 */
10865class quux {
10866
10867}
10868// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[rawType=\"{Bar}\"])","context":"any"}],"descriptionStyle":"tag"}]
10869
10870/**
10871 * Has some
10872 * description already.
10873 */
10874// "jsdoc/require-description": ["error"|"warn", {"contexts":[{"comment":"JsdocBlock[postDelimiter=\"\"]:has(JsdocTag[rawType=\"{Bar}\"])","context":"any"}],"descriptionStyle":"tag"}]
10875````
10876
10877
10878<a name="eslint-plugin-jsdoc-rules-require-example"></a>
10879### <code>require-example</code>
10880
10881Requires that all functions have examples.
10882
10883* All functions must have one or more `@example` tags.
10884* Every example tag must have a non-empty description that explains the
10885 method's usage.
10886
10887<a name="eslint-plugin-jsdoc-rules-require-example-options-24"></a>
10888#### Options
10889
10890This rule has an object option.
10891
10892<a name="eslint-plugin-jsdoc-rules-require-example-options-24-exemptedby"></a>
10893##### <code>exemptedBy</code>
10894
10895Array of tags (e.g., `['type']`) whose presence on the document
10896block avoids the need for an `@example`. Defaults to an array with
10897`inheritdoc`. If you set this array, it will overwrite the default,
10898so be sure to add back `inheritdoc` if you wish its presence to cause
10899exemption of the rule.
10900
10901<a name="eslint-plugin-jsdoc-rules-require-example-options-24-exemptnoarguments"></a>
10902##### <code>exemptNoArguments</code>
10903
10904Boolean to indicate that no-argument functions should not be reported for
10905missing `@example` declarations.
10906
10907<a name="eslint-plugin-jsdoc-rules-require-example-options-24-contexts-6"></a>
10908##### <code>contexts</code>
10909
10910Set this to an array of strings representing the AST context (or an object with
10911`context` and `comment` properties) where you wish the rule to be applied.
10912(e.g., `ClassDeclaration` for ES6
10913classes). Overrides the default contexts (see below). Set to `"any"` if you
10914want the rule to apply to any jsdoc block throughout your files.
10915
10916See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
10917section of our README for more on the expected format.
10918
10919<a name="eslint-plugin-jsdoc-rules-require-example-options-24-checkconstructors"></a>
10920##### <code>checkConstructors</code>
10921
10922A value indicating whether `constructor`s should be checked.
10923Defaults to `true`.
10924
10925<a name="eslint-plugin-jsdoc-rules-require-example-options-24-checkgetters"></a>
10926##### <code>checkGetters</code>
10927
10928A value indicating whether getters should be checked. Defaults to `false`.
10929
10930<a name="eslint-plugin-jsdoc-rules-require-example-options-24-checksetters"></a>
10931##### <code>checkSetters</code>
10932
10933A value indicating whether setters should be checked. Defaults to `false`.
10934
10935<a name="eslint-plugin-jsdoc-rules-require-example-fixer"></a>
10936#### Fixer
10937
10938The fixer for `require-example` will add an empty `@example`, but it will still
10939report a missing example description after this is added.
10940
10941|||
10942|---|---|
10943|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
10944|Tags|`example`|
10945|Recommended|false|
10946|Options|`exemptedBy`, `exemptNoArguments`, `avoidExampleOnConstructors`, `contexts`|
10947|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
10948
10949The following patterns are considered problems:
10950
10951````js
10952/**
10953 *
10954 */
10955function quux () {
10956
10957}
10958// Message: Missing JSDoc @example declaration.
10959
10960/**
10961 *
10962 */
10963function quux (someParam) {
10964
10965}
10966// "jsdoc/require-example": ["error"|"warn", {"exemptNoArguments":true}]
10967// Message: Missing JSDoc @example declaration.
10968
10969/**
10970 *
10971 */
10972function quux () {
10973
10974}
10975// Message: Missing JSDoc @example declaration.
10976
10977/**
10978 * @example
10979 */
10980function quux () {
10981
10982}
10983// Message: Missing JSDoc @example description.
10984
10985/**
10986 * @constructor
10987 */
10988function quux () {
10989
10990}
10991// Message: Missing JSDoc @example declaration.
10992
10993/**
10994 * @constructor
10995 * @example
10996 */
10997function quux () {
10998
10999}
11000// Message: Missing JSDoc @example description.
11001
11002/**
11003 *
11004 */
11005class quux {
11006
11007}
11008// "jsdoc/require-example": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
11009// Message: Missing JSDoc @example declaration.
11010
11011/**
11012 *
11013 */
11014// "jsdoc/require-example": ["error"|"warn", {"contexts":["any"]}]
11015// Message: Missing JSDoc @example declaration.
11016
11017/**
11018 *
11019 */
11020function quux () {
11021}
11022// "jsdoc/require-example": ["error"|"warn", {"exemptedBy":["notPresent"]}]
11023// Message: Missing JSDoc @example declaration.
11024
11025class TestClass {
11026 /**
11027 *
11028 */
11029 get Test() { }
11030}
11031// "jsdoc/require-example": ["error"|"warn", {"checkGetters":true}]
11032// Message: Missing JSDoc @example declaration.
11033
11034class TestClass {
11035 /**
11036 * @example
11037 */
11038 get Test() { }
11039}
11040// "jsdoc/require-example": ["error"|"warn", {"checkGetters":true}]
11041// Message: Missing JSDoc @example description.
11042
11043class TestClass {
11044 /**
11045 *
11046 */
11047 set Test(value) { }
11048}
11049// "jsdoc/require-example": ["error"|"warn", {"checkSetters":true}]
11050// Message: Missing JSDoc @example declaration.
11051
11052class TestClass {
11053 /**
11054 * @example
11055 */
11056 set Test(value) { }
11057}
11058// "jsdoc/require-example": ["error"|"warn", {"checkSetters":true}]
11059// Message: Missing JSDoc @example description.
11060````
11061
11062The following patterns are not considered problems:
11063
11064````js
11065/**
11066 *
11067 */
11068
11069/**
11070 * @example
11071 * // arbitrary example content
11072 */
11073function quux () {
11074
11075}
11076
11077/**
11078 * @example
11079 * quux(); // does something useful
11080 */
11081function quux () {
11082
11083}
11084
11085/**
11086 * @example <caption>Valid usage</caption>
11087 * quux(); // does something useful
11088 *
11089 * @example <caption>Invalid usage</caption>
11090 * quux('random unwanted arg'); // results in an error
11091 */
11092function quux () {
11093
11094}
11095
11096/**
11097 * @constructor
11098 */
11099function quux () {
11100
11101}
11102// "jsdoc/require-example": ["error"|"warn", {"checkConstructors":false}]
11103
11104/**
11105 * @constructor
11106 * @example
11107 */
11108function quux () {
11109
11110}
11111// "jsdoc/require-example": ["error"|"warn", {"checkConstructors":false}]
11112
11113class Foo {
11114 /**
11115 *
11116 */
11117 constructor () {
11118
11119 }
11120}
11121// "jsdoc/require-example": ["error"|"warn", {"checkConstructors":false}]
11122
11123/**
11124 * @inheritdoc
11125 */
11126function quux () {
11127
11128}
11129
11130/**
11131 * @type {MyCallback}
11132 */
11133function quux () {
11134
11135}
11136// "jsdoc/require-example": ["error"|"warn", {"exemptedBy":["type"]}]
11137
11138/**
11139 * @example Some example code
11140 */
11141class quux {
11142
11143}
11144// "jsdoc/require-example": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
11145
11146/**
11147 *
11148 */
11149function quux () {
11150
11151}
11152// "jsdoc/require-example": ["error"|"warn", {"contexts":["ClassDeclaration"]}]
11153
11154class TestClass {
11155 /**
11156 *
11157 */
11158 get Test() { }
11159}
11160
11161class TestClass {
11162 /**
11163 * @example
11164 */
11165 get Test() { }
11166}
11167
11168class TestClass {
11169 /**
11170 * @example Test
11171 */
11172 get Test() { }
11173}
11174// "jsdoc/require-example": ["error"|"warn", {"checkGetters":true}]
11175
11176class TestClass {
11177 /**
11178 *
11179 */
11180 set Test(value) { }
11181}
11182
11183class TestClass {
11184 /**
11185 * @example
11186 */
11187 set Test(value) { }
11188}
11189// "jsdoc/require-example": ["error"|"warn", {"checkSetters":false}]
11190
11191class TestClass {
11192 /**
11193 * @example Test
11194 */
11195 set Test(value) { }
11196}
11197// "jsdoc/require-example": ["error"|"warn", {"checkSetters":true}]
11198
11199/**
11200 *
11201 */
11202function quux () {
11203
11204}
11205// "jsdoc/require-example": ["error"|"warn", {"exemptNoArguments":true}]
11206````
11207
11208
11209<a name="eslint-plugin-jsdoc-rules-require-file-overview"></a>
11210### <code>require-file-overview</code>
11211
11212Checks that:
11213
112141. All files have a `@file`, `@fileoverview`, or `@overview` tag.
112152. Duplicate file overview tags within a given file will be reported
112163. File overview tags will be reported which are not, as per
11217 [the docs](https://jsdoc.app/tags-file.html), "at the beginning of
11218 the file"–where beginning of the file is interpreted in this rule
11219 as being when the overview tag is not preceded by anything other than
11220 a comment.
11221
11222<a name="eslint-plugin-jsdoc-rules-require-file-overview-options-25"></a>
11223#### Options
11224
11225<a name="eslint-plugin-jsdoc-rules-require-file-overview-options-25-tags-5"></a>
11226##### <code>tags</code>
11227
11228The keys of this object are tag names, and the values are configuration
11229objects indicating what will be checked for these whole-file tags.
11230
11231Each configuration object has the following boolean keys (which default
11232to `false` when this option is supplied): `mustExist`, `preventDuplicates`,
11233`initialCommentsOnly`. These correspond to the three items above.
11234
11235When no `tags` is present, the default is:
11236
11237```json
11238{
11239 "file": {
11240 "initialCommentsOnly": true,
11241 "mustExist": true,
11242 "preventDuplicates": true,
11243 }
11244}
11245```
11246
11247You can add additional tag names and/or override `file` if you supply this
11248option, e.g., in place of or in addition to `file`, giving other potential
11249file global tags like `@license`, `@copyright`, `@author`, `@module` or
11250`@exports`, optionally restricting them to a single use or preventing them
11251from being preceded by anything besides comments.
11252
11253For example:
11254
11255```js
11256{
11257 "license": {
11258 "mustExist": true,
11259 "preventDuplicates": true,
11260 }
11261}
11262```
11263
11264This would require one and only one `@license` in the file, though because
11265`initialCommentsOnly` is absent and defaults to `false`, the `@license`
11266can be anywhere.
11267
11268In the case of `@license`, you can use this rule along with the
11269`check-values` rule (with its `allowedLicenses` or `licensePattern` options),
11270to enforce a license whitelist be present on every JS file.
11271
11272Note that if you choose to use `preventDuplicates` with `license`, you still
11273have a way to allow multiple licenses for the whole page by using the SPDX
11274"AND" expression, e.g., `@license (MIT AND GPL-3.0)`.
11275
11276Note that the tag names are the main jsdoc tag name, so you should use `file`
11277in this configuration object regardless of whether you have configured
11278`fileoverview` instead of `file` on `tagNamePreference` (i.e., `fileoverview`
11279will be checked, but you must use `file` on the configuration object).
11280
11281|||
11282|---|---|
11283|Context|Everywhere|
11284|Tags|`file`; others when `tags` set|
11285|Aliases|`fileoverview`, `overview`|
11286|Recommended|false|
11287|Options|`tags`|
11288
11289The following patterns are considered problems:
11290
11291````js
11292
11293// Message: Missing @file
11294
11295
11296// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"file":{"initialCommentsOnly":true,"mustExist":true,"preventDuplicates":true}}}]
11297// Message: Missing @file
11298
11299
11300// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"file":{"mustExist":true}}}]
11301// Message: Missing @file
11302
11303
11304// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"author":{"initialCommentsOnly":false,"mustExist":true,"preventDuplicates":false}}}]
11305// Message: Missing @author
11306
11307/**
11308 *
11309 */
11310// Message: Missing @file
11311
11312/**
11313 *
11314 */
11315function quux () {}
11316// Message: Missing @file
11317
11318/**
11319 *
11320 */
11321function quux () {}
11322// Settings: {"jsdoc":{"tagNamePreference":{"file":"fileoverview"}}}
11323// Message: Missing @fileoverview
11324
11325/**
11326 *
11327 */
11328function quux () {}
11329// Settings: {"jsdoc":{"tagNamePreference":{"file":"overview"}}}
11330// Message: Missing @overview
11331
11332/**
11333 *
11334 */
11335function quux () {}
11336// Settings: {"jsdoc":{"tagNamePreference":{"file":false}}}
11337// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
11338
11339/**
11340 *
11341 */
11342function quux () {}
11343// Settings: {"jsdoc":{"tagNamePreference":{"file":false}}}
11344// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"file":{"initialCommentsOnly":false,"mustExist":true,"preventDuplicates":false}}}]
11345// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
11346
11347/**
11348 *
11349 */
11350function quux () {}
11351// Settings: {"jsdoc":{"tagNamePreference":{"file":{"message":"Don't use file"}}}}
11352// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
11353
11354/**
11355 * @param a
11356 */
11357function quux (a) {}
11358// Message: Missing @file
11359
11360/**
11361 * @param a
11362 */
11363function quux (a) {}
11364
11365/**
11366 * @param b
11367 */
11368function bar (b) {}
11369// Message: Missing @file
11370
11371/**
11372 * @file
11373 */
11374
11375 /**
11376 * @file
11377 */
11378// Message: Duplicate @file
11379
11380/**
11381 * @copyright
11382 */
11383
11384 /**
11385 * @copyright
11386 */
11387// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"copyright":{"initialCommentsOnly":false,"mustExist":false,"preventDuplicates":true}}}]
11388// Message: Duplicate @copyright
11389
11390function quux () {
11391}
11392/**
11393 * @file
11394 */
11395// Message: @file should be at the beginning of the file
11396
11397function quux () {
11398}
11399/**
11400 * @license
11401 */
11402// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":true,"mustExist":false,"preventDuplicates":false}}}]
11403// Message: @license should be at the beginning of the file
11404
11405function quux () {
11406}
11407/**
11408 * @license
11409 */
11410// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":true}}}]
11411// Message: @license should be at the beginning of the file
11412
11413/**
11414 * @file
11415 */
11416
11417/**
11418 * @file
11419 */
11420// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"file":{"initialCommentsOnly":true,"preventDuplicates":true}}}]
11421// Message: Duplicate @file
11422````
11423
11424The following patterns are not considered problems:
11425
11426````js
11427/**
11428 * @file
11429 */
11430
11431/**
11432 * @file
11433 */
11434
11435/**
11436 * @file
11437 */
11438// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":true,"preventDuplicates":true}}}]
11439
11440// Ok preceded by comment
11441/**
11442 * @file
11443 */
11444
11445/**
11446 * @fileoverview
11447 */
11448// Settings: {"jsdoc":{"tagNamePreference":{"file":"fileoverview"}}}
11449
11450/**
11451 * @overview
11452 */
11453// Settings: {"jsdoc":{"tagNamePreference":{"file":"overview"}}}
11454
11455/**
11456 * @file Description of file
11457 */
11458
11459/**
11460 * @file Description of file
11461 */
11462function quux () {
11463}
11464
11465/**
11466 *
11467 */
11468
11469function quux () {
11470}
11471/**
11472 *
11473 */
11474// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":true,"mustExist":false,"preventDuplicates":false}}}]
11475
11476function quux () {
11477}
11478/**
11479 *
11480 */
11481// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":false,"mustExist":false,"preventDuplicates":false}}}]
11482
11483function quux () {
11484}
11485/**
11486 *
11487 */
11488// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":false,"mustExist":false,"preventDuplicates":true}}}]
11489
11490/**
11491 * @license MIT
11492 */
11493
11494 var a
11495
11496 /**
11497 * @type {Array}
11498 */
11499// "jsdoc/require-file-overview": ["error"|"warn", {"tags":{"license":{"initialCommentsOnly":true,"mustExist":false,"preventDuplicates":false}}}]
11500````
11501
11502
11503<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description"></a>
11504### <code>require-hyphen-before-param-description</code>
11505
11506Requires (or disallows) a hyphen before the `@param` description.
11507
11508<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-26"></a>
11509#### Options
11510
11511This rule takes one optional string argument and an optional options object.
11512
11513If the string is `"always"` then a problem is raised when there is no hyphen
11514before the description. If it is `"never"` then a problem is raised when there
11515is a hyphen before the description. The default value is `"always"`.
11516
11517The options object may have the following properties to indicate behavior for
11518other tags besides the `@param` tag (or the `@arg` tag if so set):
11519
11520- `tags` - Object whose keys indicate different tags to check for the
11521 presence or absence of hyphens; the key value should be "always" or "never",
11522 indicating how hyphens are to be applied, e.g., `{property: 'never'}`
11523 to ensure `@property` never uses hyphens. A key can also be set as `*`, e.g.,
11524 `'*': 'always'` to apply hyphen checking to any tag (besides the preferred
11525 `@param` tag which follows the main string option setting and besides any
11526 other `tags` entries).
11527
11528|||
11529|---|---|
11530|Context|everywhere|
11531|Tags|`param` and optionally other tags within `tags`|
11532|Aliases|`arg`, `argument`; potentially `prop` or other aliases|
11533|Recommended|false|
11534|Options|a string matching `"always" or "never"` followed by an optional object with a `tags` property|
11535
11536The following patterns are considered problems:
11537
11538````js
11539/**
11540 * @param foo Foo.
11541 */
11542function quux () {
11543
11544}
11545// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always"]
11546// Message: There must be a hyphen before @param description.
11547
11548/**
11549 * @param foo Foo.
11550 */
11551function quux () {
11552
11553}
11554// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"*":"never"}}]
11555// Message: There must be a hyphen before @param description.
11556
11557/**
11558 * @param foo Foo.
11559 * @returns {SomeType} - Hyphen here.
11560 */
11561function quux () {
11562
11563}
11564// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"*":"never","returns":"always"}}]
11565// Message: There must be a hyphen before @param description.
11566
11567/**
11568 * @param foo Foo.
11569 */
11570function quux () {
11571
11572}
11573// Message: There must be a hyphen before @param description.
11574
11575/**
11576 * @param foo - Foo.
11577 */
11578function quux () {
11579
11580}
11581// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never"]
11582// Message: There must be no hyphen before @param description.
11583
11584/**
11585 * @param foo - Foo.
11586 */
11587function quux () {
11588
11589}
11590// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never"]
11591// Message: There must be no hyphen before @param description.
11592
11593/**
11594 * @param foo - foo
11595 * @param foo foo
11596 */
11597function quux () {
11598
11599}
11600// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always"]
11601// Message: There must be a hyphen before @param description.
11602
11603/**
11604 * @param foo foo
11605 * bar
11606 * @param bar - bar
11607 */
11608function quux () {
11609
11610}
11611// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always"]
11612// Message: There must be a hyphen before @param description.
11613
11614/**
11615 * @param foo
11616 */
11617function quux (foo) {
11618
11619}
11620// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
11621// Message: Unexpected tag `@param`
11622
11623/**
11624 * @typedef {SomeType} ATypeDefName
11625 * @property foo Foo.
11626 */
11627// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"property":"always"}}]
11628// Message: There must be a hyphen before @property description.
11629
11630/**
11631 * @template TempA, TempB A desc.
11632 */
11633// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"template":"always"}}]
11634// Message: There must be a hyphen before @template description.
11635
11636/**
11637 * @typedef {SomeType} ATypeDefName
11638 * @property foo - Foo.
11639 */
11640// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never",{"tags":{"property":"never"}}]
11641// Message: There must be no hyphen before @property description.
11642
11643/**
11644 * @param foo Foo.
11645 * @returns {SomeType} - A description.
11646 */
11647function quux () {
11648
11649}
11650// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"returns":"never"}}]
11651// Message: There must be a hyphen before @param description.
11652````
11653
11654The following patterns are not considered problems:
11655
11656````js
11657/**
11658 * @param foo - Foo.
11659 */
11660function quux () {
11661
11662}
11663// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always"]
11664
11665/**
11666 * @param foo - Foo.
11667 */
11668function quux () {
11669
11670}
11671// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always"]
11672
11673/**
11674 * @param foo - Foo.
11675 * @returns {SomeType} A description.
11676 */
11677function quux () {
11678
11679}
11680// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"returns":"never"}}]
11681
11682/**
11683 * @param foo Foo.
11684 */
11685function quux () {
11686
11687}
11688// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never"]
11689
11690/**
11691 * @param foo
11692 */
11693function quux () {
11694
11695}
11696
11697/**
11698 *
11699 */
11700function quux () {
11701
11702}
11703// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"*":"always"}}]
11704
11705/**
11706 * @typedef {SomeType} ATypeDefName
11707 * @property foo - Foo.
11708 */
11709// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "always",{"tags":{"property":"always"}}]
11710
11711/**
11712 * @typedef {SomeType} ATypeDefName
11713 * @property foo Foo.
11714 */
11715// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never",{"tags":{"property":"never"}}]
11716
11717/**
11718 * @typedef {SomeType} ATypeDefName
11719 * @property foo - Foo.
11720 */
11721// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never",{"tags":{"*":"always"}}]
11722
11723/** Entry point for module.
11724 *
11725 * @param {!Array<string>} argv Command-line arguments.
11726 */
11727function main(argv) {
11728};
11729// "jsdoc/require-hyphen-before-param-description": ["error"|"warn", "never"]
11730````
11731
11732
11733<a name="eslint-plugin-jsdoc-rules-require-jsdoc"></a>
11734### <code>require-jsdoc</code>
11735
11736Checks for presence of jsdoc comments, on class declarations as well as
11737functions.
11738
11739<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27"></a>
11740#### Options
11741
11742Accepts one optional options object with the following optional keys.
11743
11744<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-publiconly"></a>
11745##### <code>publicOnly</code>
11746
11747This option will insist that missing jsdoc blocks are only reported for
11748function bodies / class declarations that are exported from the module.
11749May be a boolean or object. If set to `true`, the defaults below will be
11750used. If unset, jsdoc block reporting will not be limited to exports.
11751
11752This object supports the following optional boolean keys (`false` unless
11753otherwise noted):
11754
11755- `ancestorsOnly` - Only check node ancestors to check if node is exported
11756- `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
11757- `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
11758- `window` - Window global exports are checked for JSDoc comments
11759
11760<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-require"></a>
11761##### <code>require</code>
11762
11763An object with the following optional boolean keys which all default to
11764`false` except as noted, indicating the contexts where the rule will apply:
11765
11766- `ArrowFunctionExpression`
11767- `ClassDeclaration`
11768- `ClassExpression`
11769- `FunctionDeclaration` (defaults to `true`)
11770- `FunctionExpression`
11771- `MethodDefinition`
11772
11773<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-contexts-7"></a>
11774##### <code>contexts</code>
11775
11776Set this to an array of strings or objects representing the additional AST
11777contexts where you wish the rule to be applied (e.g., `Property` for
11778properties). If specified as an object, it should have a `context` property
11779and can have an `inlineCommentBlock` property which, if set to `true`, will
11780add an inline `/** */` instead of the regular, multi-line, indented jsdoc
11781block which will otherwise be added. Defaults to an empty array.
11782
11783Note that you may need to disable `require` items (e.g., `MethodDefinition`)
11784if you are specifying a more precise form in `contexts` (e.g., `MethodDefinition:not([accessibility="private"] > FunctionExpression`).
11785
11786See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
11787section of our README for more on the expected format.
11788
11789<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-exemptemptyconstructors"></a>
11790##### <code>exemptEmptyConstructors</code>
11791
11792Default: true
11793
11794When `true`, the rule will not report missing jsdoc blocks above constructors
11795with no parameters or return values (this is enabled by default as the class
11796name or description should be seen as sufficient to convey intent).
11797
11798<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-exemptemptyfunctions"></a>
11799##### <code>exemptEmptyFunctions</code>
11800
11801Default: false.
11802
11803When `true`, the rule will not report missing jsdoc blocks above
11804functions/methods with no parameters or return values (intended where
11805function/method names are sufficient for themselves as documentation).
11806
11807<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-checkconstructors-1"></a>
11808##### <code>checkConstructors</code>
11809
11810A value indicating whether `constructor`s should be checked. Defaults to
11811`true`. When `true`, `exemptEmptyConstructors` may still avoid reporting when
11812no parameters or return values are found.
11813
11814<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-checkgetters-1"></a>
11815##### <code>checkGetters</code>
11816
11817A value indicating whether getters should be checked. Besides setting as a
11818boolean, this option can be set to the string `"no-setter"` to indicate that
11819getters should be checked but only when there is no setter. This may be useful
11820if one only wishes documentation on one of the two accessors. Defaults to
11821`false`.
11822
11823<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-checksetters-1"></a>
11824##### <code>checkSetters</code>
11825
11826A value indicating whether setters should be checked. Besides setting as a
11827boolean, this option can be set to the string `"no-getter"` to indicate that
11828setters should be checked but only when there is no getter. This may be useful
11829if one only wishes documentation on one of the two accessors. Defaults to
11830`false`.
11831
11832<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-27-enablefixer-2"></a>
11833##### <code>enableFixer</code>
11834
11835A boolean on whether to enable the fixer (which adds an empty jsdoc block).
11836Defaults to `true`.
11837
11838|||
11839|---|---|
11840|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
11841|Tags|N/A|
11842|Recommended|true|
11843|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyConstructors`, `exemptEmptyFunctions`, `enableFixer`|
11844
11845The following patterns are considered problems:
11846
11847````js
11848/** This is comment */
11849export interface Foo {
11850 /** This is comment x2 */
11851 tom: string;
11852 catchJerry(): boolean;
11853}
11854// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true,"ClassExpression":true,"MethodDefinition":true}}]
11855// Message: Missing JSDoc comment.
11856
11857/** This is comment */
11858export interface Foo {
11859 /** This is comment x2 */
11860 tom: string;
11861 jerry: number;
11862}
11863// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true,"ClassExpression":true,"MethodDefinition":true}}]
11864// Message: Missing JSDoc comment.
11865
11866/** This is comment */
11867export interface Foo {
11868 bar(): string;
11869}
11870// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true}}]
11871// Message: Missing JSDoc comment.
11872
11873/** This is comment */
11874export interface Foo {
11875 bar: string;
11876}
11877// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true,"esm":true}}]
11878// Message: Missing JSDoc comment.
11879
11880/**
11881 * Foo interface documentation.
11882 */
11883export interface Foo extends Bar {
11884 /**
11885 * baz method documentation.
11886 */
11887 baz(): void;
11888
11889 meow(): void;
11890}
11891// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSMethodSignature"],"publicOnly":{"ancestorsOnly":true}}]
11892// Message: Missing JSDoc comment.
11893
11894function quux (foo) {
11895
11896}
11897// Message: Missing JSDoc comment.
11898
11899/**
11900 * @func myFunction
11901 */
11902function myFunction() {
11903
11904}
11905// Settings: {"jsdoc":{"maxLines":3,"minLines":2}}
11906// Message: Missing JSDoc comment.
11907
11908/**
11909 * @func myFunction
11910 */
11911
11912
11913function myFunction() {
11914
11915}
11916// Settings: {"jsdoc":{"maxLines":2}}
11917// Message: Missing JSDoc comment.
11918
11919/** @func myFunction */ function myFunction() {
11920
11921}
11922// Settings: {"jsdoc":{"minLines":1}}
11923// Message: Missing JSDoc comment.
11924
11925function myFunction() {
11926
11927}
11928// "jsdoc/require-jsdoc": ["error"|"warn", {"enableFixer":false}]
11929// Message: Missing JSDoc comment.
11930
11931export var test = function () {
11932
11933};
11934// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
11935// Message: Missing JSDoc comment.
11936
11937function test () {
11938
11939}
11940export var test2 = test;
11941// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionDeclaration":true}}]
11942// Message: Missing JSDoc comment.
11943
11944export const test = () => {
11945
11946};
11947// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
11948// Message: Missing JSDoc comment.
11949
11950export const test = () => {
11951
11952};
11953// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ArrowFunctionExpression"],"publicOnly":true}]
11954// Message: Missing JSDoc comment.
11955
11956export const test = () => {
11957
11958};
11959// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":[{"context":"ArrowFunctionExpression"}],"publicOnly":true}]
11960// Message: Missing JSDoc comment.
11961
11962export let test = class {
11963
11964};
11965// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ClassExpression":true}}]
11966// Message: Missing JSDoc comment.
11967
11968export default function () {}
11969// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
11970// Message: Missing JSDoc comment.
11971
11972export default () => {}
11973// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"ArrowFunctionExpression":true}}]
11974// Message: Missing JSDoc comment.
11975
11976export default (function () {})
11977// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
11978// Message: Missing JSDoc comment.
11979
11980export default class {}
11981// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"ClassDeclaration":true}}]
11982// Message: Missing JSDoc comment.
11983
11984function quux (foo) {
11985
11986}
11987// Message: Missing JSDoc comment.
11988
11989function quux (foo) {
11990
11991}
11992// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":true}]
11993// Message: Missing JSDoc comment.
11994
11995function quux (foo) {
11996
11997}
11998// Settings: {"jsdoc":{"minLines":2}}
11999// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":true}]
12000// Message: Missing JSDoc comment.
12001
12002function myFunction() {}
12003// Message: Missing JSDoc comment.
12004
12005/**
12006 * Description for A.
12007 */
12008class A {
12009 constructor(xs) {
12010 this.a = xs;
12011 }
12012}
12013// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12014// Message: Missing JSDoc comment.
12015
12016class A {
12017 /**
12018 * Description for constructor.
12019 * @param {object[]} xs - xs
12020 */
12021 constructor(xs) {
12022 this.a = xs;
12023 }
12024}
12025// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12026// Message: Missing JSDoc comment.
12027
12028class A extends B {
12029 /**
12030 * Description for constructor.
12031 * @param {object[]} xs - xs
12032 */
12033 constructor(xs) {
12034 this.a = xs;
12035 }
12036}
12037// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12038// Message: Missing JSDoc comment.
12039
12040export class A extends B {
12041 /**
12042 * Description for constructor.
12043 * @param {object[]} xs - xs
12044 */
12045 constructor(xs) {
12046 this.a = xs;
12047 }
12048}
12049// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12050// Message: Missing JSDoc comment.
12051
12052export default class A extends B {
12053 /**
12054 * Description for constructor.
12055 * @param {object[]} xs - xs
12056 */
12057 constructor(xs) {
12058 this.a = xs;
12059 }
12060}
12061// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12062// Message: Missing JSDoc comment.
12063
12064var myFunction = () => {}
12065// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true}}]
12066// Message: Missing JSDoc comment.
12067
12068var myFunction = () => () => {}
12069// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true}}]
12070// Message: Missing JSDoc comment.
12071
12072var foo = function() {}
12073// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12074// Message: Missing JSDoc comment.
12075
12076const foo = {bar() {}}
12077// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12078// Message: Missing JSDoc comment.
12079
12080var foo = {bar: function() {}}
12081// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12082// Message: Missing JSDoc comment.
12083
12084function foo (abc) {}
12085// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":false}]
12086// Message: Missing JSDoc comment.
12087
12088function foo () {
12089 return true;
12090}
12091// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":false}]
12092// Message: Missing JSDoc comment.
12093
12094module.exports = function quux () {
12095
12096}
12097// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12098// Message: Missing JSDoc comment.
12099
12100module.exports = function quux () {
12101
12102}
12103// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
12104// Message: Missing JSDoc comment.
12105
12106module.exports = {
12107 method: function() {
12108
12109 }
12110}
12111// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12112// Message: Missing JSDoc comment.
12113
12114module.exports = {
12115 test: {
12116 test2: function() {
12117
12118 }
12119 }
12120}
12121// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12122// Message: Missing JSDoc comment.
12123
12124module.exports = {
12125 test: {
12126 test2: function() {
12127
12128 }
12129 }
12130}
12131// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
12132// Message: Missing JSDoc comment.
12133
12134const test = module.exports = function () {
12135
12136}
12137// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12138// Message: Missing JSDoc comment.
12139
12140/**
12141*
12142*/
12143const test = module.exports = function () {
12144
12145}
12146
12147test.prototype.method = function() {}
12148// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12149// Message: Missing JSDoc comment.
12150
12151const test = function () {
12152
12153}
12154module.exports = {
12155 test: test
12156}
12157// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12158// Message: Missing JSDoc comment.
12159
12160const test = () => {
12161
12162}
12163module.exports = {
12164 test: test
12165}
12166// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
12167// Message: Missing JSDoc comment.
12168
12169class Test {
12170 method() {
12171
12172 }
12173}
12174module.exports = Test;
12175// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"MethodDefinition":true}}]
12176// Message: Missing JSDoc comment.
12177
12178export default function quux () {
12179
12180}
12181// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12182// Message: Missing JSDoc comment.
12183
12184export default function quux () {
12185
12186}
12187// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
12188// Message: Missing JSDoc comment.
12189
12190function quux () {
12191
12192}
12193export default quux;
12194// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12195// Message: Missing JSDoc comment.
12196
12197export function test() {
12198
12199}
12200// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12201// Message: Missing JSDoc comment.
12202
12203export function test() {
12204
12205}
12206// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
12207// Message: Missing JSDoc comment.
12208
12209var test = function () {
12210
12211}
12212var test2 = 2;
12213export { test, test2 }
12214// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12215// Message: Missing JSDoc comment.
12216
12217var test = function () {
12218
12219}
12220export { test as test2 }
12221// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12222// Message: Missing JSDoc comment.
12223
12224export default class A {
12225
12226}
12227// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ClassDeclaration":true}}]
12228// Message: Missing JSDoc comment.
12229
12230export default class A {
12231
12232}
12233// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true}}]
12234// Message: Missing JSDoc comment.
12235
12236var test = function () {
12237
12238}
12239// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
12240// Message: Missing JSDoc comment.
12241
12242window.test = function () {
12243
12244}
12245// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
12246// Message: Missing JSDoc comment.
12247
12248function test () {
12249
12250}
12251// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"window":true}}]
12252// Message: Missing JSDoc comment.
12253
12254module.exports = function() {
12255
12256}
12257// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionExpression":true}}]
12258// Message: Missing JSDoc comment.
12259
12260export function someMethod() {
12261
12262}
12263// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
12264// Message: Missing JSDoc comment.
12265
12266export function someMethod() {
12267
12268}
12269// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
12270// Message: Missing JSDoc comment.
12271
12272const myObject = {
12273 myProp: true
12274};
12275// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["Property"]}]
12276// Message: Missing JSDoc comment.
12277
12278/**
12279 * Foo interface documentation.
12280 */
12281export interface Foo extends Bar {
12282 /**
12283 * baz method documentation.
12284 */
12285 baz(): void;
12286
12287 meow(): void;
12288}
12289// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSMethodSignature"]}]
12290// Message: Missing JSDoc comment.
12291
12292class MyClass {
12293 someProperty: boolean; // Flow type annotation.
12294}
12295// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":true,"require":{"ClassDeclaration":true}}]
12296// Message: Missing JSDoc comment.
12297
12298export default class Test {
12299 constructor(a) {
12300 this.a = a;
12301 }
12302}
12303// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ArrowFunctionExpression":false,"ClassDeclaration":false,"ClassExpression":false,"FunctionDeclaration":false,"FunctionExpression":false,"MethodDefinition":true}}]
12304// Message: Missing JSDoc comment.
12305
12306export default class Test {
12307 constructor(a) {
12308 this.a = a;
12309 }
12310 private abc(a) {
12311 this.a = a;
12312 }
12313}
12314// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition:not([accessibility=\"private\"]) > FunctionExpression"],"publicOnly":true,"require":{"ArrowFunctionExpression":false,"ClassDeclaration":false,"ClassExpression":false,"FunctionDeclaration":false,"FunctionExpression":false,"MethodDefinition":false}}]
12315// Message: Missing JSDoc comment.
12316
12317e = function () {
12318};
12319// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionDeclaration":false,"FunctionExpression":true}}]
12320// Message: Missing JSDoc comment.
12321
12322/**
12323 *
12324 */
12325export class Class {
12326 test = 1;
12327
12328 foo() {
12329 this.test = 2;
12330 }
12331}
12332// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionDeclaration":false,"MethodDefinition":true}}]
12333// Message: Missing JSDoc comment.
12334
12335class Dog {
12336 eat() {
12337
12338 }
12339}
12340// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionDeclaration":false,"MethodDefinition":true}}]
12341// Message: Missing JSDoc comment.
12342
12343const hello = name => {
12344 document.body.textContent = "Hello, " + name + "!";
12345};
12346// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":false}}]
12347// Message: Missing JSDoc comment.
12348
12349export const loginSuccessAction = (): BaseActionPayload => ({ type: LOGIN_SUCCESSFUL });
12350// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":false}}]
12351// Message: Missing JSDoc comment.
12352
12353export type Container = {
12354 constants?: ObjByString;
12355 enums?: { [key in string]: TypescriptEnum };
12356 helpers?: { [key in string]: AnyFunction };
12357};
12358// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSTypeAliasDeclaration",{"context":"TSPropertySignature","inlineCommentBlock":true}]}]
12359// Message: Missing JSDoc comment.
12360
12361class Foo {
12362 constructor() {}
12363
12364 bar() {}
12365}
12366// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition[key.name!=\"constructor\"]"],"require":{"ClassDeclaration":true}}]
12367// Message: Missing JSDoc comment.
12368
12369class Example extends React.PureComponent {
12370 componentDidMount() {}
12371
12372 render() {}
12373
12374 someOtherMethod () {}
12375}
12376// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition:not([key.name=\"componentDidMount\"]):not([key.name=\"render\"])"],"require":{"ClassDeclaration":true}}]
12377// Message: Missing JSDoc comment.
12378
12379function foo(arg: boolean): boolean {
12380 return arg;
12381}
12382
12383function bar(arg: true): true;
12384function bar(arg: false): false;
12385function bar(arg: boolean): boolean {
12386 return arg;
12387}
12388// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSDeclareFunction:not(TSDeclareFunction + TSDeclareFunction)","FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)"],"require":{"FunctionDeclaration":false}}]
12389// Message: Missing JSDoc comment.
12390
12391export function foo(arg: boolean): boolean {
12392 return arg;
12393}
12394
12395export function bar(arg: true): true;
12396export function bar(arg: false): false;
12397export function bar(arg: boolean): boolean {
12398 return arg;
12399}
12400// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ExportNamedDeclaration[declaration.type=\"TSDeclareFunction\"]:not(ExportNamedDeclaration[declaration.type=\"TSDeclareFunction\"] + ExportNamedDeclaration[declaration.type=\"TSDeclareFunction\"])","ExportNamedDeclaration[declaration.type=\"FunctionDeclaration\"]:not(ExportNamedDeclaration[declaration.type=\"TSDeclareFunction\"] + ExportNamedDeclaration[declaration.type=\"FunctionDeclaration\"])"],"require":{"FunctionDeclaration":false}}]
12401// Message: Missing JSDoc comment.
12402
12403module.exports.foo = (bar) => {
12404 return bar + "biz"
12405}
12406// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":false,"require":{"ArrowFunctionExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}]
12407// Message: Missing JSDoc comment.
12408
12409class Animal {
12410
12411 #name: string;
12412
12413 private species: string;
12414
12415 public color: string;
12416
12417 @SomeAnnotation('optionalParameter')
12418 tail: boolean;
12419}
12420// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ClassProperty"]}]
12421// Message: Missing JSDoc comment.
12422
12423@Entity('users')
12424export class User {}
12425// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true}}]
12426// Message: Missing JSDoc comment.
12427
12428/**
12429 *
12430 */
12431class Foo {
12432 constructor() {}
12433}
12434// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyConstructors":false,"require":{"MethodDefinition":true}}]
12435// Message: Missing JSDoc comment.
12436
12437/**
12438 *
12439 */
12440class Foo {
12441 constructor(notEmpty) {}
12442}
12443// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyConstructors":true,"require":{"MethodDefinition":true}}]
12444// Message: Missing JSDoc comment.
12445
12446/**
12447 *
12448 */
12449class Foo {
12450 constructor() {
12451 const notEmpty = true;
12452 return notEmpty;
12453 }
12454}
12455// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyConstructors":true,"require":{"MethodDefinition":true}}]
12456// Message: Missing JSDoc comment.
12457
12458/**
12459 *
12460 */
12461function quux() {
12462
12463}
12464// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
12465// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
12466
12467class Test {
12468 aFunc() {}
12469}
12470// "jsdoc/require-jsdoc": ["error"|"warn", {"checkConstructors":false,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":false,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}]
12471// Message: Missing JSDoc comment.
12472
12473class Test {
12474 aFunc = () => {}
12475 anotherFunc() {}
12476}
12477// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true,"ClassDeclaration":false,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":true,"MethodDefinition":true}}]
12478// Message: Missing JSDoc comment.
12479
12480export enum testEnum {
12481 A, B
12482}
12483// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSEnumDeclaration"],"publicOnly":true}]
12484// Message: Missing JSDoc comment.
12485
12486export interface Test {
12487 aFunc: () => void;
12488 aVar: string;
12489}
12490// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"],"publicOnly":true}]
12491// Message: Missing JSDoc comment.
12492
12493export type testType = string | number;
12494// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSTypeAliasDeclaration"],"publicOnly":true}]
12495// Message: Missing JSDoc comment.
12496
12497export interface Foo {
12498 bar: number;
12499 baz: string;
12500 quux(): void;
12501}
12502// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSPropertySignature","TSMethodSignature"],"publicOnly":true}]
12503// Message: Missing JSDoc comment.
12504
12505export class MyComponentComponent {
12506 @Output()
12507 public changed = new EventEmitter();
12508
12509 public test = 'test';
12510
12511 @Input()
12512 public value = new EventEmitter();
12513}
12514// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ClassProperty:has(Decorator[expression.callee.name=\"Input\"])"]}]
12515// Message: Missing JSDoc comment.
12516
12517requestAnimationFrame(draw)
12518
12519function bench() {
12520}
12521// Message: Missing JSDoc comment.
12522
12523class Foo {
12524 set aName (val) {}
12525}
12526// "jsdoc/require-jsdoc": ["error"|"warn", {"checkSetters":"no-getter","contexts":["MethodDefinition > FunctionExpression"]}]
12527// Message: Missing JSDoc comment.
12528
12529class Foo {
12530 get aName () {}
12531}
12532// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":"no-setter","contexts":["MethodDefinition > FunctionExpression"]}]
12533// Message: Missing JSDoc comment.
12534
12535const obj = {
12536 get aName () {},
12537}
12538// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":"no-setter","contexts":["Property > FunctionExpression"]}]
12539// Message: Missing JSDoc comment.
12540````
12541
12542The following patterns are not considered problems:
12543
12544````js
12545interface FooBar {
12546 fooBar: string;
12547}
12548// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true}}]
12549
12550/** This is comment */
12551interface FooBar {
12552 fooBar: string;
12553}
12554// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true}}]
12555
12556/** This is comment */
12557export class Foo {
12558 someMethod() {
12559 interface FooBar {
12560 fooBar: string;
12561 }
12562 }
12563}
12564// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true}}]
12565
12566/** This is comment */
12567function someFunciton() {
12568 interface FooBar {
12569 fooBar: string;
12570 }
12571}
12572// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true}}]
12573
12574/** This is comment */
12575export function foo() {
12576 interface bar {
12577 fooBar: string;
12578 }
12579}
12580// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration","TSMethodSignature","TSPropertySignature"],"publicOnly":{"ancestorsOnly":true}}]
12581
12582/**
12583 *
12584 */
12585
12586var array = [1,2,3];
12587array.forEach(function() {});
12588
12589/**
12590 * @class MyClass
12591 **/
12592function MyClass() {}
12593
12594/**
12595 Function doing something
12596 */
12597function myFunction() {}
12598/**
12599 Function doing something
12600 */
12601var myFunction = function() {};
12602/**
12603 Function doing something
12604 */
12605Object.myFunction = function () {};
12606var obj = {
12607 /**
12608 * Function doing something
12609 **/
12610 myFunction: function () {} };
12611
12612/**
12613 @func myFunction
12614 */
12615function myFunction() {}
12616/**
12617 @method myFunction
12618 */
12619function myFunction() {}
12620/**
12621 @function myFunction
12622 */
12623function myFunction() {}
12624
12625/**
12626 @func myFunction
12627 */
12628var myFunction = function () {}
12629/**
12630 @method myFunction
12631 */
12632var myFunction = function () {}
12633/**
12634 @function myFunction
12635 */
12636var myFunction = function () {}
12637
12638/**
12639 @func myFunction
12640 */
12641Object.myFunction = function() {}
12642/**
12643 @method myFunction
12644 */
12645Object.myFunction = function() {}
12646/**
12647 @function myFunction
12648 */
12649Object.myFunction = function() {}
12650(function(){})();
12651
12652var object = {
12653 /**
12654 * @func myFunction - Some function
12655 */
12656 myFunction: function() {} }
12657var object = {
12658 /**
12659 * @method myFunction - Some function
12660 */
12661 myFunction: function() {} }
12662var object = {
12663 /**
12664 * @function myFunction - Some function
12665 */
12666 myFunction: function() {} }
12667
12668var array = [1,2,3];
12669array.filter(function() {});
12670Object.keys(this.options.rules || {}).forEach(function(name) {}.bind(this));
12671var object = { name: 'key'};
12672Object.keys(object).forEach(function() {})
12673
12674/**
12675 * @func myFunction
12676 */
12677
12678function myFunction() {
12679
12680}
12681// Settings: {"jsdoc":{"maxLines":2,"minLines":0}}
12682
12683/**
12684 * @func myFunction
12685 */
12686
12687
12688function myFunction() {
12689
12690}
12691// Settings: {"jsdoc":{"maxLines":3,"minLines":0}}
12692
12693/** @func myFunction */ function myFunction() {
12694
12695}
12696// Settings: {"jsdoc":{"maxLines":0,"minLines":0}}
12697
12698/**
12699 * @func myFunction
12700 */
12701
12702function myFunction() {
12703
12704}
12705// Settings: {"jsdoc":{"maxLines":3,"minLines":2}}
12706
12707function myFunction() {}
12708// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"FunctionDeclaration":false,"MethodDefinition":true}}]
12709
12710var myFunction = function() {}
12711// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"FunctionDeclaration":false,"MethodDefinition":true}}]
12712
12713/**
12714 * Description for A.
12715 */
12716class A {
12717 /**
12718 * Description for constructor.
12719 * @param {object[]} xs - xs
12720 */
12721 constructor(xs) {
12722 this.a = xs;
12723 }
12724}
12725// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12726
12727/**
12728 * Description for A.
12729 */
12730class App extends Component {
12731 /**
12732 * Description for constructor.
12733 * @param {object[]} xs - xs
12734 */
12735 constructor(xs) {
12736 this.a = xs;
12737 }
12738}
12739// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12740
12741/**
12742 * Description for A.
12743 */
12744export default class App extends Component {
12745 /**
12746 * Description for constructor.
12747 * @param {object[]} xs - xs
12748 */
12749 constructor(xs) {
12750 this.a = xs;
12751 }
12752}
12753// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12754
12755/**
12756 * Description for A.
12757 */
12758export class App extends Component {
12759 /**
12760 * Description for constructor.
12761 * @param {object[]} xs - xs
12762 */
12763 constructor(xs) {
12764 this.a = xs;
12765 }
12766}
12767// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
12768
12769class A {
12770 constructor(xs) {
12771 this.a = xs;
12772 }
12773}
12774// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":false,"MethodDefinition":false}}]
12775
12776/**
12777* Function doing something
12778*/
12779var myFunction = () => {}
12780// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true}}]
12781
12782/**
12783* Function doing something
12784*/
12785var myFunction = function () {}
12786// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true}}]
12787
12788/**
12789* Function doing something
12790*/
12791var myFunction = () => {}
12792// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":false}}]
12793
12794/**
12795 Function doing something
12796*/
12797var myFunction = () => () => {}
12798// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true}}]
12799
12800setTimeout(() => {}, 10);
12801// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":true}}]
12802
12803/**
12804JSDoc Block
12805*/
12806var foo = function() {}
12807// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12808
12809const foo = {/**
12810JSDoc Block
12811*/
12812bar() {}}
12813// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12814
12815var foo = {/**
12816JSDoc Block
12817*/
12818bar: function() {}}
12819// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12820
12821var foo = { [function() {}]: 1 };
12822// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"FunctionExpression":true}}]
12823
12824function foo () {}
12825// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":true}]
12826
12827function foo () {
12828 return;
12829}
12830// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":true}]
12831
12832const test = {};
12833/**
12834 * test
12835 */
12836 test.method = function () {
12837
12838}
12839module.exports = {
12840 prop: { prop2: test.method }
12841}
12842// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12843
12844/**
12845 *
12846 */
12847function test() {
12848
12849}
12850
12851module.exports = {
12852 prop: { prop2: test }
12853}
12854// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12855
12856/**
12857 *
12858 */
12859test = function() {
12860
12861}
12862
12863module.exports = {
12864 prop: { prop2: test }
12865}
12866// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionExpression":true}}]
12867
12868/**
12869 *
12870 */
12871test = function() {
12872
12873}
12874
12875exports.someMethod = {
12876 prop: { prop2: test }
12877}
12878// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
12879
12880/**
12881 *
12882 */
12883const test = () => {
12884
12885}
12886
12887module.exports = {
12888prop: { prop2: test }
12889}
12890// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
12891
12892const test = () => {
12893
12894}
12895module.exports = {
12896 prop: { prop2: test }
12897}
12898// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"ArrowFunctionExpression":true}}]
12899
12900/**
12901 *
12902 */
12903window.test = function() {
12904
12905}
12906
12907module.exports = {
12908prop: window
12909}
12910// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12911
12912test = function() {
12913
12914}
12915
12916/**
12917 *
12918 */
12919test = function() {
12920
12921}
12922
12923module.exports = {
12924prop: { prop2: test }
12925}
12926// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12927
12928test = function() {
12929
12930}
12931
12932test = 2;
12933
12934module.exports = {
12935prop: { prop2: test }
12936}
12937// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12938
12939/**
12940 *
12941 */
12942function test() {
12943
12944}
12945
12946/**
12947 *
12948 */
12949test.prototype.method = function() {
12950
12951}
12952
12953module.exports = {
12954prop: { prop2: test }
12955}
12956// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12957
12958class Test {
12959 /**
12960 * Test
12961 */
12962 method() {
12963
12964 }
12965}
12966module.exports = Test;
12967// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"MethodDefinition":true}}]
12968
12969/**
12970 *
12971 */
12972export default function quux () {
12973
12974}
12975// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12976
12977/**
12978 *
12979 */
12980export default function quux () {
12981
12982}
12983// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
12984
12985/**
12986 *
12987 */
12988function quux () {
12989
12990}
12991export default quux;
12992// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
12993
12994function quux () {
12995
12996}
12997export default quux;
12998// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
12999
13000/**
13001 *
13002 */
13003export function test() {
13004
13005}
13006// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
13007
13008/**
13009 *
13010 */
13011export function test() {
13012
13013}
13014// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
13015
13016/**
13017 *
13018 */
13019var test = function () {
13020
13021}
13022var test2 = 2;
13023export { test, test2 }
13024// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
13025
13026/**
13027 *
13028 */
13029var test = function () {
13030
13031}
13032export { test as test2 }
13033// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
13034
13035/**
13036 *
13037 */
13038export default class A {
13039
13040}
13041// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true}}]
13042
13043/**
13044 *
13045 */
13046var test = function () {
13047
13048}
13049// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
13050
13051let test = function () {
13052
13053}
13054// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
13055
13056let test = class {
13057
13058}
13059// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ClassExpression":false}}]
13060
13061/**
13062 *
13063 */
13064let test = class {
13065
13066}
13067// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"ClassExpression":true}}]
13068
13069export function someMethod() {
13070
13071}
13072// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionDeclaration":true}}]
13073
13074export function someMethod() {
13075
13076}
13077// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionDeclaration":true}}]
13078
13079exports.someMethod = function() {
13080
13081}
13082// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
13083
13084const myObject = {
13085 myProp: true
13086};
13087// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":[]}]
13088
13089function bear() {}
13090/**
13091 *
13092 */
13093function quux () {
13094}
13095export default quux;
13096// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true,"require":{"FunctionExpression":true}}]
13097
13098/**
13099 * This example interface is great!
13100 */
13101export interface Example {
13102 /**
13103 * My super test string!
13104 */
13105 test: string
13106}
13107// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"]}]
13108
13109/**
13110 * This example interface is great!
13111 */
13112interface Example {
13113 /**
13114 * My super test string!
13115 */
13116 test: string
13117}
13118// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSInterfaceDeclaration"]}]
13119
13120/**
13121 * This example type is great!
13122 */
13123export type Example = {
13124 /**
13125 * My super test string!
13126 */
13127 test: string
13128};
13129// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSTypeAliasDeclaration"]}]
13130
13131/**
13132 * This example type is great!
13133 */
13134type Example = {
13135 /**
13136 * My super test string!
13137 */
13138 test: string
13139};
13140// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSTypeAliasDeclaration"]}]
13141
13142/**
13143 * This example enum is great!
13144 */
13145export enum Example {
13146 /**
13147 * My super test enum!
13148 */
13149 test = 123
13150}
13151// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSEnumDeclaration"]}]
13152
13153/**
13154 * This example enum is great!
13155 */
13156enum Example {
13157 /**
13158 * My super test enum!
13159 */
13160 test = 123
13161}
13162// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSEnumDeclaration"]}]
13163
13164const foo = {...{}};
13165function bar() {}
13166// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":false,"publicOnly":true,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
13167
13168/**
13169 * Class documentation
13170 */
13171 @logged
13172export default class Foo {
13173 // ....
13174}
13175// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyFunctions":false,"require":{"ClassDeclaration":true}}]
13176
13177const a = {};
13178const b = {
13179 ...a
13180};
13181
13182export default b;
13183// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["ObjectExpression"],"exemptEmptyFunctions":false,"publicOnly":true}]
13184
13185/**
13186 * Foo interface documentation.
13187 */
13188export interface Foo extends Bar {
13189 /**
13190 * baz method documentation.
13191 */
13192 baz(): void;
13193
13194 /**
13195 * meow method documentation.
13196 */
13197 meow(): void;
13198}
13199// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSMethodSignature"]}]
13200
13201export default class Test {
13202 private abc(a) {
13203 this.a = a;
13204 }
13205}
13206// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition:not([accessibility=\"private\"]) > FunctionExpression"],"publicOnly":true,"require":{"ArrowFunctionExpression":false,"ClassDeclaration":false,"ClassExpression":false,"FunctionDeclaration":false,"FunctionExpression":false,"MethodDefinition":false}}]
13207
13208/**
13209 * Basic application controller.
13210 */
13211@Controller()
13212export class AppController {
13213 /**
13214 * Returns the application information.
13215 *
13216 * @returns ...
13217 */
13218 @Get('/info')
13219 public getInfo(): string {
13220 return 'OK';
13221 }
13222}
13223// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":false,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
13224
13225/**
13226 * Entity to represent a user in the system.
13227 */
13228@Entity('users')
13229export class User {
13230}
13231// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":false,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
13232
13233/**
13234 * Entity to represent a user in the system.
13235 */
13236@Entity('users', getVal())
13237export class User {
13238}
13239// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ArrowFunctionExpression":false,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
13240
13241/**
13242 *
13243 */
13244class Foo {
13245 constructor() {}
13246}
13247// "jsdoc/require-jsdoc": ["error"|"warn", {"exemptEmptyConstructors":true,"require":{"MethodDefinition":true}}]
13248
13249/**
13250 *
13251 */
13252class Foo {
13253 constructor() {}
13254}
13255// "jsdoc/require-jsdoc": ["error"|"warn", {"checkConstructors":false,"require":{"MethodDefinition":true}}]
13256
13257class Foo {
13258 get aName () {}
13259 set aName (val) {}
13260}
13261// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":"no-setter","checkSetters":false,"contexts":["MethodDefinition > FunctionExpression"]}]
13262
13263const obj = {
13264 get aName () {},
13265 set aName (val) {}
13266}
13267// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":"no-setter","checkSetters":false,"contexts":["Property > FunctionExpression"]}]
13268
13269class Foo {
13270 set aName (val) {}
13271}
13272// "jsdoc/require-jsdoc": ["error"|"warn", {"checkSetters":false,"contexts":["MethodDefinition > FunctionExpression"]}]
13273
13274class Foo {
13275 get aName () {}
13276}
13277// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":false,"contexts":["MethodDefinition > FunctionExpression"]}]
13278
13279class Foo {
13280 /**
13281 *
13282 */
13283 set aName (val) {}
13284}
13285// "jsdoc/require-jsdoc": ["error"|"warn", {"checkSetters":"no-getter","contexts":["MethodDefinition > FunctionExpression"]}]
13286
13287class Foo {
13288 /**
13289 *
13290 */
13291 get aName () {}
13292}
13293// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":"no-setter","contexts":["MethodDefinition > FunctionExpression"]}]
13294
13295class Foo {
13296 get aName () {}
13297 set aName (val) {}
13298}
13299// "jsdoc/require-jsdoc": ["error"|"warn", {"checkGetters":false,"checkSetters":"no-getter","contexts":["MethodDefinition > FunctionExpression"]}]
13300
13301class Base {
13302 constructor() {
13303 }
13304}
13305// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["MethodDefinition"],"exemptEmptyConstructors":true}]
13306
13307/**
13308 * This is a text.
13309 */
13310export function a(); // Reports an error
13311// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["TSDeclareFunction"],"require":{"FunctionDeclaration":true}}]
13312
13313/**
13314 * Foo
13315 */
13316export function foo(): void {
13317 function bar(): void {
13318 console.log('bar');
13319 }
13320
13321 console.log('foo');
13322}
13323// "jsdoc/require-jsdoc": ["error"|"warn", {"publicOnly":true}]
13324
13325const foo = {
13326 bar: () => {
13327 // ...
13328 }
13329}
13330// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":[":not(Property) > ArrowFunctionExpression"],"require":{"ArrowFunctionExpression":false,"ClassDeclaration":true,"ClassExpression":true}}]
13331
13332/** Defines the current user's settings. */
13333@Injectable({
13334 providedIn: 'root',
13335})
13336@State<Partial<UserSettingsStateModel>>
13337({
13338 name: 'userSettings',
13339 defaults: {
13340 isDev: !environment.production,
13341 },
13342})
13343export class UserSettingsState { }
13344// "jsdoc/require-jsdoc": ["error"|"warn", {"require":{"ClassDeclaration":true}}]
13345
13346/**
13347 * Entity to represent a user in the system.
13348 */
13349@Entity('users')
13350export class User {
13351}
13352// "jsdoc/require-jsdoc": ["error"|"warn", {"contexts":["Decorator"],"require":{"FunctionDeclaration":false}}]
13353````
13354
13355
13356<a name="eslint-plugin-jsdoc-rules-require-param-description"></a>
13357### <code>require-param-description</code>
13358
13359Requires that each `@param` tag has a `description` value.
13360
13361<a name="eslint-plugin-jsdoc-rules-require-param-description-options-28"></a>
13362#### Options
13363
13364<a name="eslint-plugin-jsdoc-rules-require-param-description-options-28-contexts-8"></a>
13365##### <code>contexts</code>
13366
13367Set this to an array of strings representing the AST context (or an object with
13368`context` and `comment` properties) where you wish the rule to be applied.
13369Overrides the default contexts (see below). Set to `"any"` if you want
13370the rule to apply to any jsdoc block throughout your files (as is necessary
13371for finding function blocks not attached to a function declaration or
13372expression, i.e., `@callback` or `@function` (or its aliases `@func` or
13373`@method`) (including those associated with an `@interface`).
13374
13375See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
13376section of our README for more on the expected format.
13377
13378|||
13379|---|---|
13380|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
13381|Tags|`param`|
13382|Aliases|`arg`, `argument`|
13383|Recommended|true|
13384|Options|`contexts`|
13385
13386The following patterns are considered problems:
13387
13388````js
13389/**
13390 * @param foo
13391 */
13392function quux (foo) {
13393
13394}
13395// Message: Missing JSDoc @param "foo" description.
13396
13397/**
13398 * @param foo
13399 */
13400function quux (foo) {
13401
13402}
13403// "jsdoc/require-param-description": ["error"|"warn", {"contexts":["any"]}]
13404// Message: Missing JSDoc @param "foo" description.
13405
13406/**
13407 * @function
13408 * @param foo
13409 */
13410// "jsdoc/require-param-description": ["error"|"warn", {"contexts":["any"]}]
13411// Message: Missing JSDoc @param "foo" description.
13412
13413/**
13414 * @callback
13415 * @param foo
13416 */
13417// "jsdoc/require-param-description": ["error"|"warn", {"contexts":["any"]}]
13418// Message: Missing JSDoc @param "foo" description.
13419
13420/**
13421 * @arg foo
13422 */
13423function quux (foo) {
13424
13425}
13426// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
13427// Message: Missing JSDoc @arg "foo" description.
13428
13429/**
13430 * @param foo
13431 */
13432function quux (foo) {
13433
13434}
13435// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
13436// Message: Unexpected tag `@param`
13437````
13438
13439The following patterns are not considered problems:
13440
13441````js
13442/**
13443 *
13444 */
13445function quux (foo) {
13446
13447}
13448
13449/**
13450 * @param foo Foo.
13451 */
13452function quux (foo) {
13453
13454}
13455
13456/**
13457 * @param foo Foo.
13458 */
13459function quux (foo) {
13460
13461}
13462// "jsdoc/require-param-description": ["error"|"warn", {"contexts":["any"]}]
13463
13464/**
13465 * @function
13466 * @param foo
13467 */
13468
13469/**
13470 * @callback
13471 * @param foo
13472 */
13473````
13474
13475
13476<a name="eslint-plugin-jsdoc-rules-require-param-name"></a>
13477### <code>require-param-name</code>
13478
13479Requires that all function parameters have names.
13480
13481> The `@param` tag requires you to specify the name of the parameter you are documenting. You can also include the parameter's type, enclosed in curly brackets, and a description of the parameter.
13482>
13483> [JSDoc](https://jsdoc.app/tags-param.html#overview)
13484
13485<a name="eslint-plugin-jsdoc-rules-require-param-name-options-29"></a>
13486#### Options
13487
13488<a name="eslint-plugin-jsdoc-rules-require-param-name-options-29-contexts-9"></a>
13489##### <code>contexts</code>
13490
13491Set this to an array of strings representing the AST context (or an object with
13492`context` and `comment` properties) where you wish the rule to be applied.
13493Overrides the default contexts (see below). Set to `"any"` if you want
13494the rule to apply to any jsdoc block throughout your files (as is necessary
13495for finding function blocks not attached to a function declaration or
13496expression, i.e., `@callback` or `@function` (or its aliases `@func` or
13497`@method`) (including those associated with an `@interface`).
13498
13499See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
13500section of our README for more on the expected format.
13501
13502|||
13503|---|---|
13504|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
13505|Tags|`param`|
13506|Aliases|`arg`, `argument`|
13507|Recommended|true|
13508|Options|`contexts`|
13509
13510The following patterns are considered problems:
13511
13512````js
13513/**
13514 * @param
13515 */
13516function quux (foo) {
13517
13518}
13519// Message: There must be an identifier after @param type.
13520
13521/**
13522 * @param {string}
13523 */
13524function quux (foo) {
13525
13526}
13527// Message: There must be an identifier after @param tag.
13528
13529/**
13530 * @param {string}
13531 */
13532function quux (foo) {
13533
13534}
13535// "jsdoc/require-param-name": ["error"|"warn", {"contexts":["any"]}]
13536// Message: There must be an identifier after @param tag.
13537
13538/**
13539 * @function
13540 * @param {string}
13541 */
13542// "jsdoc/require-param-name": ["error"|"warn", {"contexts":["any"]}]
13543// Message: There must be an identifier after @param tag.
13544
13545/**
13546 * @callback
13547 * @param {string}
13548 */
13549// "jsdoc/require-param-name": ["error"|"warn", {"contexts":["any"]}]
13550// Message: There must be an identifier after @param tag.
13551
13552/**
13553 * @param foo
13554 */
13555function quux (foo) {
13556
13557}
13558// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
13559// Message: Unexpected tag `@param`
13560````
13561
13562The following patterns are not considered problems:
13563
13564````js
13565/**
13566 * @param foo
13567 */
13568function quux (foo) {
13569
13570}
13571
13572/**
13573 * @param foo
13574 */
13575function quux (foo) {
13576
13577}
13578// "jsdoc/require-param-name": ["error"|"warn", {"contexts":["any"]}]
13579
13580/**
13581 * @param {string} foo
13582 */
13583function quux (foo) {
13584
13585}
13586
13587/**
13588 * @function
13589 * @param
13590 */
13591
13592/**
13593 * @callback
13594 * @param
13595 */
13596
13597/**
13598 * @param {Function} [processor=data => data] A function to run
13599 */
13600function processData(processor) {
13601 return processor(data)
13602}
13603
13604/** Example with multi-line param type.
13605*
13606* @param {function(
13607* number
13608* )} cb Callback.
13609*/
13610function example(cb) {
13611 cb(42);
13612}
13613````
13614
13615
13616<a name="eslint-plugin-jsdoc-rules-require-param-type"></a>
13617### <code>require-param-type</code>
13618
13619Requires that each `@param` tag has a `type` value.
13620
13621<a name="eslint-plugin-jsdoc-rules-require-param-type-options-30"></a>
13622#### Options
13623
13624<a name="eslint-plugin-jsdoc-rules-require-param-type-options-30-contexts-10"></a>
13625##### <code>contexts</code>
13626
13627Set this to an array of strings representing the AST context (or an object with
13628`context` and `comment` properties) where you wish the rule to be applied.
13629Overrides the default contexts (see below). Set to `"any"` if you want
13630the rule to apply to any jsdoc block throughout your files (as is necessary
13631for finding function blocks not attached to a function declaration or
13632expression, i.e., `@callback` or `@function` (or its aliases `@func` or
13633`@method`) (including those associated with an `@interface`).
13634
13635See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
13636section of our README for more on the expected format.
13637
13638|||
13639|---|---|
13640|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
13641|Tags|`param`|
13642|Aliases|`arg`, `argument`|
13643|Recommended|true|
13644|Options|`contexts`|
13645
13646The following patterns are considered problems:
13647
13648````js
13649/**
13650 * @param foo
13651 */
13652function quux (foo) {
13653
13654}
13655// Message: Missing JSDoc @param "foo" type.
13656
13657/**
13658 * @param foo
13659 */
13660function quux (foo) {
13661
13662}
13663// "jsdoc/require-param-type": ["error"|"warn", {"contexts":["any"]}]
13664// Message: Missing JSDoc @param "foo" type.
13665
13666/**
13667 * @function
13668 * @param foo
13669 */
13670// "jsdoc/require-param-type": ["error"|"warn", {"contexts":["any"]}]
13671// Message: Missing JSDoc @param "foo" type.
13672
13673/**
13674 * @callback
13675 * @param foo
13676 */
13677// "jsdoc/require-param-type": ["error"|"warn", {"contexts":["any"]}]
13678// Message: Missing JSDoc @param "foo" type.
13679
13680/**
13681 * @arg foo
13682 */
13683function quux (foo) {
13684
13685}
13686// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
13687// Message: Missing JSDoc @arg "foo" type.
13688
13689/**
13690 * @param foo
13691 */
13692function quux (foo) {
13693
13694}
13695// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
13696// Message: Unexpected tag `@param`
13697````
13698
13699The following patterns are not considered problems:
13700
13701````js
13702/**
13703 *
13704 */
13705function quux (foo) {
13706
13707}
13708
13709/**
13710 * @param {number} foo
13711 */
13712function quux (foo) {
13713
13714}
13715
13716/**
13717 * @param {number} foo
13718 */
13719function quux (foo) {
13720
13721}
13722// "jsdoc/require-param-type": ["error"|"warn", {"contexts":["any"]}]
13723
13724/**
13725 * @function
13726 * @param foo
13727 */
13728
13729/**
13730 * @callback
13731 * @param foo
13732 */
13733````
13734
13735
13736<a name="eslint-plugin-jsdoc-rules-require-param"></a>
13737### <code>require-param</code>
13738
13739Requires that all function parameters are documented.
13740
13741<a name="eslint-plugin-jsdoc-rules-require-param-fixer-1"></a>
13742#### Fixer
13743
13744Adds `@param <name>` for each tag present in the function signature but
13745missing in the jsdoc. Can be disabled by setting the `enableFixer`
13746option to `false`.
13747
13748<a name="eslint-plugin-jsdoc-rules-require-param-fixer-1-destructured-object-and-array-naming"></a>
13749##### Destructured object and array naming
13750
13751When the fixer is applied to destructured objects, only the input name is
13752used.
13753
13754So for:
13755
13756```js
13757/**
13758 * @param cfg
13759 */
13760function quux ({foo: bar, baz: bax = 5}) {
13761}
13762```
13763
13764..the fixed jsdoc will be:
13765
13766```js
13767/**
13768* @param cfg
13769* @param cfg.foo
13770* @param cfg.baz
13771*/
13772```
13773
13774This is because the input to the function is the relevant item for
13775understanding the function's input, not how the variable is renamed
13776for internal use (the signature itself documents that).
13777
13778For destructured arrays, the input name is merely the array index.
13779
13780So for:
13781
13782```js
13783/**
13784 * @param cfg
13785 */
13786function quux ([foo, bar]) {
13787}
13788```
13789
13790..the fixed jsdoc will be:
13791
13792```js
13793/**
13794* @param cfg
13795* @param cfg."0"
13796* @param cfg."1"
13797*/
13798```
13799
13800<a name="eslint-plugin-jsdoc-rules-require-param-fixer-1-missing-root-fixing"></a>
13801##### Missing root fixing
13802
13803Note that unless `enableRootFixer` (or `enableFixer`) is set to `false`,
13804missing roots will be added and auto-incremented. The default behavior
13805is for "root" to be auto-inserted for missing roots, followed by a
138060-based auto-incrementing number.
13807
13808So for:
13809
13810```js
13811function quux ({foo}, {bar}, {baz}) {
13812}
13813```
13814
13815...the default jsdoc that would be added if the fixer is enabled would be:
13816
13817```js
13818/**
13819* @param root0
13820* @param root0.foo
13821* @param root1
13822* @param root1.bar
13823* @param root2
13824* @param root2.baz
13825*/
13826```
13827
13828The name of "root" can be configured with `unnamedRootBase` (which also allows
13829cycling through a list of multiple root names before there is need for any
13830numeric component).
13831
13832And one can have the count begin at another number (e.g., `1`) by changing
13833`autoIncrementBase` from the default of `0`.
13834
13835<a name="eslint-plugin-jsdoc-rules-require-param-fixer-1-rest-element-restelement-insertions"></a>
13836##### Rest Element (<code>RestElement</code>) insertions
13837
13838The fixer will automatically report/insert
13839[jsdoc repeatable parameters](https://jsdoc.app/tags-param.html#multiple-types-and-repeatable-parameters)
13840if missing.
13841
13842```js
13843/**
13844 * @param {GenericArray} cfg
13845 * @param {number} cfg."0"
13846 */
13847function baar ([a, ...extra]) {
13848 //
13849}
13850```
13851
13852..becomes:
13853
13854```js
13855/**
13856 * @param {GenericArray} cfg
13857 * @param {number} cfg."0"
13858 * @param {...any} cfg."1"
13859 */
13860function baar ([a, ...extra]) {
13861 //
13862}
13863```
13864
13865Note that the type `any` is included since we don't know of any specific
13866type to use.
13867
13868To disable such rest element insertions, set `enableRestElementFixer` to
13869`false`.
13870
13871Note too that the following will be reported even though there is an item
13872corresponding to `extra`:
13873
13874```js
13875/**
13876 * @param {GenericArray} cfg
13877 * @param {number} cfg."0"
13878 * @param {any} cfg."1"
13879 */
13880function baar ([a, ...extra]) {
13881 //
13882}
13883```
13884
13885...because it does not use the `...` syntax in the type.
13886
13887<a name="eslint-plugin-jsdoc-rules-require-param-fixer-1-object-rest-property-insertions"></a>
13888##### Object Rest Property insertions
13889
13890If the `checkRestProperty` option is set to `true` (`false` by default),
13891missing rest properties will be reported with documentation auto-inserted:
13892
13893```js
13894/**
13895 * @param cfg
13896 * @param cfg.num
13897 */
13898function quux ({num, ...extra}) {
13899}
13900```
13901
13902...becomes:
13903
13904```js
13905/**
13906 * @param cfg
13907 * @param cfg.num
13908 * @param cfg.extra
13909 */
13910function quux ({num, ...extra}) {
13911}
13912```
13913
13914You may wish to manually note in your jsdoc for `extra` that this is a
13915rest property, however, as jsdoc
13916[does not appear](https://github.com/jsdoc/jsdoc/issues/1773)
13917to currently support syntax or output to distinguish rest properties from
13918other properties, so in looking at the docs alone without looking at the
13919function signature, it may appear that there is an actual property named
13920`extra`.
13921
13922<a name="eslint-plugin-jsdoc-rules-require-param-options-31"></a>
13923#### Options
13924
13925An options object accepts the following optional properties:
13926
13927<a name="eslint-plugin-jsdoc-rules-require-param-options-31-enablefixer-3"></a>
13928##### <code>enableFixer</code>
13929
13930Whether to enable the fixer. Defaults to `true`.
13931
13932<a name="eslint-plugin-jsdoc-rules-require-param-options-31-enablerootfixer"></a>
13933##### <code>enableRootFixer</code>
13934
13935Whether to enable the auto-adding of incrementing roots (see the "Fixer"
13936section). Defaults to `true`. Has no effect if `enableFixer` is set to
13937`false`.
13938
13939<a name="eslint-plugin-jsdoc-rules-require-param-options-31-enablerestelementfixer"></a>
13940##### <code>enableRestElementFixer</code>
13941
13942Whether to enable the rest element fixer (see
13943"Rest Element (`RestElement`) insertions"). Defaults to `true`.
13944
13945<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checkrestproperty-1"></a>
13946##### <code>checkRestProperty</code>
13947
13948If set to `true`, will report (and add fixer insertions) for missing rest
13949properties. Defaults to `false`.
13950
13951If set to `true`, note that you can still document the subproperties of the
13952rest property using other jsdoc features, e.g., `@typedef`:
13953
13954```js
13955/**
13956 * @typedef ExtraOptions
13957 * @property innerProp1
13958 * @property innerProp2
13959 */
13960
13961/**
13962 * @param cfg
13963 * @param cfg.num
13964 * @param {ExtraOptions} extra
13965 */
13966function quux ({num, ...extra}) {
13967}
13968```
13969
13970Setting this option to `false` (the default) may be useful in cases where
13971you already have separate `@param` definitions for each of the properties
13972within the rest property.
13973
13974For example, with the option disabled, this will not give an error despite
13975`extra` not having any definition:
13976
13977```js
13978/**
13979 * @param cfg
13980 * @param cfg.num
13981 */
13982function quux ({num, ...extra}) {
13983}
13984```
13985
13986Nor will this:
13987
13988```js
13989/**
13990 * @param cfg
13991 * @param cfg.num
13992 * @param cfg.innerProp1
13993 * @param cfg.innerProp2
13994 */
13995function quux ({num, ...extra}) {
13996}
13997```
13998
13999<a name="eslint-plugin-jsdoc-rules-require-param-options-31-autoincrementbase"></a>
14000##### <code>autoIncrementBase</code>
14001
14002Numeric to indicate the number at which to begin auto-incrementing roots.
14003Defaults to `0`.
14004
14005<a name="eslint-plugin-jsdoc-rules-require-param-options-31-unnamedrootbase"></a>
14006##### <code>unnamedRootBase</code>
14007
14008An array of root names to use in the fixer when roots are missing. Defaults
14009to `['root']`. Note that only when all items in the array besides the last
14010are exhausted will auto-incrementing occur. So, with
14011`unnamedRootBase: ['arg', 'config']`, the following:
14012
14013```js
14014function quux ({foo}, [bar], {baz}) {
14015}
14016```
14017
14018...will get the following jsdoc block added:
14019
14020```js
14021/**
14022* @param arg
14023* @param arg.foo
14024* @param config0
14025* @param config0."0" (`bar`)
14026* @param config1
14027* @param config1.baz
14028*/
14029```
14030
14031<a name="eslint-plugin-jsdoc-rules-require-param-options-31-exemptedby-1"></a>
14032##### <code>exemptedBy</code>
14033
14034Array of tags (e.g., `['type']`) whose presence on the document block
14035avoids the need for a `@param`. Defaults to an array with
14036`inheritdoc`. If you set this array, it will overwrite the default,
14037so be sure to add back `inheritdoc` if you wish its presence to cause
14038exemption of the rule.
14039
14040<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checktypespattern-1"></a>
14041##### <code>checkTypesPattern</code>
14042
14043When one specifies a type, unless it is of a generic type, like `object`
14044or `array`, it may be considered unnecessary to have that object's
14045destructured components required, especially where generated docs will
14046link back to the specified type. For example:
14047
14048```js
14049/**
14050 * @param {SVGRect} bbox - a SVGRect
14051 */
14052export const bboxToObj = function ({x, y, width, height}) {
14053 return {x, y, width, height};
14054};
14055```
14056
14057By default `checkTypesPattern` is set to
14058`/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/u`,
14059meaning that destructuring will be required only if the type of the `@param`
14060(the text between curly brackets) is a match for "Object" or "Array" (with or
14061without initial caps), "PlainObject", or "GenericObject", "GenericArray" (or
14062if no type is present). So in the above example, the lack of a match will
14063mean that no complaint will be given about the undocumented destructured
14064parameters.
14065
14066Note that the `/` delimiters are optional, but necessary to add flags.
14067
14068Defaults to using (only) the `u` flag, so to add your own flags, encapsulate
14069your expression as a string, but like a literal, e.g., `/^object$/ui`.
14070
14071You could set this regular expression to a more expansive list, or you
14072could restrict it such that even types matching those strings would not
14073need destructuring.
14074
14075<a name="eslint-plugin-jsdoc-rules-require-param-options-31-contexts-11"></a>
14076##### <code>contexts</code>
14077
14078Set this to an array of strings representing the AST context (or an object with
14079`context` and `comment` properties) where you wish the rule to be applied.
14080Overrides the default contexts (see below). May be useful for adding such as
14081`TSMethodSignature` in TypeScript or restricting the contexts
14082which are checked.
14083
14084See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
14085section of our README for more on the expected format.
14086
14087<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checkconstructors-2"></a>
14088##### <code>checkConstructors</code>
14089
14090A value indicating whether `constructor`s should be checked. Defaults to
14091`true`.
14092
14093<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checkgetters-2"></a>
14094##### <code>checkGetters</code>
14095
14096A value indicating whether getters should be checked. Defaults to `false`.
14097
14098<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checksetters-2"></a>
14099##### <code>checkSetters</code>
14100
14101A value indicating whether setters should be checked. Defaults to `false`.
14102
14103<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checkdestructured-1"></a>
14104##### <code>checkDestructured</code>
14105
14106Whether to require destructured properties. Defaults to `true`.
14107
14108<a name="eslint-plugin-jsdoc-rules-require-param-options-31-checkdestructuredroots"></a>
14109##### <code>checkDestructuredRoots</code>
14110
14111Whether to check the existence of a corresponding `@param` for root objects
14112of destructured properties (e.g., that for `function ({a, b}) {}`, that there
14113is something like `@param myRootObj` defined that can correspond to
14114the `{a, b}` object parameter).
14115
14116If `checkDestructuredRoots` is `false`, `checkDestructured` will also be
14117implied to be `false` (i.e., the inside of the roots will not be checked
14118either, e.g., it will also not complain if `a` or `b` do not have their own
14119documentation). Defaults to `true`.
14120
14121<a name="eslint-plugin-jsdoc-rules-require-param-options-31-usedefaultobjectproperties-1"></a>
14122##### <code>useDefaultObjectProperties</code>
14123
14124Set to `true` if you wish to expect documentation of properties on objects
14125supplied as default values. Defaults to `false`.
14126
14127| | |
14128| -------- | ----------------------------------------------------------------------------- |
14129| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
14130| Tags | `param` |
14131| Aliases | `arg`, `argument` |
14132|Recommended | true|
14133| Options | `autoIncrementBase`, `checkDestructured`, `checkDestructuredRoots`, `contexts`, `enableFixer`, `enableRootFixer`, `enableRestElementFixer`, `checkRestProperty`, `exemptedBy`, `checkConstructors`, `checkGetters`, `checkSetters`, `checkTypesPattern`, `unnamedRootBase`, `useDefaultObjectProperties`|
14134| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
14135
14136The following patterns are considered problems:
14137
14138````js
14139/**
14140 *
14141 */
14142function quux (foo) {
14143
14144}
14145// Message: Missing JSDoc @param "foo" declaration.
14146
14147/**
14148 *
14149 */
14150function quux (foo) {
14151
14152}
14153// "jsdoc/require-param": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
14154// Message: Missing JSDoc @param "foo" declaration.
14155
14156/**
14157 *
14158 */
14159function quux ({foo}) {
14160
14161}
14162// Message: Missing JSDoc @param "root0" declaration.
14163
14164/**
14165 * @param foo
14166 */
14167function quux (foo, bar, {baz}) {
14168
14169}
14170// "jsdoc/require-param": ["error"|"warn", {"checkDestructured":false}]
14171// Message: Missing JSDoc @param "bar" declaration.
14172
14173/**
14174 * @param foo
14175 */
14176function quux (foo, bar, {baz}) {
14177
14178}
14179// "jsdoc/require-param": ["error"|"warn", {"checkDestructuredRoots":false}]
14180// Message: Missing JSDoc @param "bar" declaration.
14181
14182/**
14183 *
14184 */
14185function quux ({foo}) {
14186
14187}
14188// "jsdoc/require-param": ["error"|"warn", {"enableFixer":false}]
14189// Message: Missing JSDoc @param "root0" declaration.
14190
14191/**
14192 *
14193 */
14194function quux ({foo: bar = 5} = {}) {
14195
14196}
14197// Message: Missing JSDoc @param "root0" declaration.
14198
14199/**
14200 * @param
14201 */
14202function quux ({foo}) {
14203
14204}
14205// Message: Missing JSDoc @param "root0" declaration.
14206
14207/**
14208 * @param
14209 */
14210function quux ({foo}) {
14211
14212}
14213// "jsdoc/require-param": ["error"|"warn", {"autoIncrementBase":1}]
14214// Message: Missing JSDoc @param "root1" declaration.
14215
14216/**
14217 * @param options
14218 */
14219function quux ({foo}) {
14220
14221}
14222// Message: Missing JSDoc @param "options.foo" declaration.
14223
14224/**
14225 * @param
14226 */
14227function quux ({ foo, bar: { baz }}) {
14228
14229}
14230// Message: Missing JSDoc @param "root0" declaration.
14231
14232/**
14233 *
14234 */
14235function quux ({foo}, {bar}) {
14236
14237}
14238// "jsdoc/require-param": ["error"|"warn", {"unnamedRootBase":["arg"]}]
14239// Message: Missing JSDoc @param "arg0" declaration.
14240
14241/**
14242 *
14243 */
14244function quux ({foo}, {bar}) {
14245
14246}
14247// "jsdoc/require-param": ["error"|"warn", {"unnamedRootBase":["arg","config"]}]
14248// Message: Missing JSDoc @param "arg" declaration.
14249
14250/**
14251 *
14252 */
14253function quux ({foo}, {bar}) {
14254
14255}
14256// "jsdoc/require-param": ["error"|"warn", {"enableRootFixer":false,"unnamedRootBase":["arg","config"]}]
14257// Message: Missing JSDoc @param "arg" declaration.
14258
14259/**
14260 *
14261 */
14262function quux (foo, bar) {
14263
14264}
14265// Message: Missing JSDoc @param "foo" declaration.
14266
14267/**
14268 * @param foo
14269 */
14270function quux (foo, bar) {
14271
14272}
14273// Message: Missing JSDoc @param "bar" declaration.
14274
14275/**
14276 * @param bar
14277 */
14278function quux (foo, bar, baz) {
14279
14280}
14281// Message: Missing JSDoc @param "foo" declaration.
14282
14283/**
14284 * @param foo
14285 * @param bar
14286 */
14287function quux (foo, bar, baz) {
14288
14289}
14290// Message: Missing JSDoc @param "baz" declaration.
14291
14292/**
14293 * @param baz
14294 */
14295function quux (foo, bar, baz) {
14296
14297}
14298// Message: Missing JSDoc @param "foo" declaration.
14299
14300/**
14301 * @param
14302 */
14303function quux (foo) {
14304
14305}
14306// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
14307// Message: Missing JSDoc @arg "foo" declaration.
14308
14309/**
14310 * @param foo
14311 */
14312function quux (foo, bar) {
14313
14314}
14315// Message: Missing JSDoc @param "bar" declaration.
14316
14317/**
14318 * @override
14319 */
14320function quux (foo) {
14321
14322}
14323// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
14324// Message: Missing JSDoc @param "foo" declaration.
14325
14326/**
14327 * @implements
14328 */
14329function quux (foo) {
14330
14331}
14332// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
14333// Message: Missing JSDoc @param "foo" declaration.
14334
14335/**
14336 * @augments
14337 */
14338function quux (foo) {
14339
14340}
14341// Message: Missing JSDoc @param "foo" declaration.
14342
14343/**
14344 * @extends
14345 */
14346function quux (foo) {
14347
14348}
14349// Message: Missing JSDoc @param "foo" declaration.
14350
14351/**
14352 * @override
14353 */
14354class A {
14355 /**
14356 *
14357 */
14358 quux (foo) {
14359
14360 }
14361}
14362// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
14363// Message: Missing JSDoc @param "foo" declaration.
14364
14365/**
14366 * @implements
14367 */
14368class A {
14369 /**
14370 *
14371 */
14372 quux (foo) {
14373
14374 }
14375}
14376// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
14377// Message: Missing JSDoc @param "foo" declaration.
14378
14379/**
14380 * @augments
14381 */
14382class A {
14383 /**
14384 *
14385 */
14386 quux (foo) {
14387
14388 }
14389}
14390// Message: Missing JSDoc @param "foo" declaration.
14391
14392/**
14393 * @extends
14394 */
14395class A {
14396 /**
14397 *
14398 */
14399 quux (foo) {
14400
14401 }
14402}
14403// Message: Missing JSDoc @param "foo" declaration.
14404
14405export class SomeClass {
14406 /**
14407 * @param property
14408 */
14409 constructor(private property: string, private foo: number) {}
14410}
14411// Message: Missing JSDoc @param "foo" declaration.
14412
14413/**
14414 * @param
14415 */
14416function quux (foo) {
14417
14418}
14419// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
14420// Message: Unexpected tag `@param`
14421
14422/**
14423 *
14424 */
14425function quux ({bar, baz}, foo) {
14426}
14427// Message: Missing JSDoc @param "root0" declaration.
14428
14429/**
14430 *
14431 */
14432function quux (foo, {bar, baz}) {
14433}
14434// Message: Missing JSDoc @param "foo" declaration.
14435
14436/**
14437 *
14438 */
14439function quux ([bar, baz], foo) {
14440}
14441// Message: Missing JSDoc @param "root0" declaration.
14442
14443/**
14444 *
14445 */
14446function quux (foo) {
14447}
14448// "jsdoc/require-param": ["error"|"warn", {"exemptedBy":["notPresent"]}]
14449// Message: Missing JSDoc @param "foo" declaration.
14450
14451/**
14452 * @inheritdoc
14453 */
14454function quux (foo) {
14455
14456}
14457// "jsdoc/require-param": ["error"|"warn", {"exemptedBy":[]}]
14458// Message: Missing JSDoc @param "foo" declaration.
14459
14460/**
14461 * @inheritdoc
14462 */
14463function quux (foo) {
14464
14465}
14466// Settings: {"jsdoc":{"mode":"closure"}}
14467// Message: Missing JSDoc @param "foo" declaration.
14468
14469/**
14470 * Assign the project to a list of employees.
14471 * @param {object[]} employees - The employees who are responsible for the project.
14472 * @param {string} employees[].name - The name of an employee.
14473 * @param {string} employees[].department - The employee's department.
14474 */
14475function assign (employees, name) {
14476
14477};
14478// Message: Missing JSDoc @param "name" declaration.
14479
14480interface ITest {
14481/**
14482 * Test description.
14483 */
14484TestMethod(id: number): void;
14485}
14486// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSMethodSignature"]}]
14487// Message: Missing JSDoc @param "id" declaration.
14488
14489/**
14490 * A test class.
14491 */
14492abstract class TestClass
14493{
14494/**
14495 * A test method.
14496 */
14497abstract TestFunction(id);
14498}
14499// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSEmptyBodyFunctionExpression"]}]
14500// Message: Missing JSDoc @param "id" declaration.
14501
14502/**
14503 * A test class.
14504 */
14505declare class TestClass
14506{
14507/**
14508 *
14509 */
14510TestMethod(id);
14511}
14512// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSEmptyBodyFunctionExpression"]}]
14513// Message: Missing JSDoc @param "id" declaration.
14514
14515/**
14516 * A test function.
14517 */
14518declare let TestFunction: (id) => void;
14519// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14520// Message: Missing JSDoc @param "id" declaration.
14521
14522/**
14523 * A test function.
14524 */
14525let TestFunction: (id) => void;
14526// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14527// Message: Missing JSDoc @param "id" declaration.
14528
14529/**
14530 * A test function.
14531 */
14532function test(
14533 processor: (id: number) => string
14534) {
14535 return processor(10);
14536}
14537// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14538// Message: Missing JSDoc @param "id" declaration.
14539
14540/**
14541 * A test function.
14542 */
14543let test = (processor: (id: number) => string) =>
14544{
14545 return processor(10);
14546}
14547// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14548// Message: Missing JSDoc @param "id" declaration.
14549
14550class TestClass {
14551 /**
14552 * A class property.
14553 */
14554 public Test: (id: number) => string;
14555}
14556// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14557// Message: Missing JSDoc @param "id" declaration.
14558
14559class TestClass {
14560 /**
14561 * A class method.
14562 */
14563 public TestMethod(): (id: number) => string
14564 {
14565 }
14566}
14567// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14568// Message: Missing JSDoc @param "id" declaration.
14569
14570interface TestInterface {
14571/**
14572 * An interface property.
14573 */
14574public Test: (id: number) => string;
14575}
14576// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14577// Message: Missing JSDoc @param "id" declaration.
14578
14579interface TestInterface {
14580 /**
14581 * An interface method.
14582 */
14583 public TestMethod(): (id: number) => string;
14584}
14585// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14586// Message: Missing JSDoc @param "id" declaration.
14587
14588/**
14589 * A function with return type
14590 */
14591function test(): (id: number) => string;
14592// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14593// Message: Missing JSDoc @param "id" declaration.
14594
14595/**
14596 * A function with return type
14597 */
14598let test = (): (id: number) => string =>
14599{
14600 return (id) => `${id}`;
14601}
14602// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
14603// Message: Missing JSDoc @param "id" declaration.
14604
14605/**
14606 * @param baz
14607 * @param options
14608 */
14609function quux (baz, {foo: bar}) {
14610
14611}
14612// Message: Missing JSDoc @param "options.foo" declaration.
14613
14614class Client {
14615 /**
14616 * Set collection data.
14617 * @param {Object} data The collection data object.
14618 * @param {number} data.last_modified
14619 * @param {Object} options The options object.
14620 * @param {Object} [options.headers] The headers object option.
14621 * @param {Number} [options.retry=0] Number of retries to make
14622 * when faced with transient errors.
14623 * @param {Boolean} [options.safe] The safe option.
14624 * @param {Boolean} [options.patch] The patch option.
14625 * @param {Number} [options.last_modified] The last_modified option.
14626 * @return {Promise<Object, Error>}
14627 */
14628 async setData(
14629 data: { last_modified?: number },
14630 options: {
14631 headers?: Record<string, string>;
14632 safe?: boolean;
14633 retry?: number;
14634 patch?: boolean;
14635 last_modified?: number;
14636 permissions?: [];
14637 } = {}
14638 ) {}
14639}
14640// Message: Missing JSDoc @param "options.permissions" declaration.
14641
14642/**
14643 *
14644 */
14645function quux (foo) {
14646
14647}
14648// "jsdoc/require-param": ["error"|"warn", {"enableFixer":false}]
14649// Message: Missing JSDoc @param "foo" declaration.
14650
14651class Client {
14652 /**
14653 * Set collection data.
14654 * @return {Promise<Object, Error>}
14655 */
14656 async setData(
14657 data: { last_modified?: number }
14658 ) {}
14659}
14660// Message: Missing JSDoc @param "data" declaration.
14661
14662/**
14663 * @param cfg
14664 * @param cfg.num
14665 */
14666function quux ({num, ...extra}) {
14667}
14668// "jsdoc/require-param": ["error"|"warn", {"checkRestProperty":true}]
14669// Message: Missing JSDoc @param "cfg.extra" declaration.
14670
14671/**
14672 * @param cfg
14673 * @param cfg.opts
14674 * @param cfg.opts.num
14675 */
14676function quux ({opts: {num, ...extra}}) {
14677}
14678// "jsdoc/require-param": ["error"|"warn", {"checkRestProperty":true}]
14679// Message: Missing JSDoc @param "cfg.opts.extra" declaration.
14680
14681/**
14682 * @param {GenericArray} cfg
14683 * @param {number} cfg."0"
14684 */
14685function baar ([a, ...extra]) {
14686 //
14687}
14688// Message: Missing JSDoc @param "cfg."1"" declaration.
14689
14690/**
14691 * @param a
14692 */
14693function baar (a, ...extra) {
14694 //
14695}
14696// Message: Missing JSDoc @param "extra" declaration.
14697
14698/**
14699 * Converts an SVGRect into an object.
14700 * @param {SVGRect} bbox - a SVGRect
14701 */
14702const bboxToObj = function ({x, y, width, height}) {
14703 return {x, y, width, height};
14704};
14705// "jsdoc/require-param": ["error"|"warn", {"checkTypesPattern":"SVGRect"}]
14706// Message: Missing JSDoc @param "bbox.x" declaration.
14707
14708/**
14709 * Converts an SVGRect into an object.
14710 * @param {object} bbox - a SVGRect
14711 */
14712const bboxToObj = function ({x, y, width, height}) {
14713 return {x, y, width, height};
14714};
14715// Message: Missing JSDoc @param "bbox.x" declaration.
14716
14717module.exports = class GraphQL {
14718 /**
14719 * @param fetchOptions
14720 * @param cacheKey
14721 */
14722 fetch = ({ url, ...options }, cacheKey) => {
14723 }
14724};
14725// "jsdoc/require-param": ["error"|"warn", {"checkRestProperty":true}]
14726// Message: Missing JSDoc @param "fetchOptions.url" declaration.
14727
14728(function() {
14729 /**
14730 * A function.
14731 */
14732 function f(param) {
14733 return !param;
14734 }
14735})();
14736// Message: Missing JSDoc @param "param" declaration.
14737
14738/**
14739 * Description.
14740 * @param {Object} options
14741 * @param {Object} options.foo
14742 */
14743function quux ({ foo: { bar } }) {}
14744// Message: Missing JSDoc @param "options.foo.bar" declaration.
14745
14746/**
14747 * Description.
14748 * @param {FooBar} options
14749 * @param {FooBar} options.foo
14750 */
14751function quux ({ foo: { bar } }) {}
14752// "jsdoc/require-param": ["error"|"warn", {"checkTypesPattern":"FooBar"}]
14753// Message: Missing JSDoc @param "options.foo.bar" declaration.
14754
14755/**
14756 * Description.
14757 * @param {Object} options
14758 * @param {FooBar} foo
14759 */
14760function quux ({ foo: { bar } }) {}
14761// Message: Missing JSDoc @param "options.foo" declaration.
14762
14763/**
14764 * Description.
14765 * @param {Object} options
14766 * @param options.foo
14767 */
14768function quux ({ foo: { bar } }) {}
14769// Message: Missing JSDoc @param "options.foo.bar" declaration.
14770
14771/**
14772 * Description.
14773 * @param {object} options Options.
14774 * @param {object} options.foo A description.
14775 * @param {object} options.foo.bar
14776 */
14777function foo({ foo: { bar: { baz } }}) {}
14778// Message: Missing JSDoc @param "options.foo.bar.baz" declaration.
14779
14780/**
14781* Returns a number.
14782* @param {Object} props Props.
14783* @param {Object} props.prop Prop.
14784* @return {number} A number.
14785*/
14786export function testFn1 ({ prop = { a: 1, b: 2 } }) {
14787}
14788// "jsdoc/require-param": ["error"|"warn", {"useDefaultObjectProperties":true}]
14789// Message: Missing JSDoc @param "props.prop.a" declaration.
14790````
14791
14792The following patterns are not considered problems:
14793
14794````js
14795/**
14796 * @param foo
14797 */
14798function quux (foo) {
14799
14800}
14801
14802/**
14803 * @param root0
14804 * @param root0.foo
14805 */
14806function quux ({foo}) {
14807
14808}
14809
14810/**
14811 * @param root0
14812 * @param root0.foo
14813 * @param root1
14814 * @param root1.bar
14815 */
14816function quux ({foo}, {bar}) {
14817
14818}
14819
14820/**
14821 * @param arg0
14822 * @param arg0.foo
14823 * @param arg1
14824 * @param arg1.bar
14825 */
14826function quux ({foo}, {bar}) {
14827
14828}
14829// "jsdoc/require-param": ["error"|"warn", {"unnamedRootBase":["arg"]}]
14830
14831/**
14832 * @param arg
14833 * @param arg.foo
14834 * @param config0
14835 * @param config0.bar
14836 * @param config1
14837 * @param config1.baz
14838 */
14839function quux ({foo}, {bar}, {baz}) {
14840
14841}
14842// "jsdoc/require-param": ["error"|"warn", {"unnamedRootBase":["arg","config"]}]
14843
14844/**
14845 * @inheritdoc
14846 */
14847function quux (foo) {
14848
14849}
14850
14851/**
14852 * @inheritDoc
14853 */
14854function quux (foo) {
14855
14856}
14857
14858/**
14859 * @arg foo
14860 */
14861function quux (foo) {
14862
14863}
14864// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
14865
14866/**
14867 * @override
14868 * @param foo
14869 */
14870function quux (foo) {
14871
14872}
14873
14874/**
14875 * @override
14876 */
14877function quux (foo) {
14878
14879}
14880
14881/**
14882 * @override
14883 */
14884class A {
14885 /**
14886 *
14887 */
14888 quux (foo) {
14889
14890 }
14891}
14892
14893/**
14894 * @override
14895 */
14896function quux (foo) {
14897
14898}
14899// Settings: {"jsdoc":{"overrideReplacesDocs":true}}
14900
14901/**
14902 * @implements
14903 */
14904class A {
14905 /**
14906 *
14907 */
14908 quux (foo) {
14909
14910 }
14911}
14912
14913/**
14914 * @implements
14915 */
14916function quux (foo) {
14917
14918}
14919
14920/**
14921 * @implements
14922 */
14923function quux (foo) {
14924
14925}
14926// Settings: {"jsdoc":{"implementsReplacesDocs":true}}
14927
14928/**
14929 * @implements
14930 * @param foo
14931 */
14932function quux (foo) {
14933
14934}
14935
14936/**
14937 * @augments
14938 */
14939function quux (foo) {
14940
14941}
14942// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
14943
14944/**
14945 * @augments
14946 * @param foo
14947 */
14948function quux (foo) {
14949
14950}
14951
14952/**
14953 * @extends
14954 */
14955function quux (foo) {
14956
14957}
14958// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
14959
14960/**
14961 * @extends
14962 * @param foo
14963 */
14964function quux (foo) {
14965
14966}
14967
14968/**
14969 * @augments
14970 */
14971function quux (foo) {
14972
14973}
14974// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
14975
14976/**
14977 * @extends
14978 */
14979function quux (foo) {
14980
14981}
14982// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
14983
14984/**
14985 * @override
14986 */
14987class A {
14988 /**
14989 * @param foo
14990 */
14991 quux (foo) {
14992
14993 }
14994}
14995
14996/**
14997 * @override
14998 */
14999class A {
15000 /**
15001 *
15002 */
15003 quux (foo) {
15004
15005 }
15006}
15007// Settings: {"jsdoc":{"overrideReplacesDocs":true}}
15008
15009/**
15010 * @implements
15011 */
15012class A {
15013 /**
15014 *
15015 */
15016 quux (foo) {
15017
15018 }
15019}
15020// Settings: {"jsdoc":{"implementsReplacesDocs":true}}
15021
15022/**
15023 * @implements
15024 */
15025class A {
15026 /**
15027 * @param foo
15028 */
15029 quux (foo) {
15030
15031 }
15032}
15033
15034/**
15035 * @augments
15036 */
15037class A {
15038 /**
15039 *
15040 */
15041 quux (foo) {
15042
15043 }
15044}
15045// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
15046
15047/**
15048 * @augments
15049 */
15050class A {
15051 /**
15052 * @param foo
15053 */
15054 quux (foo) {
15055
15056 }
15057}
15058
15059/**
15060 * @extends
15061 */
15062class A {
15063 /**
15064 *
15065 */
15066 quux (foo) {
15067
15068 }
15069}
15070// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
15071
15072/**
15073 * @extends
15074 */
15075class A {
15076 /**
15077 * @param foo
15078 */
15079 quux (foo) {
15080
15081 }
15082}
15083
15084/**
15085 * @augments
15086 */
15087class A {
15088 /**
15089 *
15090 */
15091 quux (foo) {
15092
15093 }
15094}
15095// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
15096
15097/**
15098 * @extends
15099 */
15100class A {
15101 /**
15102 *
15103 */
15104 quux (foo) {
15105
15106 }
15107}
15108// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
15109
15110/**
15111 * @internal
15112 */
15113function quux (foo) {
15114
15115}
15116// Settings: {"jsdoc":{"ignoreInternal":true}}
15117
15118/**
15119 * @private
15120 */
15121function quux (foo) {
15122
15123}
15124// Settings: {"jsdoc":{"ignorePrivate":true}}
15125
15126/**
15127 * @access private
15128 */
15129function quux (foo) {
15130
15131}
15132// Settings: {"jsdoc":{"ignorePrivate":true}}
15133
15134// issue 182: optional chaining
15135/** @const {boolean} test */
15136const test = something?.find(_ => _)
15137
15138/** @type {RequestHandler} */
15139function foo(req, res, next) {}
15140
15141/**
15142 * @type {MyCallback}
15143 */
15144function quux () {
15145
15146}
15147// "jsdoc/require-param": ["error"|"warn", {"exemptedBy":["type"]}]
15148
15149/**
15150 * @override
15151 */
15152var A = class {
15153 /**
15154 *
15155 */
15156 quux (foo) {
15157
15158 }
15159}
15160
15161export class SomeClass {
15162 /**
15163 * @param property
15164 */
15165 constructor(private property: string) {}
15166}
15167
15168/**
15169 * Assign the project to an employee.
15170 *
15171 * @param {object} employee - The employee who is responsible for the project.
15172 * @param {string} employee.name - The name of the employee.
15173 * @param {string} employee.department - The employee's department.
15174 */
15175function assign({name, department}) {
15176 // ...
15177}
15178
15179export abstract class StephanPlugin<O, D> {
15180
15181 /**
15182 * Called right after Stephan loads the plugin file.
15183 *
15184 * @example
15185 *```typescript
15186 * type Options = {
15187 * verbose?: boolean;
15188 * token?: string;
15189 * }
15190 * ```
15191 *
15192 * Note that your Options type should only have optional properties...
15193 *
15194 * @param args Arguments compiled and provided by StephanClient.
15195 * @param args.options The options as provided by the user, or an empty object if not provided.
15196 * @param args.client The options as provided by the user, or an empty object if not provided.
15197 * @param defaultOptions The default options as provided by the plugin, or an empty object.
15198 */
15199 public constructor({options, client}: {
15200 options: O;
15201 client: unknown;
15202 }, defaultOptions: D) {
15203
15204 }
15205}
15206
15207/**
15208 *
15209 */
15210function quux (foo) {
15211
15212}
15213// "jsdoc/require-param": ["error"|"warn", {"contexts":["ArrowFunctionExpression"]}]
15214
15215/**
15216* A function with return type
15217*
15218* @param id
15219*/
15220let test = (): (id: number) => string =>
15221{
15222 return (id) => `${id}`;
15223}
15224// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
15225
15226/** @abstract */
15227class base {
15228/** @param {boolean} arg0 */
15229constructor(arg0) {}
15230}
15231
15232class foo extends base {
15233/** @inheritDoc */
15234constructor(arg0) {
15235super(arg0);
15236this.arg0 = arg0;
15237}
15238}
15239// Settings: {"jsdoc":{"mode":"closure"}}
15240
15241 export abstract class StephanPlugin<O, D> {
15242
15243 /**
15244 * Called right after Stephan loads the plugin file.
15245 *
15246 * @example
15247 *```typescript
15248 * type Options = {
15249 * verbose?: boolean;
15250 * token?: string;
15251 * }
15252 * ```
15253 *
15254 * Note that your Options type should only have optional properties...
15255 *
15256 * @param args Arguments compiled and provided by StephanClient.
15257 * @param args.options The options as provided by the user, or an empty object if not provided.
15258 * @param args.client The options as provided by the user, or an empty object if not provided.
15259 * @param args.client.name The name of the client.
15260 * @param defaultOptions The default options as provided by the plugin, or an empty object.
15261 */
15262 public constructor({ options, client: { name } }: {
15263 options: O;
15264 client: { name: string };
15265 }, defaultOptions: D) {
15266
15267 }
15268}
15269
15270/**
15271* @param {string} cb
15272*/
15273function createGetter (cb) {
15274 return function (...args) {
15275 cb();
15276 };
15277}
15278
15279/**
15280 * @param cfg
15281 * @param cfg.num
15282 */
15283function quux ({num, ...extra}) {
15284}
15285
15286/**
15287 * @param {GenericArray} cfg
15288 * @param {number} cfg."0"
15289 */
15290function baar ([a, ...extra]) {
15291 //
15292}
15293// "jsdoc/require-param": ["error"|"warn", {"enableRestElementFixer":false}]
15294
15295/**
15296 * @param a
15297 */
15298function baar (a, ...extra) {
15299 //
15300}
15301// "jsdoc/require-param": ["error"|"warn", {"enableRestElementFixer":false}]
15302
15303/**
15304* Converts an SVGRect into an object.
15305* @param {SVGRect} bbox - a SVGRect
15306*/
15307const bboxToObj = function ({x, y, width, height}) {
15308 return {x, y, width, height};
15309};
15310
15311/**
15312* Converts an SVGRect into an object.
15313* @param {object} bbox - a SVGRect
15314*/
15315const bboxToObj = function ({x, y, width, height}) {
15316 return {x, y, width, height};
15317};
15318// "jsdoc/require-param": ["error"|"warn", {"checkTypesPattern":"SVGRect"}]
15319
15320class CSS {
15321 /**
15322 * Set one or more CSS properties for the set of matched elements.
15323 *
15324 * @param {Object} propertyObject - An object of property-value pairs to set.
15325 */
15326 setCssObject(propertyObject: {[key: string]: string | number}): void {
15327 }
15328}
15329
15330/**
15331 * @param foo
15332 * @param bar
15333 * @param cfg
15334 */
15335function quux (foo, bar, {baz}) {
15336
15337}
15338// "jsdoc/require-param": ["error"|"warn", {"checkDestructured":false}]
15339
15340/**
15341 * @param foo
15342 * @param bar
15343 */
15344function quux (foo, bar, {baz}) {
15345
15346}
15347// "jsdoc/require-param": ["error"|"warn", {"checkDestructuredRoots":false}]
15348
15349/**
15350 * @param root
15351 * @param root.foo
15352 */
15353function quux ({"foo": bar}) {
15354
15355}
15356
15357/**
15358 * @param root
15359 * @param root."foo"
15360 */
15361function quux ({foo: bar}) {
15362
15363}
15364
15365/**
15366 * Description.
15367 * @param {string} b Description `/**`.
15368 */
15369module.exports = function a(b) {
15370 console.info(b);
15371};
15372
15373/**
15374 * Description.
15375 * @param {Object} options Options.
15376 * @param {FooBar} options.foo foo description.
15377 */
15378function quux ({ foo: { bar } }) {}
15379
15380/**
15381 * Description.
15382 * @param {FooBar} options
15383 * @param {Object} options.foo
15384 */
15385function quux ({ foo: { bar } }) {}
15386// "jsdoc/require-param": ["error"|"warn", {"checkTypesPattern":"FooBar"}]
15387
15388/**
15389 * @param obj
15390 * @param obj.data
15391 * @param obj.data."0"
15392 * @param obj.data."1"
15393 * @param obj.data."2"
15394 * @param obj.defaulting
15395 * @param obj.defaulting."0"
15396 * @param obj.defaulting."1"
15397 */
15398function Item({
15399 data: [foo, bar, ...baz],
15400 defaulting: [quux, xyz] = []
15401}) {
15402}
15403
15404/**
15405* Returns a number.
15406* @param {Object} props Props.
15407* @param {Object} props.prop Prop.
15408* @return {number} A number.
15409*/
15410export function testFn1 ({ prop = { a: 1, b: 2 } }) {
15411}
15412// "jsdoc/require-param": ["error"|"warn", {"useDefaultObjectProperties":false}]
15413````
15414
15415
15416<a name="eslint-plugin-jsdoc-rules-require-property"></a>
15417### <code>require-property</code>
15418
15419Requires that all `@typedef` and `@namespace` tags have `@property`
15420when their type is a plain `object`, `Object`, or `PlainObject`.
15421
15422Note that any other type, including a subtype of object such as
15423`object<string, string>`, will not be reported.
15424
15425<a name="eslint-plugin-jsdoc-rules-require-property-fixer-2"></a>
15426#### Fixer
15427
15428The fixer for `require-property` will add an empty `@property`.
15429
15430|||
15431|---|---|
15432|Context|Everywhere|
15433|Tags|`typedef`, `namespace`|
15434|Recommended|true|
15435
15436The following patterns are considered problems:
15437
15438````js
15439/**
15440 * @typedef {object} SomeTypedef
15441 */
15442// Message: Missing JSDoc @property.
15443
15444class Test {
15445 /**
15446 * @typedef {object} SomeTypedef
15447 */
15448 quux () {}
15449}
15450// Message: Missing JSDoc @property.
15451
15452/**
15453 * @typedef {PlainObject} SomeTypedef
15454 */
15455// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
15456// Message: Missing JSDoc @prop.
15457
15458/**
15459 * @namespace {Object} SomeName
15460 */
15461// Message: Missing JSDoc @property.
15462````
15463
15464The following patterns are not considered problems:
15465
15466````js
15467/**
15468 *
15469 */
15470
15471/**
15472 * @property
15473 */
15474
15475/**
15476 * @typedef {Object} SomeTypedef
15477 * @property {SomeType} propName Prop description
15478 */
15479
15480/**
15481 * @typedef {object} SomeTypedef
15482 * @prop {SomeType} propName Prop description
15483 */
15484// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
15485
15486/**
15487 * @typedef {object} SomeTypedef
15488 * @property
15489 * // arbitrary property content
15490 */
15491
15492/**
15493 * @typedef {object<string, string>} SomeTypedef
15494 */
15495
15496/**
15497 * @typedef {string} SomeTypedef
15498 */
15499
15500/**
15501 * @namespace {object} SomeName
15502 * @property {SomeType} propName Prop description
15503 */
15504
15505/**
15506 * @namespace {object} SomeName
15507 * @property
15508 * // arbitrary property content
15509 */
15510
15511/**
15512 * @typedef {object} SomeTypedef
15513 * @property someProp
15514 * @property anotherProp This with a description
15515 * @property {anotherType} yetAnotherProp This with a type and desc.
15516 */
15517function quux () {
15518
15519}
15520````
15521
15522
15523<a name="eslint-plugin-jsdoc-rules-require-property-description"></a>
15524### <code>require-property-description</code>
15525
15526Requires that each `@property` tag has a `description` value.
15527
15528|||
15529|---|---|
15530|Context|everywhere|
15531|Tags|`property`|
15532|Aliases|`prop`|
15533|Recommended|true|
15534
15535The following patterns are considered problems:
15536
15537````js
15538/**
15539 * @typedef {SomeType} SomeTypedef
15540 * @property foo
15541 */
15542// Message: Missing JSDoc @property "foo" description.
15543
15544/**
15545 * @typedef {SomeType} SomeTypedef
15546 * @prop foo
15547 */
15548// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
15549// Message: Missing JSDoc @prop "foo" description.
15550
15551/**
15552 * @typedef {SomeType} SomeTypedef
15553 * @property foo
15554 */
15555// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
15556// Message: Unexpected tag `@property`
15557````
15558
15559The following patterns are not considered problems:
15560
15561````js
15562/**
15563 * @typedef {SomeType} SomeTypedef
15564 */
15565
15566/**
15567 * @typedef {SomeType} SomeTypedef
15568 * @property foo Foo.
15569 */
15570
15571/**
15572 * @namespace {SomeType} SomeName
15573 * @property foo Foo.
15574 */
15575
15576/**
15577 * @class
15578 * @property foo Foo.
15579 */
15580
15581/**
15582 * Typedef with multi-line property type.
15583 *
15584 * @typedef {object} MyType
15585 * @property {function(
15586 * number
15587 * )} numberEater Method which takes a number.
15588 */
15589````
15590
15591
15592<a name="eslint-plugin-jsdoc-rules-require-property-name"></a>
15593### <code>require-property-name</code>
15594
15595Requires that all function `@property` tags have names.
15596
15597|||
15598|---|---|
15599|Context|everywhere|
15600|Tags|`property`|
15601|Aliases|`prop`|
15602|Recommended|true|
15603
15604The following patterns are considered problems:
15605
15606````js
15607/**
15608 * @typedef {SomeType} SomeTypedef
15609 * @property
15610 */
15611// Message: There must be an identifier after @property type.
15612
15613/**
15614 * @typedef {SomeType} SomeTypedef
15615 * @property {string}
15616 */
15617// Message: There must be an identifier after @property tag.
15618
15619/**
15620 * @typedef {SomeType} SomeTypedef
15621 * @property foo
15622 */
15623// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
15624// Message: Unexpected tag `@property`
15625````
15626
15627The following patterns are not considered problems:
15628
15629````js
15630/**
15631 * @typedef {SomeType} SomeTypedef
15632 * @property foo
15633 */
15634
15635/**
15636 * @typedef {SomeType} SomeTypedef
15637 * @property {string} foo
15638 */
15639
15640/**
15641 * @namespace {SomeType} SomeName
15642 * @property {string} foo
15643 */
15644
15645/**
15646 * @class
15647 * @property {string} foo
15648 */
15649````
15650
15651
15652<a name="eslint-plugin-jsdoc-rules-require-property-type"></a>
15653### <code>require-property-type</code>
15654
15655Requires that each `@property` tag has a `type` value.
15656
15657|||
15658|---|---|
15659|Context|everywhere|
15660|Tags|`property`|
15661|Aliases|`prop`|
15662|Recommended|true|
15663
15664The following patterns are considered problems:
15665
15666````js
15667/**
15668 * @typedef {SomeType} SomeTypedef
15669 * @property foo
15670 */
15671// Message: Missing JSDoc @property "foo" type.
15672
15673/**
15674 * @typedef {SomeType} SomeTypedef
15675 * @prop foo
15676 */
15677// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
15678// Message: Missing JSDoc @prop "foo" type.
15679
15680/**
15681 * @typedef {SomeType} SomeTypedef
15682 * @property foo
15683 */
15684// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
15685// Message: Unexpected tag `@property`
15686````
15687
15688The following patterns are not considered problems:
15689
15690````js
15691/**
15692 * @typedef {SomeType} SomeTypedef
15693 */
15694
15695/**
15696 * @typedef {SomeType} SomeTypedef
15697 * @property {number} foo
15698 */
15699
15700/**
15701 * @namespace {SomeType} SomeName
15702 * @property {number} foo
15703 */
15704
15705/**
15706 * @class
15707 * @property {number} foo
15708 */
15709````
15710
15711
15712<a name="eslint-plugin-jsdoc-rules-require-returns-check"></a>
15713### <code>require-returns-check</code>
15714
15715Requires a return statement (or non-`undefined` Promise resolve value) in
15716function bodies if a `@returns` tag (without a `void` or `undefined` type)
15717is specified in the function's jsdoc comment.
15718
15719Will also report `@returns {void}` and `@returns {undefined}` if `exemptAsync`
15720is set to `false` no non-`undefined` returned or resolved value is found.
15721
15722Will also report if multiple `@returns` tags are present.
15723
15724<a name="eslint-plugin-jsdoc-rules-require-returns-check-options-32"></a>
15725#### Options
15726
15727- `exemptAsync` - By default, functions which return a `Promise` that are not
15728 detected as resolving with a non-`undefined` value and `async` functions
15729 (even ones that do not explicitly return a value, as these are returning a
15730 `Promise` implicitly) will be exempted from reporting by this rule.
15731 If you wish to insist that only `Promise`'s which resolve to
15732 non-`undefined` values or `async` functions with explicit `return`'s will
15733 be exempted from reporting (i.e., that `async` functions can be reported
15734 if they lack an explicit (non-`undefined`) `return` when a `@returns` is
15735 present), you can set `exemptAsync` to `false` on the options object.
15736- `reportMissingReturnForUndefinedTypes` - If `true` and no return or
15737 resolve value is found, this setting will even insist that reporting occur
15738 with `void` or `undefined` (including as an indicated `Promise` type).
15739 Unlike `require-returns`, with this option in the rule, one can
15740 *discourage* the labeling of `undefined` types. Defaults to `false`.
15741
15742|||
15743|---|---|
15744|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
15745|Tags|`returns`|
15746|Aliases|`return`|
15747|Options|`exemptAsync`, `reportMissingReturnForUndefinedTypes`|
15748|Recommended|true|
15749
15750The following patterns are considered problems:
15751
15752````js
15753/**
15754 * @returns
15755 */
15756function quux (foo) {
15757
15758}
15759// Message: JSDoc @returns declaration present but return expression not available in function.
15760
15761/**
15762 * @return
15763 */
15764function quux (foo) {
15765
15766}
15767// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
15768// Message: JSDoc @return declaration present but return expression not available in function.
15769
15770/**
15771 * @returns
15772 */
15773const quux = () => {}
15774// Message: JSDoc @returns declaration present but return expression not available in function.
15775
15776/**
15777 * @returns {undefined} Foo.
15778 * @returns {String} Foo.
15779 */
15780function quux () {
15781
15782 return foo;
15783}
15784// Message: Found more than one @returns declaration.
15785
15786const language = {
15787 /**
15788 * @param {string} name
15789 * @returns {string}
15790 */
15791 get name() {
15792 this._name = name;
15793 }
15794}
15795// Message: JSDoc @returns declaration present but return expression not available in function.
15796
15797class Foo {
15798 /**
15799 * @returns {string}
15800 */
15801 bar () {
15802 }
15803}
15804// Message: JSDoc @returns declaration present but return expression not available in function.
15805
15806/**
15807 * @returns
15808 */
15809function quux () {
15810
15811}
15812// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
15813// Message: Unexpected tag `@returns`
15814
15815/**
15816 * @returns {string}
15817 */
15818function f () {
15819 function g() {
15820 return 'foo'
15821 }
15822
15823 () => {
15824 return 5
15825 }
15826}
15827// Message: JSDoc @returns declaration present but return expression not available in function.
15828
15829/**
15830 * @returns {Promise<void>}
15831 */
15832async function quux() {}
15833// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
15834// Message: JSDoc @returns declaration present but return expression not available in function.
15835
15836/**
15837 * @returns {Promise<void>}
15838 */
15839function quux() {
15840 return new Promise((resolve, reject) => {})
15841}
15842// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
15843// Message: JSDoc @returns declaration present but return expression not available in function.
15844
15845/**
15846 * @returns {Promise<void>}
15847 */
15848function quux() {
15849 return new Promise((resolve, reject) => {
15850 setTimeout(() => {
15851 resolve();
15852 });
15853 })
15854}
15855// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
15856// Message: JSDoc @returns declaration present but return expression not available in function.
15857
15858/**
15859 * Description.
15860 * @returns {string}
15861 */
15862async function foo() {
15863 return new Promise(resolve => resolve());
15864}
15865// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
15866// Message: JSDoc @returns declaration present but return expression not available in function.
15867
15868/**
15869 * Description.
15870 * @returns {void}
15871 */
15872async function foo() {
15873 return new Promise(resolve => resolve());
15874}
15875// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false,"reportMissingReturnForUndefinedTypes":true}]
15876// Message: JSDoc @returns declaration present but return expression not available in function.
15877
15878/**
15879 * @returns { void } Foo.
15880 */
15881function quux () {}
15882// "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
15883// Message: JSDoc @returns declaration present but return expression not available in function.
15884````
15885
15886The following patterns are not considered problems:
15887
15888````js
15889/**
15890 * @returns Foo.
15891 */
15892function quux () {
15893
15894 return foo;
15895}
15896
15897/**
15898 * @returns {string} Foo.
15899 */
15900function quux () {
15901
15902 return foo;
15903}
15904
15905/**
15906 * @returns {string} Foo.
15907 */
15908function quux () {
15909
15910 return foo;
15911}
15912
15913/**
15914 *
15915 */
15916function quux () {
15917}
15918
15919/**
15920 * @returns {*} Foo.
15921 */
15922const quux = () => foo;
15923
15924/**
15925 * @returns {undefined} Foo.
15926 */
15927function quux () {}
15928
15929/**
15930 * @returns { void } Foo.
15931 */
15932function quux () {}
15933
15934/**
15935 * @returns {Promise<void>}
15936 */
15937async function quux() {}
15938
15939/**
15940 * @returns {Promise<void>}
15941 */
15942const quux = async function () {}
15943
15944/**
15945 * @returns {Promise<void>}
15946 */
15947const quux = async () => {}
15948
15949/**
15950 * @returns Foo.
15951 * @abstract
15952 */
15953function quux () {
15954 throw new Error('must be implemented by subclass!');
15955}
15956
15957/**
15958 * @returns Foo.
15959 * @virtual
15960 */
15961function quux () {
15962 throw new Error('must be implemented by subclass!');
15963}
15964
15965/**
15966 * @returns Foo.
15967 * @constructor
15968 */
15969function quux () {
15970}
15971
15972/**
15973 * @interface
15974 */
15975class Foo {
15976 /**
15977 * @returns {string}
15978 */
15979 bar () {
15980 }
15981}
15982
15983/**
15984 * @record
15985 */
15986class Foo {
15987 /**
15988 * @returns {string}
15989 */
15990 bar () {
15991 }
15992}
15993// Settings: {"jsdoc":{"mode":"closure"}}
15994
15995/**
15996 * @returns {undefined} Foo.
15997 */
15998function quux () {
15999}
16000
16001/**
16002 * @returns {void} Foo.
16003 */
16004function quux () {
16005}
16006
16007/**
16008 * @returns {void} Foo.
16009 */
16010function quux () {
16011 return undefined;
16012}
16013
16014/**
16015 * @returns {void} Foo.
16016 */
16017function quux () {
16018 return;
16019}
16020
16021/**
16022 *
16023 */
16024function quux () {
16025 return undefined;
16026}
16027
16028/**
16029 *
16030 */
16031function quux () {
16032 return;
16033}
16034
16035/**
16036 * @returns {true}
16037 */
16038function quux () {
16039 try {
16040 return true;
16041 } catch (err) {
16042 }
16043 return;
16044}
16045
16046/**
16047 * @returns {true}
16048 */
16049function quux () {
16050 try {
16051 } finally {
16052 return true;
16053 }
16054 return;
16055}
16056
16057/**
16058 * @returns {true}
16059 */
16060function quux () {
16061 try {
16062 return;
16063 } catch (err) {
16064 }
16065 return true;
16066}
16067
16068/**
16069 * @returns {true}
16070 */
16071function quux () {
16072 try {
16073 something();
16074 } catch (err) {
16075 return true;
16076 }
16077 return;
16078}
16079
16080/**
16081 * @returns {true}
16082 */
16083function quux () {
16084 switch (true) {
16085 case 'abc':
16086 return true;
16087 }
16088 return;
16089}
16090
16091/**
16092 * @returns {true}
16093 */
16094function quux () {
16095 switch (true) {
16096 case 'abc':
16097 return;
16098 }
16099 return true;
16100}
16101
16102/**
16103 * @returns {true}
16104 */
16105function quux () {
16106 for (const i of abc) {
16107 return true;
16108 }
16109 return;
16110}
16111
16112/**
16113 * @returns {true}
16114 */
16115function quux () {
16116 for (const a in b) {
16117 return true;
16118 }
16119}
16120
16121/**
16122 * @returns {true}
16123 */
16124function quux () {
16125 for (let i=0; i<n; i+=1) {
16126 return true;
16127 }
16128}
16129
16130/**
16131 * @returns {true}
16132 */
16133function quux () {
16134 while(true) {
16135 return true
16136 }
16137}
16138
16139/**
16140 * @returns {true}
16141 */
16142function quux () {
16143 do {
16144 return true
16145 }
16146 while(true)
16147}
16148
16149/**
16150 * @returns {true}
16151 */
16152function quux () {
16153 if (true) {
16154 return;
16155 }
16156 return true;
16157}
16158
16159/**
16160 * @returns {true}
16161 */
16162function quux () {
16163 if (true) {
16164 return true;
16165 }
16166}
16167
16168/**
16169 * @returns {true}
16170 */
16171function quux () {
16172 var a = {};
16173 with (a) {
16174 return true;
16175 }
16176}
16177
16178/**
16179 * @returns {true}
16180 */
16181function quux () {
16182 if (true) {
16183 return;
16184 } else {
16185 return true;
16186 }
16187 return;
16188}
16189
16190/**
16191 * @returns {Promise<number>}
16192 */
16193async function quux() {
16194 return 5;
16195}
16196
16197/**
16198 * @returns {Promise<number>}
16199 */
16200async function quux() {
16201 return 5;
16202}
16203// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
16204
16205/**
16206 * @returns {Promise<void>}
16207 */
16208function quux() {
16209 return new Promise((resolve, reject) => {
16210 setTimeout(() => {
16211 resolve(true);
16212 });
16213 })
16214}
16215// "jsdoc/require-returns-check": ["error"|"warn", {"exemptAsync":false}]
16216
16217/**
16218 * Description.
16219 * @returns {void}
16220 */
16221async function foo() {
16222 return new Promise(resolve => resolve());
16223}
16224// "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
16225
16226/**
16227 * @returns { void } Foo.
16228 */
16229function quux () {
16230 return undefined;
16231}
16232// "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
16233
16234/**
16235 * @returns { string } Foo.
16236 */
16237function quux () {
16238 return 'abc';
16239}
16240// "jsdoc/require-returns-check": ["error"|"warn", {"reportMissingReturnForUndefinedTypes":true}]
16241````
16242
16243
16244<a name="eslint-plugin-jsdoc-rules-require-returns-description"></a>
16245### <code>require-returns-description</code>
16246
16247Requires that the `@returns` tag has a `description` value. The error
16248will not be reported if the return value is `void` or `undefined`
16249or if it is `Promise<void>` or `Promise<undefined>`.
16250
16251<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-33"></a>
16252#### Options
16253
16254<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-33-contexts-12"></a>
16255##### <code>contexts</code>
16256
16257Set this to an array of strings representing the AST context (or an object with
16258`context` and `comment` properties) where you wish the rule to be applied.
16259Overrides the default contexts (see below). Set to `"any"` if you want
16260the rule to apply to any jsdoc block throughout your files (as is necessary
16261for finding function blocks not attached to a function declaration or
16262expression, i.e., `@callback` or `@function` (or its aliases `@func` or
16263`@method`) (including those associated with an `@interface`).
16264
16265See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
16266section of our README for more on the expected format.
16267
16268|||
16269|---|---|
16270|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
16271|Tags|`returns`|
16272|Aliases|`return`|
16273|Recommended|true|
16274|Options|`contexts`|
16275
16276The following patterns are considered problems:
16277
16278````js
16279/**
16280 * @returns
16281 */
16282function quux (foo) {
16283
16284}
16285// Message: Missing JSDoc @returns description.
16286
16287/**
16288 * @returns {string}
16289 */
16290function quux (foo) {
16291
16292}
16293// Message: Missing JSDoc @returns description.
16294
16295/**
16296 * @returns {string}
16297 */
16298function quux (foo) {
16299
16300}
16301// "jsdoc/require-returns-description": ["error"|"warn", {"contexts":["any"]}]
16302// Message: Missing JSDoc @returns description.
16303
16304/**
16305 * @function
16306 * @returns {string}
16307 */
16308// "jsdoc/require-returns-description": ["error"|"warn", {"contexts":["any"]}]
16309// Message: Missing JSDoc @returns description.
16310
16311/**
16312 * @callback
16313 * @returns {string}
16314 */
16315// "jsdoc/require-returns-description": ["error"|"warn", {"contexts":["any"]}]
16316// Message: Missing JSDoc @returns description.
16317
16318/**
16319 * @return
16320 */
16321function quux (foo) {
16322
16323}
16324// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
16325// Message: Missing JSDoc @return description.
16326
16327/**
16328 * @returns
16329 */
16330function quux () {
16331
16332}
16333// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
16334// Message: Unexpected tag `@returns`
16335````
16336
16337The following patterns are not considered problems:
16338
16339````js
16340/**
16341 *
16342 */
16343function quux () {
16344
16345}
16346
16347/**
16348 * @returns Foo.
16349 */
16350function quux () {
16351
16352}
16353
16354/**
16355 * @returns Foo.
16356 */
16357function quux () {
16358
16359}
16360// "jsdoc/require-returns-description": ["error"|"warn", {"contexts":["any"]}]
16361
16362/**
16363 * @returns {undefined}
16364 */
16365function quux () {
16366
16367}
16368
16369/**
16370 * @returns {void}
16371 */
16372function quux () {
16373
16374}
16375
16376/**
16377 * @returns {Promise<void>}
16378 */
16379function quux () {
16380
16381}
16382
16383/**
16384 * @returns {Promise<undefined>}
16385 */
16386function quux () {
16387
16388}
16389
16390/**
16391 * @function
16392 * @returns
16393 */
16394
16395/**
16396 * @callback
16397 * @returns
16398 */
16399````
16400
16401
16402<a name="eslint-plugin-jsdoc-rules-require-returns-type"></a>
16403### <code>require-returns-type</code>
16404
16405Requires that `@returns` tag has `type` value.
16406
16407<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-34"></a>
16408#### Options
16409
16410<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-34-contexts-13"></a>
16411##### <code>contexts</code>
16412
16413Set this to an array of strings representing the AST context (or an object with
16414`context` and `comment` properties) where you wish the rule to be applied.
16415Overrides the default contexts (see below). Set to `"any"` if you want
16416the rule to apply to any jsdoc block throughout your files (as is necessary
16417for finding function blocks not attached to a function declaration or
16418expression, i.e., `@callback` or `@function` (or its aliases `@func` or
16419`@method`) (including those associated with an `@interface`).
16420
16421See the ["AST and Selectors"](#eslint-plugin-jsdoc-advanced-ast-and-selectors)
16422section of our README for more on the expected format.
16423
16424|||
16425|---|---|
16426|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
16427|Tags|`returns`|
16428|Aliases|`return`|
16429|Recommended|true|
16430|Options|`contexts`|
16431
16432The following patterns are considered problems:
16433
16434````js
16435/**
16436 * @returns
16437 */
16438function quux () {
16439
16440}
16441// Message: Missing JSDoc @returns type.
16442
16443/**
16444 * @returns Foo.
16445 */
16446function quux () {
16447
16448}
16449// Message: Missing JSDoc @returns type.
16450
16451/**
16452 * @returns Foo.
16453 */
16454function quux () {
16455
16456}
16457// "jsdoc/require-returns-type": ["error"|"warn", {"contexts":["any"]}]
16458// Message: Missing JSDoc @returns type.
16459
16460/**
16461 * @function
16462 * @returns Foo.
16463 */
16464// "jsdoc/require-returns-type": ["error"|"warn", {"contexts":["any"]}]
16465// Message: Missing JSDoc @returns type.
16466
16467/**
16468 * @callback
16469 * @returns Foo.
16470 */
16471// "jsdoc/require-returns-type": ["error"|"warn", {"contexts":["any"]}]
16472// Message: Missing JSDoc @returns type.
16473
16474/**
16475 * @return Foo.
16476 */
16477function quux () {
16478
16479}
16480// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
16481// Message: Missing JSDoc @return type.
16482
16483/**
16484 * @returns
16485 */
16486function quux () {
16487
16488}
16489// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
16490// Message: Unexpected tag `@returns`
16491````
16492
16493The following patterns are not considered problems:
16494
16495````js
16496/**
16497 * @returns {number}
16498 */
16499function quux () {
16500
16501}
16502
16503/**
16504 * @returns {number}
16505 */
16506function quux () {
16507
16508}
16509// "jsdoc/require-returns-type": ["error"|"warn", {"contexts":["any"]}]
16510
16511/**
16512 * @function
16513 * @returns Foo.
16514 */
16515
16516/**
16517 * @callback
16518 * @returns Foo.
16519 */
16520````
16521
16522
16523<a name="eslint-plugin-jsdoc-rules-require-returns"></a>
16524### <code>require-returns</code>
16525
16526Requires that returns are documented.
16527
16528Will also report if multiple `@returns` tags are present.
16529
16530<a name="eslint-plugin-jsdoc-rules-require-returns-options-35"></a>
16531#### Options
16532
16533- `checkConstructors` - A value indicating whether `constructor`s should
16534 be checked for `@returns` tags. Defaults to `false`.
16535- `checkGetters` - Boolean to determine whether getter methods should
16536 be checked for `@returns` tags. Defaults to `true`.
16537- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
16538 document block avoids the need for a `@returns`. Defaults to an array
16539 with `inheritdoc`. If you set this array, it will overwrite the default,
16540 so be sure to add back `inheritdoc` if you wish its presence to cause
16541 exemption of the rule.
16542- `forceRequireReturn` - Set to `true` to always insist on
16543 `@returns` documentation regardless of implicit or explicit `return`'s
16544 in the function. May be desired to flag that a project is aware of an
16545 `undefined`/`void` return. Defaults to `false`.
16546- `forceReturnsWithAsync` - By default `async` functions that do not explicitly
16547 return a value pass this rule as an `async` function will always return a
16548 `Promise`, even if the `Promise` resolves to void. You can force all
16549 `async` functions (including ones with an explicit `Promise` but no
16550 detected non-`undefined` `resolve` value) to require `@return`
16551 documentation by setting `forceReturnsWithAsync` to `true` on the options
16552 object. This may be useful for flagging that there has been consideration
16553 of return type. Defaults to `false`.
16554- `contexts` - Set this to an array of strings representing the AST context
16555 (or an object with `context` and `comment` properties) where you wish
16556 the rule to be applied.
16557 Overrides the default contexts (see below). Set to `"any"` if you want
16558 the rule to apply to any jsdoc block throughout your files (as is necessary
16559 for finding function blocks not attached to a function declaration or
16560 expression, i.e., `@callback` or `@function` (or its aliases `@func` or
16561 `@method`) (including those associated with an `@interface`). This
16562 rule will only apply on non-default contexts when there is such a tag
16563 present and the `forceRequireReturn` option is set or if the
16564 `forceReturnsWithAsync` option is set with a present `@async` tag
16565 (since we are not checking against the actual `return` values in these
16566 cases).
16567
16568| | |
16569| -------- | ------- |
16570| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
16571| Tags | `returns` |
16572| Aliases | `return` |
16573|Recommended|true|
16574| Options | `checkConstructors`, `checkGetters`, `contexts`, `exemptedBy`, `forceRequireReturn`, `forceReturnsWithAsync` |
16575| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` |
16576
16577The following patterns are considered problems:
16578
16579````js
16580/**
16581 *
16582 */
16583function quux (foo) {
16584
16585 return foo;
16586}
16587// Message: Missing JSDoc @returns declaration.
16588
16589/**
16590 *
16591 */
16592const foo = () => ({
16593 bar: 'baz'
16594})
16595// Message: Missing JSDoc @returns declaration.
16596
16597/**
16598 *
16599 */
16600const foo = bar=>({ bar })
16601// Message: Missing JSDoc @returns declaration.
16602
16603/**
16604 *
16605 */
16606const foo = bar => bar.baz()
16607// Message: Missing JSDoc @returns declaration.
16608
16609/**
16610 *
16611 */
16612function quux (foo) {
16613
16614 return foo;
16615}
16616// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
16617// Message: Missing JSDoc @return declaration.
16618
16619/**
16620 *
16621 */
16622async function quux() {
16623}
16624// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
16625// Message: Missing JSDoc @returns declaration.
16626
16627/**
16628 *
16629 */
16630const quux = async function () {}
16631// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
16632// Message: Missing JSDoc @returns declaration.
16633
16634/**
16635 *
16636 */
16637const quux = async () => {}
16638// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
16639// Message: Missing JSDoc @returns declaration.
16640
16641/**
16642 *
16643 */
16644async function quux () {}
16645// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
16646// Message: Missing JSDoc @returns declaration.
16647
16648/**
16649 *
16650 */
16651function quux () {
16652}
16653// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
16654// Message: Missing JSDoc @returns declaration.
16655
16656/**
16657 *
16658 */
16659function quux () {
16660}
16661// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceRequireReturn":true}]
16662// Message: Missing JSDoc @returns declaration.
16663
16664/**
16665 * @function
16666 */
16667// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceRequireReturn":true}]
16668// Message: Missing JSDoc @returns declaration.
16669
16670/**
16671 * @callback
16672 */
16673// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceRequireReturn":true}]
16674// Message: Missing JSDoc @returns declaration.
16675
16676const language = {
16677 /**
16678 * @param {string} name
16679 */
16680 get name() {
16681 return this._name;
16682 }
16683}
16684// Message: Missing JSDoc @returns declaration.
16685
16686/**
16687 *
16688 */
16689async function quux () {
16690}
16691// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
16692// Message: Missing JSDoc @returns declaration.
16693
16694/**
16695 * @function
16696 * @async
16697 */
16698// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceReturnsWithAsync":true}]
16699// Message: Missing JSDoc @returns declaration.
16700
16701/**
16702 * @callback
16703 * @async
16704 */
16705// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceReturnsWithAsync":true}]
16706// Message: Missing JSDoc @returns declaration.
16707
16708/**
16709 * @returns {undefined}
16710 * @returns {void}
16711 */
16712function quux (foo) {
16713
16714 return foo;
16715}
16716// Message: Found more than one @returns declaration.
16717
16718/**
16719 * @returns
16720 */
16721function quux () {
16722
16723}
16724// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
16725// Message: Unexpected tag `@returns`
16726
16727/**
16728 * @param foo
16729 */
16730function quux (foo) {
16731 return 'bar';
16732}
16733// "jsdoc/require-returns": ["error"|"warn", {"exemptedBy":["notPresent"]}]
16734// Message: Missing JSDoc @returns declaration.
16735
16736/**
16737 * @param {array} a
16738 */
16739async function foo(a) {
16740 return;
16741}
16742// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
16743// Message: Missing JSDoc @returns declaration.
16744
16745/**
16746 * @param {array} a
16747 */
16748async function foo(a) {
16749 return Promise.all(a);
16750}
16751// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
16752// Message: Missing JSDoc @returns declaration.
16753
16754class foo {
16755 /** gets bar */
16756 get bar() {
16757 return 0;
16758 }
16759}
16760// "jsdoc/require-returns": ["error"|"warn", {"checkGetters":true}]
16761// Message: Missing JSDoc @returns declaration.
16762
16763class TestClass {
16764 /**
16765 *
16766 */
16767 constructor() {
16768 return new Map();
16769 }
16770}
16771// "jsdoc/require-returns": ["error"|"warn", {"checkConstructors":true}]
16772// Message: Missing JSDoc @returns declaration.
16773
16774class TestClass {
16775 /**
16776 *
16777 */
16778 get Test() {
16779 return 0;
16780 }
16781}
16782// "jsdoc/require-returns": ["error"|"warn", {"checkGetters":true}]
16783// Message: Missing JSDoc @returns declaration.
16784
16785class quux {
16786 /**
16787 *
16788 */
16789 quux () {
16790 }
16791}
16792// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceRequireReturn":true}]
16793// Message: Missing JSDoc @returns declaration.
16794
16795/**
16796 * @param {array} a
16797 */
16798async function foo(a) {
16799 return Promise.all(a);
16800}
16801// Message: Missing JSDoc @returns declaration.
16802
16803/**
16804 *
16805 */
16806function quux (foo) {
16807
16808 return new Promise(function (resolve, reject) {
16809 resolve(foo);
16810 });
16811}
16812// Message: Missing JSDoc @returns declaration.
16813
16814/**
16815 *
16816 */
16817function quux (foo) {
16818
16819 return new Promise(function (resolve, reject) {
16820 setTimeout(() => {
16821 resolve(true);
16822 });
16823 });
16824}
16825// Message: Missing JSDoc @returns declaration.
16826
16827/**
16828 *
16829 */
16830function quux (foo) {
16831
16832 return new Promise(function (resolve, reject) {
16833 foo(resolve);
16834 });
16835}
16836// Message: Missing JSDoc @returns declaration.
16837
16838/**
16839 *
16840 */
16841function quux () {
16842 return new Promise((resolve, reject) => {
16843 while(true) {
16844 resolve(true);
16845 }
16846 });
16847}
16848// Message: Missing JSDoc @returns declaration.
16849
16850/**
16851 *
16852 */
16853function quux () {
16854 return new Promise((resolve, reject) => {
16855 do {
16856 resolve(true);
16857 }
16858 while(true)
16859 });
16860}
16861// Message: Missing JSDoc @returns declaration.
16862
16863/**
16864 *
16865 */
16866function quux () {
16867 return new Promise((resolve, reject) => {
16868 if (true) {
16869 resolve(true);
16870 }
16871 return;
16872 });
16873}
16874// Message: Missing JSDoc @returns declaration.
16875
16876/**
16877 *
16878 */
16879function quux () {
16880 return new Promise((resolve, reject) => {
16881 if (true) {
16882 resolve(true);
16883 }
16884 });
16885}
16886// Message: Missing JSDoc @returns declaration.
16887
16888/**
16889 *
16890 */
16891function quux () {
16892 var a = {};
16893 return new Promise((resolve, reject) => {
16894 with (a) {
16895 resolve(true);
16896 }
16897 });
16898}
16899// Message: Missing JSDoc @returns declaration.
16900
16901/**
16902 *
16903 */
16904function quux () {
16905 var a = {};
16906 return new Promise((resolve, reject) => {
16907 try {
16908 resolve(true);
16909 } catch (err) {}
16910 });
16911}
16912// Message: Missing JSDoc @returns declaration.
16913
16914/**
16915 *
16916 */
16917function quux () {
16918 var a = {};
16919 return new Promise((resolve, reject) => {
16920 try {
16921 } catch (err) {
16922 resolve(true);
16923 }
16924 });
16925}
16926// Message: Missing JSDoc @returns declaration.
16927
16928/**
16929 *
16930 */
16931function quux () {
16932 var a = {};
16933 return new Promise((resolve, reject) => {
16934 try {
16935 } catch (err) {
16936 } finally {
16937 resolve(true);
16938 }
16939 });
16940}
16941// Message: Missing JSDoc @returns declaration.
16942
16943/**
16944 *
16945 */
16946function quux () {
16947 var a = {};
16948 return new Promise((resolve, reject) => {
16949 switch (a) {
16950 case 'abc':
16951 resolve(true);
16952 }
16953 });
16954}
16955// Message: Missing JSDoc @returns declaration.
16956
16957/**
16958 *
16959 */
16960function quux () {
16961 return new Promise((resolve, reject) => {
16962 if (true) {
16963 resolve();
16964 } else {
16965 resolve(true);
16966 }
16967 });
16968}
16969// Message: Missing JSDoc @returns declaration.
16970
16971/**
16972 *
16973 */
16974function quux () {
16975 return new Promise((resolve, reject) => {
16976 for (let i = 0; i < 5 ; i++) {
16977 resolve(true);
16978 }
16979 });
16980}
16981// Message: Missing JSDoc @returns declaration.
16982
16983/**
16984 *
16985 */
16986function quux () {
16987 return new Promise((resolve, reject) => {
16988 for (const i of obj) {
16989 resolve(true);
16990 }
16991 });
16992}
16993// Message: Missing JSDoc @returns declaration.
16994
16995/**
16996 *
16997 */
16998function quux () {
16999 return new Promise((resolve, reject) => {
17000 for (const i in obj) {
17001 resolve(true);
17002 }
17003 });
17004}
17005// Message: Missing JSDoc @returns declaration.
17006
17007/**
17008 *
17009 */
17010function quux () {
17011 return new Promise((resolve, reject) => {
17012 if (true) {
17013 return;
17014 } else {
17015 resolve(true);
17016 }
17017 });
17018}
17019// Message: Missing JSDoc @returns declaration.
17020
17021/**
17022 *
17023 */
17024function quux () {
17025 return new Promise((resolve, reject) => {
17026 function a () {
17027 resolve(true);
17028 }
17029 a();
17030 });
17031}
17032// Message: Missing JSDoc @returns declaration.
17033
17034/**
17035 *
17036 */
17037function quux () {
17038 return new Promise();
17039}
17040// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17041// Message: Missing JSDoc @returns declaration.
17042
17043/**
17044 *
17045 */
17046async function quux () {
17047 return new Promise();
17048}
17049// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17050// Message: Missing JSDoc @returns declaration.
17051
17052/**
17053 *
17054 */
17055async function quux () {
17056 return new Promise((resolve, reject) => {});
17057}
17058// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17059// Message: Missing JSDoc @returns declaration.
17060````
17061
17062The following patterns are not considered problems:
17063
17064````js
17065/**
17066 * @returns Foo.
17067 */
17068function quux () {
17069
17070 return foo;
17071}
17072
17073/**
17074 * @returns Foo.
17075 */
17076function quux () {
17077
17078 return foo;
17079}
17080// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"]}]
17081
17082/**
17083 *
17084 */
17085function quux () {
17086}
17087
17088/**
17089 *
17090 */
17091function quux (bar) {
17092 bar.filter(baz => {
17093 return baz.corge();
17094 })
17095}
17096
17097/**
17098 * @returns Array
17099 */
17100function quux (bar) {
17101 return bar.filter(baz => {
17102 return baz.corge();
17103 })
17104}
17105
17106/**
17107 * @returns Array
17108 */
17109const quux = (bar) => bar.filter(({ corge }) => corge())
17110
17111/**
17112 * @inheritdoc
17113 */
17114function quux (foo) {
17115}
17116
17117/**
17118 * @override
17119 */
17120function quux (foo) {
17121}
17122
17123/**
17124 * @constructor
17125 */
17126function quux (foo) {
17127 return true;
17128}
17129
17130/**
17131 * @implements
17132 */
17133function quux (foo) {
17134 return true;
17135}
17136
17137/**
17138 * @override
17139 */
17140function quux (foo) {
17141
17142 return foo;
17143}
17144
17145/**
17146 * @class
17147 */
17148function quux (foo) {
17149 return true;
17150}
17151
17152/**
17153 * @constructor
17154 */
17155function quux (foo) {
17156
17157}
17158
17159/**
17160 * @returns {object}
17161 */
17162function quux () {
17163
17164 return {a: foo};
17165}
17166
17167/**
17168 * @returns {object}
17169 */
17170const quux = () => ({a: foo});
17171
17172/**
17173 * @returns {object}
17174 */
17175const quux = () => {
17176 return {a: foo}
17177};
17178
17179/**
17180 * @returns {void}
17181 */
17182function quux () {
17183}
17184
17185/**
17186 * @returns {void}
17187 */
17188const quux = () => {
17189
17190}
17191
17192/**
17193 * @returns {undefined}
17194 */
17195function quux () {
17196}
17197
17198/**
17199 * @returns {undefined}
17200 */
17201const quux = () => {
17202
17203}
17204
17205/**
17206 *
17207 */
17208function quux () {
17209}
17210
17211/**
17212 *
17213 */
17214const quux = () => {
17215
17216}
17217
17218class Foo {
17219 /**
17220 *
17221 */
17222 constructor () {
17223 }
17224}
17225// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17226
17227const language = {
17228 /**
17229 * @param {string} name
17230 */
17231 set name(name) {
17232 this._name = name;
17233 }
17234}
17235
17236/**
17237 * @returns {void}
17238 */
17239function quux () {
17240}
17241// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17242
17243/**
17244 * @returns {void}
17245 */
17246function quux () {
17247 return undefined;
17248}
17249
17250/**
17251 * @returns {void}
17252 */
17253function quux () {
17254 return undefined;
17255}
17256// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17257
17258/**
17259 * @returns {void}
17260 */
17261function quux () {
17262 return;
17263}
17264
17265/**
17266 * @returns {void}
17267 */
17268function quux () {
17269}
17270// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17271
17272/**
17273 * @returns {void}
17274 */
17275function quux () {
17276 return;
17277}
17278// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17279
17280/** @type {RequestHandler} */
17281function quux (req, res , next) {
17282 return;
17283}
17284
17285/**
17286 * @returns {Promise}
17287 */
17288async function quux () {
17289}
17290// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17291
17292/**
17293 * @returns {Promise}
17294 */
17295async function quux () {
17296}
17297// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17298
17299/**
17300 *
17301 */
17302async function quux () {}
17303
17304/**
17305 *
17306 */
17307const quux = async function () {}
17308
17309/**
17310 *
17311 */
17312const quux = async () => {}
17313
17314/** foo class */
17315class foo {
17316 /** foo constructor */
17317 constructor () {
17318 // =>
17319 this.bar = true;
17320 }
17321}
17322
17323export default foo;
17324
17325/**
17326 *
17327 */
17328function quux () {
17329}
17330// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17331
17332/**
17333 * @type {MyCallback}
17334 */
17335function quux () {
17336
17337}
17338// "jsdoc/require-returns": ["error"|"warn", {"exemptedBy":["type"]}]
17339
17340/**
17341 * @param {array} a
17342 */
17343async function foo(a) {
17344 return;
17345}
17346
17347/**
17348 *
17349 */
17350// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"]}]
17351
17352/**
17353 * @async
17354 */
17355// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"]}]
17356
17357/**
17358 * @function
17359 */
17360// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17361
17362/**
17363 * @callback
17364 */
17365// "jsdoc/require-returns": ["error"|"warn", {"forceRequireReturn":true}]
17366
17367/**
17368 * @function
17369 * @async
17370 */
17371// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17372
17373/**
17374 * @callback
17375 * @async
17376 */
17377// "jsdoc/require-returns": ["error"|"warn", {"forceReturnsWithAsync":true}]
17378
17379/**
17380 * @function
17381 */
17382// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceReturnsWithAsync":true}]
17383
17384/**
17385 * @callback
17386 */
17387// "jsdoc/require-returns": ["error"|"warn", {"contexts":["any"],"forceReturnsWithAsync":true}]
17388
17389class foo {
17390 get bar() {
17391 return 0;
17392 }
17393}
17394// "jsdoc/require-returns": ["error"|"warn", {"checkGetters":false}]
17395
17396class foo {
17397 /** @returns zero */
17398 get bar() {
17399 return 0;
17400 }
17401}
17402// "jsdoc/require-returns": ["error"|"warn", {"checkGetters":true}]
17403
17404class foo {
17405 /** @returns zero */
17406 get bar() {
17407 return 0;
17408 }
17409}
17410// "jsdoc/require-returns": ["error"|"warn", {"checkGetters":false}]
17411
17412class TestClass {
17413 /**
17414 *
17415 */
17416 constructor() { }
17417}
17418
17419class TestClass {
17420 /**
17421 * @returns A map.
17422 */
17423 constructor() {
17424 return new Map();
17425 }
17426}
17427
17428class TestClass {
17429 /**
17430 *
17431 */
17432 constructor() { }
17433}
17434// "jsdoc/require-returns": ["error"|"warn", {"checkConstructors":false}]
17435
17436class TestClass {
17437 /**
17438 *
17439 */
17440 get Test() { }
17441}
17442
17443class TestClass {
17444 /**
17445 * @returns A number.
17446 */
17447 get Test() {
17448 return 0;
17449 }
17450}
17451
17452class TestClass {
17453 /**
17454 *
17455 */
17456 get Test() {
17457 return 0;
17458 }
17459}
17460// "jsdoc/require-returns": ["error"|"warn", {"checkGetters":false}]
17461
17462/**
17463 *
17464 */
17465function quux (foo) {
17466
17467 return new Promise(function (resolve, reject) {
17468 resolve();
17469 });
17470}
17471
17472/**
17473 *
17474 */
17475function quux (foo) {
17476
17477 return new Promise(function (resolve, reject) {
17478 setTimeout(() => {
17479 resolve();
17480 });
17481 });
17482}
17483
17484/**
17485 *
17486 */
17487function quux (foo) {
17488
17489 return new Promise(function (resolve, reject) {
17490 foo();
17491 });
17492}
17493
17494/**
17495 *
17496 */
17497function quux (foo) {
17498
17499 return new Promise(function (resolve, reject) {
17500 abc((resolve) => {
17501 resolve(true);
17502 });
17503 });
17504}
17505
17506/**
17507 *
17508 */
17509function quux (foo) {
17510
17511 return new Promise(function (resolve, reject) {
17512 abc(function (resolve) {
17513 resolve(true);
17514 });
17515 });
17516}
17517
17518/**
17519 *
17520 */
17521function quux () {
17522 return new Promise((resolve, reject) => {
17523 if (true) {
17524 resolve();
17525 }
17526 });
17527 return;
17528}
17529
17530/**
17531 *
17532 */
17533function quux () {
17534 return new Promise();
17535}
17536
17537/**
17538 * Description.
17539 */
17540async function foo() {
17541 return new Promise(resolve => resolve());
17542}
17543````
17544
17545
17546<a name="eslint-plugin-jsdoc-rules-require-throws"></a>
17547### <code>require-throws</code>
17548
17549Requires that throw statements are documented.
17550
17551<a name="eslint-plugin-jsdoc-rules-require-throws-options-36"></a>
17552#### Options
17553
17554- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
17555 document block avoids the need for a `@throws`. Defaults to an array
17556 with `inheritdoc`. If you set this array, it will overwrite the default,
17557 so be sure to add back `inheritdoc` if you wish its presence to cause
17558 exemption of the rule.
17559- `contexts` - Set this to an array of strings representing the AST context
17560 (or an object with `context` and `comment` properties) where you wish
17561 the rule to be applied.
17562 Overrides the default contexts (see below). Set to `"any"` if you want
17563 the rule to apply to any jsdoc block throughout your files (as is necessary
17564 for finding function blocks not attached to a function declaration or
17565 expression, i.e., `@callback` or `@function` (or its aliases `@func` or
17566 `@method`) (including those associated with an `@interface`).
17567
17568```js
17569'jsdoc/require-throws': 'error',
17570```
17571
17572| | |
17573| -------- | --- |
17574| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
17575| Tags | `throws` |
17576| Aliases | `exception` |
17577|Recommended|true|
17578| Options | `contexts`, `exemptedBy` |
17579| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` |
17580
17581The following patterns are considered problems:
17582
17583````js
17584/**
17585 *
17586 */
17587function quux (foo) {
17588 throw new Error('err')
17589}
17590// Message: Missing JSDoc @throws declaration.
17591
17592/**
17593 *
17594 */
17595const quux = function (foo) {
17596 throw new Error('err')
17597}
17598// Message: Missing JSDoc @throws declaration.
17599
17600/**
17601 *
17602 */
17603const quux = (foo) => {
17604 throw new Error('err')
17605}
17606// Message: Missing JSDoc @throws declaration.
17607
17608/**
17609 *
17610 */
17611function quux (foo) {
17612 while(true) {
17613 throw new Error('err')
17614 }
17615}
17616// Message: Missing JSDoc @throws declaration.
17617
17618/**
17619 *
17620 */
17621function quux (foo) {
17622 do {
17623 throw new Error('err')
17624 } while(true)
17625}
17626// Message: Missing JSDoc @throws declaration.
17627
17628/**
17629 *
17630 */
17631function quux (foo) {
17632 for(var i = 0; i <= 10; i++) {
17633 throw new Error('err')
17634 }
17635}
17636// Message: Missing JSDoc @throws declaration.
17637
17638/**
17639 *
17640 */
17641function quux (foo) {
17642 for(num in [1,2,3]) {
17643 throw new Error('err')
17644 }
17645}
17646// Message: Missing JSDoc @throws declaration.
17647
17648/**
17649 *
17650 */
17651function quux (foo) {
17652 for(const num of [1,2,3]) {
17653 throw new Error('err')
17654 }
17655}
17656// Message: Missing JSDoc @throws declaration.
17657
17658/**
17659 *
17660 */
17661function quux (foo) {
17662 for(const index in [1,2,3]) {
17663 throw new Error('err')
17664 }
17665}
17666// Message: Missing JSDoc @throws declaration.
17667
17668/**
17669 *
17670 */
17671function quux (foo) {
17672 with(foo) {
17673 throw new Error('err')
17674 }
17675}
17676// Message: Missing JSDoc @throws declaration.
17677
17678/**
17679 *
17680 */
17681function quux (foo) {
17682 if (true) {
17683 throw new Error('err')
17684 }
17685}
17686// Message: Missing JSDoc @throws declaration.
17687
17688/**
17689 *
17690 */
17691function quux (foo) {
17692 if (false) {
17693 // do nothing
17694 } else {
17695 throw new Error('err')
17696 }
17697}
17698// Message: Missing JSDoc @throws declaration.
17699
17700/**
17701 *
17702 */
17703function quux (foo) {
17704 try {
17705 throw new Error('err')
17706 } catch(e) {
17707 throw new Error(e.message)
17708 }
17709}
17710// Message: Missing JSDoc @throws declaration.
17711
17712/**
17713 *
17714 */
17715function quux (foo) {
17716 try {
17717 // do nothing
17718 } finally {
17719 throw new Error(e.message)
17720 }
17721}
17722// Message: Missing JSDoc @throws declaration.
17723
17724/**
17725 *
17726 */
17727function quux (foo) {
17728 const a = 'b'
17729 switch(a) {
17730 case 'b':
17731 throw new Error('err')
17732 }
17733}
17734// Message: Missing JSDoc @throws declaration.
17735
17736/**
17737 * @throws
17738 */
17739function quux () {
17740
17741}
17742// Settings: {"jsdoc":{"tagNamePreference":{"throws":false}}}
17743// Message: Unexpected tag `@throws`
17744
17745/**
17746 *
17747 */
17748const directThrowAfterArrow = (b) => {
17749 const a = () => {};
17750 if (b) {
17751 throw new Error('oops')
17752 }
17753 return a;
17754};
17755// Message: Missing JSDoc @throws declaration.
17756````
17757
17758The following patterns are not considered problems:
17759
17760````js
17761/**
17762 * @throws An error.
17763 */
17764function quux () {
17765 throw new Error('err')
17766}
17767
17768/**
17769 *
17770 */
17771function quux (foo) {
17772 try {
17773 throw new Error('err')
17774 } catch(e) {}
17775}
17776
17777/**
17778 * @inheritdoc
17779 */
17780function quux (foo) {
17781 throw new Error('err')
17782}
17783
17784/**
17785 * @abstract
17786 */
17787function quux (foo) {
17788 throw new Error('err')
17789}
17790
17791/**
17792 *
17793 */
17794function quux (foo) {
17795}
17796
17797/**
17798 * @type {MyCallback}
17799 */
17800function quux () {
17801 throw new Error('err')
17802}
17803// "jsdoc/require-throws": ["error"|"warn", {"exemptedBy":["type"]}]
17804
17805/**
17806 *
17807 */
17808const itself = (n) => n;
17809
17810/**
17811 * Not tracking on nested function
17812 */
17813const nested = () => () => {throw new Error('oops');};
17814````
17815
17816
17817<a name="eslint-plugin-jsdoc-rules-require-yields"></a>
17818### <code>require-yields</code>
17819
17820Requires that yields are documented.
17821
17822Will also report if multiple `@yields` tags are present.
17823
17824See the `next`, `forceRequireNext`, and `nextWithGeneratorTag` options for an
17825option to expect a non-standard `@next` tag.
17826
17827<a name="eslint-plugin-jsdoc-rules-require-yields-options-37"></a>
17828#### Options
17829
17830- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
17831 document block avoids the need for a `@yields`. Defaults to an array
17832 with `inheritdoc`. If you set this array, it will overwrite the default,
17833 so be sure to add back `inheritdoc` if you wish its presence to cause
17834 exemption of the rule.
17835- `forceRequireYields` - Set to `true` to always insist on
17836 `@yields` documentation for generators even if there are only
17837 expressionless `yield` statements in the function. May be desired to flag
17838 that a project is aware of an `undefined`/`void` yield. Defaults to
17839 `false`.
17840- `contexts` - Set this to an array of strings representing the AST context
17841 (or an object with `context` and `comment` properties) where you wish
17842 the rule to be applied.
17843 Overrides the default contexts (see below). Set to `"any"` if you want
17844 the rule to apply to any jsdoc block throughout your files (as is necessary
17845 for finding function blocks not attached to a function declaration or
17846 expression, i.e., `@callback` or `@function` (or its aliases `@func` or
17847 `@method`) (including those associated with an `@interface`). This
17848 rule will only apply on non-default contexts when there is such a tag
17849 present and the `forceRequireYields` option is set or if the
17850 `withGeneratorTag` option is set with a present `@generator` tag
17851 (since we are not checking against the actual `yield` values in these
17852 cases).
17853- `withGeneratorTag` - If a `@generator` tag is present on a block, require
17854 `@yields`/`@yield`. Defaults to `true`. See `contexts` to `any` if you want
17855 to catch `@generator` with `@callback` or such not attached to a function.
17856- `next` - If `true`, this option will insist that any use of a `yield` return
17857 value (e.g., `const rv = yield;` or `const rv = yield value;`) has a
17858 (non-standard) `@next` tag (in addition to any `@yields` tag) so as to be
17859 able to document the type expected to be supplied into the iterator
17860 (the `Generator` iterator that is returned by the call to the generator
17861 function) to the iterator (e.g., `it.next(value)`). The tag will not be
17862 expected if the generator function body merely has plain `yield;` or
17863 `yield value;` statements without returning the values. Defaults to
17864 `false`.
17865- `forceRequireNext` - Set to `true` to always insist on
17866 `@next` documentation even if there are no `yield` statements in the
17867 function or none return values. May be desired to flag that a project is
17868 aware of the expected yield return being `undefined`. Defaults to `false`.
17869- `nextWithGeneratorTag` - If a `@generator` tag is present on a block, require
17870 (non-standard ) `@next` (see `next` option). This will require using `void`
17871 or `undefined` in cases where generators do not use the `next()`-supplied
17872 incoming `yield`-returned value. Defaults to `false`. See `contexts` to
17873 `any` if you want to catch `@generator` with `@callback` or such not
17874 attached to a function.
17875
17876|||
17877|---|---|
17878|Context|Generator functions (`FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled)|
17879|Tags|`yields`|
17880|Aliases|`yield`|
17881|Recommended|true|
17882| Options | `contexts`, `exemptedBy`, `withGeneratorTag`, `nextWithGeneratorTag`, `forceRequireYields`, `next` |
17883| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` |
17884
17885The following patterns are considered problems:
17886
17887````js
17888/**
17889 *
17890 */
17891function * quux (foo) {
17892
17893 yield foo;
17894}
17895// Message: Missing JSDoc @yields declaration.
17896
17897/**
17898 * @yields
17899 */
17900function * quux (foo) {
17901
17902 const retVal = yield foo;
17903}
17904// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
17905// Message: Missing JSDoc @next declaration.
17906
17907/**
17908 * @yields
17909 */
17910function * quux (foo) {
17911
17912 const retVal = yield;
17913}
17914// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
17915// Message: Missing JSDoc @next declaration.
17916
17917/**
17918 * @yields {void}
17919 */
17920function * quux () {
17921}
17922// "jsdoc/require-yields": ["error"|"warn", {"forceRequireNext":true}]
17923// Message: Missing JSDoc @next declaration.
17924
17925/**
17926 * @yields {void}
17927 */
17928function * quux () {
17929 yield;
17930}
17931// "jsdoc/require-yields": ["error"|"warn", {"forceRequireNext":true}]
17932// Message: Missing JSDoc @next declaration.
17933
17934/**
17935 *
17936 */
17937function * quux (foo) {
17938
17939 const a = yield foo;
17940}
17941// Message: Missing JSDoc @yields declaration.
17942
17943/**
17944 *
17945 */
17946function * quux (foo) {
17947 yield foo;
17948}
17949// Settings: {"jsdoc":{"tagNamePreference":{"yields":"yield"}}}
17950// Message: Missing JSDoc @yield declaration.
17951
17952/**
17953 * @yields
17954 */
17955function * quux (foo) {
17956 const val = yield foo;
17957}
17958// Settings: {"jsdoc":{"tagNamePreference":{"next":"yield-returns"}}}
17959// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
17960// Message: Missing JSDoc @yield-returns declaration.
17961
17962/**
17963 * @yields
17964 * @next
17965 */
17966function * quux () {
17967 const ret = yield 5;
17968}
17969// Settings: {"jsdoc":{"tagNamePreference":{"next":false}}}
17970// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
17971// Message: Unexpected tag `@next`
17972
17973/**
17974 *
17975 */
17976function * quux() {
17977 yield 5;
17978}
17979// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
17980// Message: Missing JSDoc @yields declaration.
17981
17982/**
17983 *
17984 */
17985function * quux() {
17986 yield;
17987}
17988// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
17989// Message: Missing JSDoc @yields declaration.
17990
17991/**
17992 *
17993 */
17994const quux = async function * () {
17995 yield;
17996}
17997// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
17998// Message: Missing JSDoc @yields declaration.
17999
18000/**
18001 *
18002 */
18003async function * quux () {
18004 yield;
18005}
18006// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18007// Message: Missing JSDoc @yields declaration.
18008
18009/**
18010 *
18011 */
18012function * quux () {
18013 yield;
18014}
18015// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"forceRequireYields":true}]
18016// Message: Missing JSDoc @yields declaration.
18017
18018/**
18019 * @function
18020 * @generator
18021 */
18022// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"forceRequireYields":true}]
18023// Message: Missing JSDoc @yields declaration.
18024
18025/**
18026 * @callback
18027 * @generator
18028 */
18029// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"forceRequireYields":true}]
18030// Message: Missing JSDoc @yields declaration.
18031
18032/**
18033 * @yields {undefined}
18034 * @yields {void}
18035 */
18036function * quux (foo) {
18037
18038 return foo;
18039}
18040// Message: Found more than one @yields declaration.
18041
18042/**
18043 * @yields
18044 */
18045function * quux () {
18046
18047}
18048// Settings: {"jsdoc":{"tagNamePreference":{"yields":false}}}
18049// Message: Unexpected tag `@yields`
18050
18051/**
18052 * @param foo
18053 */
18054function * quux (foo) {
18055 yield 'bar';
18056}
18057// "jsdoc/require-yields": ["error"|"warn", {"exemptedBy":["notPresent"]}]
18058// Message: Missing JSDoc @yields declaration.
18059
18060/**
18061 * @param {array} a
18062 */
18063async function * foo(a) {
18064 return;
18065}
18066// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18067// Message: Missing JSDoc @yields declaration.
18068
18069/**
18070 * @param {array} a
18071 */
18072async function * foo(a) {
18073 yield Promise.all(a);
18074}
18075// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18076// Message: Missing JSDoc @yields declaration.
18077
18078class quux {
18079 /**
18080 *
18081 */
18082 * quux () {
18083 yield;
18084 }
18085}
18086// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"forceRequireYields":true}]
18087// Message: Missing JSDoc @yields declaration.
18088
18089/**
18090 * @param {array} a
18091 */
18092async function * foo(a) {
18093 yield Promise.all(a);
18094}
18095// Message: Missing JSDoc @yields declaration.
18096
18097/**
18098 * @generator
18099 */
18100// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"withGeneratorTag":true}]
18101// Message: Missing JSDoc @yields declaration.
18102
18103/**
18104 * @generator
18105 * @yields
18106 */
18107// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"nextWithGeneratorTag":true}]
18108// Message: Missing JSDoc @next declaration.
18109
18110/**
18111 *
18112 */
18113function * quux () {
18114 if (true) {
18115 yield;
18116 }
18117 yield true;
18118}
18119// Message: Missing JSDoc @yields declaration.
18120
18121/**
18122 *
18123 */
18124function * quux () {
18125 try {
18126 yield true;
18127 } catch (err) {
18128 }
18129 yield;
18130}
18131// Message: Missing JSDoc @yields declaration.
18132
18133/**
18134 *
18135 */
18136function * quux () {
18137 try {
18138 } finally {
18139 yield true;
18140 }
18141 yield;
18142}
18143// Message: Missing JSDoc @yields declaration.
18144
18145/**
18146 *
18147 */
18148function * quux () {
18149 try {
18150 yield;
18151 } catch (err) {
18152 }
18153 yield true;
18154}
18155// Message: Missing JSDoc @yields declaration.
18156
18157/**
18158 *
18159 */
18160function * quux () {
18161 try {
18162 something();
18163 } catch (err) {
18164 yield true;
18165 }
18166 yield;
18167}
18168// Message: Missing JSDoc @yields declaration.
18169
18170/**
18171 *
18172 */
18173function * quux () {
18174 switch (true) {
18175 case 'abc':
18176 yield true;
18177 }
18178 yield;
18179}
18180// Message: Missing JSDoc @yields declaration.
18181
18182/**
18183 *
18184 */
18185function * quux () {
18186 switch (true) {
18187 case 'abc':
18188 yield;
18189 }
18190 yield true;
18191}
18192// Message: Missing JSDoc @yields declaration.
18193
18194/**
18195 *
18196 */
18197function * quux () {
18198 for (const i of abc) {
18199 yield true;
18200 }
18201 yield;
18202}
18203// Message: Missing JSDoc @yields declaration.
18204
18205/**
18206 *
18207 */
18208function * quux () {
18209 for (const a in b) {
18210 yield true;
18211 }
18212}
18213// Message: Missing JSDoc @yields declaration.
18214
18215/**
18216 *
18217 */
18218function * quux () {
18219 for (let i=0; i<n; i+=1) {
18220 yield true;
18221 }
18222}
18223// Message: Missing JSDoc @yields declaration.
18224
18225/**
18226 *
18227 */
18228function * quux () {
18229 while(true) {
18230 yield true
18231 }
18232}
18233// Message: Missing JSDoc @yields declaration.
18234
18235/**
18236 *
18237 */
18238function * quux () {
18239 do {
18240 yield true
18241 }
18242 while(true)
18243}
18244// Message: Missing JSDoc @yields declaration.
18245
18246/**
18247 *
18248 */
18249function * quux () {
18250 if (true) {
18251 yield;
18252 }
18253 yield true;
18254}
18255// Message: Missing JSDoc @yields declaration.
18256
18257/**
18258 *
18259 */
18260function * quux () {
18261 if (true) {
18262 yield true;
18263 }
18264}
18265// Message: Missing JSDoc @yields declaration.
18266
18267/**
18268 *
18269 */
18270function * quux () {
18271 var a = {};
18272 with (a) {
18273 yield true;
18274 }
18275}
18276// Message: Missing JSDoc @yields declaration.
18277
18278/**
18279 *
18280 */
18281function * quux () {
18282 if (true) {
18283 yield;
18284 } else {
18285 yield true;
18286 }
18287 yield;
18288}
18289// Message: Missing JSDoc @yields declaration.
18290````
18291
18292The following patterns are not considered problems:
18293
18294````js
18295/**
18296 * @yields Foo.
18297 */
18298function * quux () {
18299
18300 yield foo;
18301}
18302
18303/**
18304 * @yields Foo.
18305 */
18306function * quux () {
18307
18308 yield foo;
18309}
18310// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"]}]
18311
18312/**
18313 *
18314 */
18315function * quux () {
18316}
18317
18318/**
18319 *
18320 */
18321function * quux () {
18322 yield;
18323}
18324
18325/**
18326 *
18327 */
18328function quux (bar) {
18329 bar.doSomething(function * (baz) {
18330 yield baz.corge();
18331 })
18332}
18333
18334/**
18335 * @yields {Array}
18336 */
18337function * quux (bar) {
18338 yield bar.doSomething(function * (baz) {
18339 yield baz.corge();
18340 })
18341}
18342
18343/**
18344 * @inheritdoc
18345 */
18346function * quux (foo) {
18347}
18348
18349/**
18350 * @override
18351 */
18352function * quux (foo) {
18353}
18354
18355/**
18356 * @constructor
18357 */
18358function * quux (foo) {
18359}
18360
18361/**
18362 * @implements
18363 */
18364function * quux (foo) {
18365 yield;
18366}
18367
18368/**
18369 * @override
18370 */
18371function * quux (foo) {
18372
18373 yield foo;
18374}
18375
18376/**
18377 * @class
18378 */
18379function * quux (foo) {
18380 yield foo;
18381}
18382
18383/**
18384 * @constructor
18385 */
18386function * quux (foo) {
18387}
18388
18389/**
18390 * @yields {object}
18391 */
18392function * quux () {
18393
18394 yield {a: foo};
18395}
18396
18397/**
18398 * @yields {void}
18399 */
18400function * quux () {
18401}
18402
18403/**
18404 * @yields {undefined}
18405 */
18406function * quux () {
18407}
18408
18409/**
18410 *
18411 */
18412function * quux () {
18413}
18414
18415/**
18416 * @yields {void}
18417 */
18418function quux () {
18419}
18420// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18421
18422/**
18423 * @yields {void}
18424 * @next {void}
18425 */
18426function * quux () {
18427}
18428// "jsdoc/require-yields": ["error"|"warn", {"forceRequireNext":true}]
18429
18430/**
18431 * @yields {void}
18432 */
18433function * quux () {
18434 yield undefined;
18435}
18436
18437/**
18438 * @yields {void}
18439 */
18440function * quux () {
18441 yield undefined;
18442}
18443// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18444
18445/**
18446 * @yields {void}
18447 */
18448function * quux () {
18449 yield;
18450}
18451
18452/**
18453 * @yields {void}
18454 */
18455function * quux () {
18456}
18457// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18458
18459/**
18460 * @yields {void}
18461 */
18462function * quux () {
18463 yield;
18464}
18465// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18466
18467/** @type {SpecialIterator} */
18468function * quux () {
18469 yield 5;
18470}
18471
18472/**
18473 * @yields {Something}
18474 */
18475async function * quux () {
18476}
18477// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18478
18479/**
18480 *
18481 */
18482async function * quux () {}
18483
18484/**
18485 *
18486 */
18487const quux = async function * () {}
18488
18489/**
18490 * @type {MyCallback}
18491 */
18492function * quux () {
18493 yield;
18494}
18495// "jsdoc/require-yields": ["error"|"warn", {"exemptedBy":["type"]}]
18496
18497/**
18498 * @param {array} a
18499 */
18500async function * foo (a) {
18501 yield;
18502}
18503
18504/**
18505 *
18506 */
18507// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"]}]
18508
18509/**
18510 * @function
18511 */
18512// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"]}]
18513
18514/**
18515 * @function
18516 */
18517// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18518
18519/**
18520 * @callback
18521 */
18522// "jsdoc/require-yields": ["error"|"warn", {"forceRequireYields":true}]
18523
18524/**
18525 * @generator
18526 */
18527// "jsdoc/require-yields": ["error"|"warn", {"withGeneratorTag":true}]
18528
18529/**
18530 * @generator
18531 */
18532// "jsdoc/require-yields": ["error"|"warn", {"nextWithGeneratorTag":true}]
18533
18534/**
18535 * @generator
18536 * @yields
18537 */
18538// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"withGeneratorTag":true}]
18539
18540/**
18541 * @generator
18542 * @yields
18543 * @next
18544 */
18545// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"nextWithGeneratorTag":true}]
18546
18547/**
18548 * @generator
18549 */
18550// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"withGeneratorTag":false}]
18551
18552/**
18553 * @generator
18554 * @yields
18555 */
18556// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"nextWithGeneratorTag":false}]
18557
18558/**
18559 * @yields
18560 */
18561function * quux (foo) {
18562
18563 const a = yield foo;
18564}
18565
18566/**
18567 * @yields
18568 * @next
18569 */
18570function * quux (foo) {
18571 let a = yield;
18572}
18573// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
18574
18575/**
18576 * @yields
18577 * @next
18578 */
18579function * quux (foo) {
18580 const a = yield foo;
18581}
18582// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
18583
18584/**
18585 *
18586 */
18587// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"nextWithGeneratorTag":true}]
18588
18589/**
18590 *
18591 */
18592// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"next":true}]
18593
18594/**
18595 *
18596 */
18597function quux () {}
18598// "jsdoc/require-yields": ["error"|"warn", {"contexts":["any"],"next":true}]
18599
18600/**
18601 * @yields {void}
18602 */
18603function * quux () {
18604 yield;
18605}
18606// "jsdoc/require-yields": ["error"|"warn", {"next":true}]
18607
18608/**
18609 *
18610 */
18611function * quux (foo) {
18612 const a = function * bar () {
18613 yield foo;
18614 }
18615}
18616````
18617
18618
18619<a name="eslint-plugin-jsdoc-rules-require-yields-check"></a>
18620### <code>require-yields-check</code>
18621
18622Ensures that if a `@yields` is present that a `yield` (or `yield` with a
18623value) is present in the function body (or that if a `@next` is present that
18624there is a `yield` with a return value present).
18625
18626Please also note that JavaScript does allow generators not to have `yield`
18627(e.g., with just a return or even no explicit return), but if you want to
18628enforce that all generators (except wholly empty ones) have a `yield` in the
18629function body, you can use the ESLint
18630[`require-yield`](https://eslint.org/docs/rules/require-yield) rule. In
18631conjunction with this, you can also use the `checkGeneratorsOnly` option
18632as an optimization so that this rule won't need to do its own checking within
18633function bodies.
18634
18635Will also report if multiple `@yields` tags are present.
18636
18637<a name="eslint-plugin-jsdoc-rules-require-yields-check-options-38"></a>
18638#### Options
18639
18640- `checkGeneratorsOnly` - Avoids checking the function body and merely insists
18641 that all generators have `@yields`. This can be an optimization with the
18642 ESLint `require-yield` rule, as that rule already ensures a `yield` is
18643 present in generators, albeit assuming the generator is not empty).
18644 Defaults to `false`.
18645- `next` - If `true`, this option will insist that any use of a (non-standard)
18646 `@next` tag (in addition to any `@yields` tag) will be matched by a `yield`
18647 which uses a return value in the body of the generator (e.g.,
18648 `const rv = yield;` or `const rv = yield value;`). This (non-standard)
18649 tag is intended to be used to indicate a type and/or description of
18650 the value expected to be supplied by the user when supplied to the iterator
18651 by its `next` method, as with `it.next(value)` (with the iterator being
18652 the `Generator` iterator that is returned by the call to the generator
18653 function). This option will report an error if the generator function body
18654 merely has plain `yield;` or `yield value;` statements without returning
18655 the values. Defaults to `false`.
18656
18657|||
18658|---|---|
18659|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
18660|Tags|`yields`|
18661|Aliases|`yield`|
18662|Recommended|true|
18663|Options|`checkGeneratorsOnly`|
18664The following patterns are considered problems:
18665
18666````js
18667/**
18668 * @yields
18669 */
18670function * quux (foo) {
18671
18672}
18673// Message: JSDoc @yields declaration present but yield expression not available in function.
18674
18675/**
18676 * @yields
18677 */
18678function quux (foo) {
18679
18680}
18681// "jsdoc/require-yields-check": ["error"|"warn", {"checkGeneratorsOnly":true}]
18682// Message: JSDoc @yields declaration present but yield expression not available in function.
18683
18684/**
18685 * @next
18686 */
18687function quux (foo) {
18688
18689}
18690// "jsdoc/require-yields-check": ["error"|"warn", {"checkGeneratorsOnly":true,"next":true}]
18691// Message: JSDoc @next declaration present but yield expression with return value not available in function.
18692
18693/**
18694 * @next {SomeType}
18695 */
18696function * quux (foo) {
18697
18698}
18699// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
18700// Message: JSDoc @next declaration present but yield expression with return value not available in function.
18701
18702/**
18703 * @next {SomeType}
18704 */
18705function * quux (foo) {
18706 yield;
18707}
18708// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
18709// Message: JSDoc @next declaration present but yield expression with return value not available in function.
18710
18711/**
18712 * @next {SomeType}
18713 */
18714function * quux (foo) {
18715 yield 5;
18716}
18717// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
18718// Message: JSDoc @next declaration present but yield expression with return value not available in function.
18719
18720/**
18721 * @yield
18722 */
18723function * quux (foo) {
18724
18725}
18726// Settings: {"jsdoc":{"tagNamePreference":{"yields":"yield"}}}
18727// Message: JSDoc @yield declaration present but yield expression not available in function.
18728
18729/**
18730 * @yield-returns {Something}
18731 */
18732function * quux (foo) {
18733 yield;
18734}
18735// Settings: {"jsdoc":{"tagNamePreference":{"next":"yield-returns"}}}
18736// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
18737// Message: JSDoc @yield-returns declaration present but yield expression with return value not available in function.
18738
18739/**
18740 * @yields {undefined} Foo.
18741 * @yields {String} Foo.
18742 */
18743function * quux () {
18744
18745 yield foo;
18746}
18747// Message: Found more than one @yields declaration.
18748
18749class Foo {
18750 /**
18751 * @yields {string}
18752 */
18753 * bar () {
18754 }
18755}
18756// Message: JSDoc @yields declaration present but yield expression not available in function.
18757
18758/**
18759 * @yields
18760 */
18761function * quux () {
18762
18763}
18764// Settings: {"jsdoc":{"tagNamePreference":{"yields":false}}}
18765// Message: Unexpected tag `@yields`
18766
18767/**
18768 * @next
18769 */
18770function * quux () {
18771
18772}
18773// Settings: {"jsdoc":{"tagNamePreference":{"next":false}}}
18774// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
18775// Message: Unexpected tag `@next`
18776
18777/**
18778 * @yields {string}
18779 */
18780function * f () {
18781 function * g() {
18782 yield 'foo'
18783 }
18784}
18785// Message: JSDoc @yields declaration present but yield expression not available in function.
18786
18787/**
18788 * @yields {Promise<void>}
18789 */
18790async function * quux() {}
18791// Message: JSDoc @yields declaration present but yield expression not available in function.
18792
18793/**
18794 * @yields {Promise<void>}
18795 */
18796const quux = async function * () {}
18797// Message: JSDoc @yields declaration present but yield expression not available in function.
18798````
18799
18800The following patterns are not considered problems:
18801
18802````js
18803/**
18804 * @yields Foo.
18805 */
18806function * quux () {
18807
18808 yield foo;
18809}
18810
18811/**
18812 * @yields {string} Foo.
18813 */
18814function * quux () {
18815
18816 yield foo;
18817}
18818
18819/**
18820 * @yields {string} Foo.
18821 */
18822function * quux () {
18823
18824 yield foo;
18825}
18826
18827/**
18828 *
18829 */
18830function * quux () {
18831}
18832
18833/**
18834 * @yields {undefined} Foo.
18835 */
18836function * quux () {}
18837
18838/**
18839 * @yields { void } Foo.
18840 */
18841function quux () {}
18842
18843/**
18844 * @yields Foo.
18845 * @abstract
18846 */
18847function * quux () {
18848 throw new Error('must be implemented by subclass!');
18849}
18850
18851/**
18852 * @yields Foo.
18853 * @virtual
18854 */
18855function * quux () {
18856 throw new Error('must be implemented by subclass!');
18857}
18858
18859/**
18860 * @yields Foo.
18861 * @constructor
18862 */
18863function * quux () {
18864}
18865
18866/**
18867 * @interface
18868 */
18869class Foo {
18870 /**
18871 * @yields {string}
18872 */
18873 * bar () {
18874 }
18875}
18876
18877/**
18878 * @record
18879 */
18880class Foo {
18881 /**
18882 * @yields {string}
18883 */
18884 * bar () {
18885 }
18886}
18887// Settings: {"jsdoc":{"mode":"closure"}}
18888
18889/**
18890 * @yields {undefined} Foo.
18891 */
18892function * quux () {
18893}
18894
18895/**
18896 * @yields {void} Foo.
18897 */
18898function * quux () {
18899}
18900
18901/**
18902 * @yields {void} Foo.
18903 */
18904function * quux () {
18905 yield undefined;
18906}
18907
18908/**
18909 * @yields {void} Foo.
18910 */
18911function * quux () {
18912 yield;
18913}
18914
18915/**
18916 *
18917 */
18918function * quux () {
18919 yield undefined;
18920}
18921
18922/**
18923 *
18924 */
18925function * quux () {
18926 yield;
18927}
18928
18929/**
18930 * @yields {true}
18931 */
18932function * quux () {
18933 try {
18934 yield true;
18935 } catch (err) {
18936 }
18937 yield;
18938}
18939
18940/**
18941 * @yields {true}
18942 */
18943function * quux () {
18944 try {
18945 } finally {
18946 yield true;
18947 }
18948 yield;
18949}
18950
18951/**
18952 * @yields {true}
18953 */
18954function * quux () {
18955 try {
18956 yield;
18957 } catch (err) {
18958 }
18959 yield true;
18960}
18961
18962/**
18963 * @yields {true}
18964 */
18965function * quux () {
18966 try {
18967 something();
18968 } catch (err) {
18969 yield true;
18970 }
18971 yield;
18972}
18973
18974/**
18975 * @yields {true}
18976 */
18977function * quux () {
18978 switch (true) {
18979 case 'abc':
18980 yield true;
18981 }
18982 yield;
18983}
18984
18985/**
18986 * @yields {true}
18987 */
18988function * quux () {
18989 switch (true) {
18990 case 'abc':
18991 yield;
18992 }
18993 yield true;
18994}
18995
18996/**
18997 * @yields {true}
18998 */
18999function * quux () {
19000 for (const i of abc) {
19001 yield true;
19002 }
19003 yield;
19004}
19005
19006/**
19007 * @yields {true}
19008 */
19009function * quux () {
19010 for (const a in b) {
19011 yield true;
19012 }
19013}
19014
19015/**
19016 * @yields {true}
19017 */
19018function * quux () {
19019 for (let i=0; i<n; i+=1) {
19020 yield true;
19021 }
19022}
19023
19024/**
19025 * @yields {true}
19026 */
19027function * quux () {
19028 while(true) {
19029 yield true
19030 }
19031}
19032
19033/**
19034 * @yields {true}
19035 */
19036function * quux () {
19037 do {
19038 yield true
19039 }
19040 while(true)
19041}
19042
19043/**
19044 * @yields {true}
19045 */
19046function * quux () {
19047 if (true) {
19048 yield;
19049 }
19050 yield true;
19051}
19052
19053/**
19054 * @yields {true}
19055 */
19056function * quux () {
19057 if (true) {
19058 yield true;
19059 }
19060}
19061
19062/**
19063 * @yields {true}
19064 */
19065function * quux () {
19066 var a = {};
19067 with (a) {
19068 yield true;
19069 }
19070}
19071
19072/**
19073 * @yields {true}
19074 */
19075function * quux () {
19076 if (true) {
19077 yield;
19078 } else {
19079 yield true;
19080 }
19081 yield;
19082}
19083
19084/**
19085 * @next {void}
19086 */
19087function * quux (foo) {
19088
19089}
19090// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
19091
19092/**
19093 * @next {SomeType}
19094 */
19095function * quux (foo) {
19096 const a = yield;
19097}
19098// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
19099
19100/**
19101 * @next {SomeType}
19102 */
19103function * quux (foo) {
19104 const a = yield 5;
19105}
19106// "jsdoc/require-yields-check": ["error"|"warn", {"next":true}]
19107````
19108
19109
19110<a name="eslint-plugin-jsdoc-rules-tag-lines"></a>
19111### <code>tag-lines</code>
19112
19113Enforces lines (or no lines) between tags.
19114
19115<a name="eslint-plugin-jsdoc-rules-tag-lines-options-39"></a>
19116#### Options
19117
19118The first option is a single string set to "always", "never", or "any"
19119(defaults to "never").
19120
19121"any" is only useful with `tags` (allowing non-enforcement of lines except
19122for particular tags).
19123
19124The second option is an object with the following optional properties.
19125
19126<a name="eslint-plugin-jsdoc-rules-tag-lines-options-39-count-defaults-to-1"></a>
19127##### <code>count</code> (defaults to 1)
19128
19129Use with "always" to indicate the number of lines to require be present.
19130
19131<a name="eslint-plugin-jsdoc-rules-tag-lines-options-39-noendlines-defaults-to-false"></a>
19132##### <code>noEndLines</code> (defaults to <code>false</code>)
19133
19134Use with "always" to indicate the normal lines to be added after tags should
19135not be added after the final tag.
19136
19137<a name="eslint-plugin-jsdoc-rules-tag-lines-options-39-tags-default-to-empty-object"></a>
19138##### <code>tags</code> (default to empty object)
19139
19140Overrides the default behavior depending on specific tags.
19141
19142An object whose keys are tag names and whose values are objects with the
19143following keys:
19144
191451. `lines` - Set to `always` or `never` to override.
191462. `count` - Overrides main `count` (for "always")
19147
19148|||
19149|---|---|
19150|Context|everywhere|
19151|Tags|Any|
19152|Recommended|true|
19153|Settings|N/A|
19154|Options|(a string matching `"always" or "never"` and optional object with `count` and `noEndLines`)|
19155
19156The following patterns are considered problems:
19157
19158````js
19159/**
19160 * Some description
19161 * @param {string} a
19162 * @param {number} b
19163 */
19164// "jsdoc/tag-lines": ["error"|"warn", "always"]
19165// Message: Expected 1 line between tags but found 0
19166
19167/**
19168 * Some description
19169 * @param {string} a
19170 * @param {number} b
19171 */
19172// "jsdoc/tag-lines": ["error"|"warn", "always",{"count":2}]
19173// Message: Expected 2 lines between tags but found 0
19174
19175/**
19176 * Some description
19177 * @param {string} a
19178 *
19179 * @param {number} b
19180 */
19181// "jsdoc/tag-lines": ["error"|"warn", "always",{"count":2}]
19182// Message: Expected 2 lines between tags but found 1
19183
19184/**
19185 * Some description
19186 * @param {string} a
19187 * @param {number} b
19188 */
19189// "jsdoc/tag-lines": ["error"|"warn", "always",{"noEndLines":true}]
19190// Message: Expected 1 line between tags but found 0
19191
19192/**
19193 * Some description
19194 * @param {string} a
19195 *
19196 * @param {number} b
19197 *
19198 */
19199// "jsdoc/tag-lines": ["error"|"warn", "never"]
19200// Message: Expected no lines between tags
19201
19202/**
19203 * Some description
19204 * @param {string} a
19205 *
19206 * @param {number} b
19207 *
19208 */
19209// Message: Expected no lines between tags
19210
19211/**
19212 * Some description
19213 * @param {string} a
19214 *
19215 * @param {number} b
19216 * @param {number} c
19217 */
19218// "jsdoc/tag-lines": ["error"|"warn", "always"]
19219// Message: Expected 1 line between tags but found 0
19220
19221/**
19222 * Some description
19223 * @param {string} a
19224 * @param {number} b
19225 */
19226// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"always"}}}]
19227// Message: Expected 1 line between tags but found 0
19228
19229/**
19230 * Some description
19231 * @param {string} a
19232 * @param {number} b
19233 */
19234// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"always"}}}]
19235// Message: Expected 1 line between tags but found 0
19236
19237/**
19238 * Some description
19239 * @param {string} a
19240 * @param {number} b
19241 *
19242 */
19243// "jsdoc/tag-lines": ["error"|"warn", "always",{"tags":{"param":{"lines":"never"}}}]
19244// Message: Expected no lines between tags
19245
19246/**
19247 * Some description
19248 * @param {string} a
19249 *
19250 * @param {number} b
19251 */
19252// "jsdoc/tag-lines": ["error"|"warn", "never",{"count":2,"tags":{"param":{"lines":"always"}}}]
19253// Message: Expected 2 lines between tags but found 1
19254
19255/**
19256 * Some description
19257 * @param {string} a
19258 *
19259 * @param {number} b
19260 */
19261// "jsdoc/tag-lines": ["error"|"warn", "never",{"count":5,"tags":{"param":{"count":2,"lines":"always"}}}]
19262// Message: Expected 2 lines between tags but found 1
19263
19264/**
19265 * Some description
19266 * @param {string} a
19267 * @param {number} b
19268 */
19269// "jsdoc/tag-lines": ["error"|"warn", "always",{"tags":{"anotherTag":{"lines":"never"}}}]
19270// Message: Expected 1 line between tags but found 0
19271
19272/**
19273 * Some description
19274 * @param {string} A broken up
19275 *
19276 * tag description.
19277 * @param {number} b
19278 *
19279 */
19280// "jsdoc/tag-lines": ["error"|"warn", "always"]
19281// Message: Expected 1 line between tags but found 0
19282
19283/**
19284 * Some description
19285 * @param {number} b
19286 *
19287 * @returns {string} A broken up
19288 *
19289 * tag description.
19290 */
19291// "jsdoc/tag-lines": ["error"|"warn", "always"]
19292// Message: Expected 1 line between tags but found 0
19293````
19294
19295The following patterns are not considered problems:
19296
19297````js
19298/**
19299 * Some description
19300 * @param {string} a
19301 * @param {number} b
19302 */
19303
19304/**
19305 * Some description
19306 * @param {string} a
19307 * @param {number} b
19308 */
19309// "jsdoc/tag-lines": ["error"|"warn", "never"]
19310
19311/**
19312 * @param {string} a
19313 *
19314 * @param {string} a
19315 */
19316// "jsdoc/tag-lines": ["error"|"warn", "always",{"noEndLines":true}]
19317
19318/**
19319 * @param {string} a
19320 */
19321// "jsdoc/tag-lines": ["error"|"warn", "never",{"noEndLines":true}]
19322
19323/** @param {number} b */
19324// "jsdoc/tag-lines": ["error"|"warn", "never",{"noEndLines":true}]
19325
19326/**
19327 * Some description
19328 * @param {string} a
19329 *
19330 * @param {number} b
19331 *
19332 */
19333// "jsdoc/tag-lines": ["error"|"warn", "always"]
19334
19335/**
19336 * Some description
19337 * @param {string} a
19338 *
19339 *
19340 * @param {number} b
19341 *
19342 *
19343 */
19344// "jsdoc/tag-lines": ["error"|"warn", "always",{"count":2}]
19345
19346/**
19347 * Some description
19348 * @param {string} a
19349 * @param {number} b
19350 */
19351// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"any"}}}]
19352
19353/**
19354 * Some description
19355 * @param {string} a
19356 * @param {number} b
19357 */
19358// "jsdoc/tag-lines": ["error"|"warn", "always",{"tags":{"param":{"lines":"never"}}}]
19359
19360/**
19361 * Some description
19362 * @param {number} a
19363 * @param {number} b
19364 */
19365// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"any"}}}]
19366
19367/**
19368 * Some description
19369 * @param {number} a
19370 * @param {number} b
19371 */
19372// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"param":{"lines":"never"}}}]
19373
19374/**
19375 * Some description
19376 * @param {string} a
19377 *
19378 *
19379 * @param {number} b
19380 *
19381 *
19382 */
19383// "jsdoc/tag-lines": ["error"|"warn", "never",{"count":5,"tags":{"param":{"count":2,"lines":"always"}}}]
19384
19385/**
19386 * Some description
19387 * @param {string} a
19388 * @param {number} b
19389 */
19390// "jsdoc/tag-lines": ["error"|"warn", "never",{"tags":{"anotherTag":{"lines":"always"}}}]
19391
19392/**
19393 * Some description
19394 * @param {string} a
19395 *
19396 * This is still part of `@param`.
19397 * @returns {SomeType} An extended
19398 * description.
19399 */
19400// "jsdoc/tag-lines": ["error"|"warn", "never"]
19401
19402/**
19403 * Some description
19404 * @param {string} a
19405 * @returns {SomeType} An extended
19406 * description.
19407 *
19408 * This is still part of `@returns`.
19409 */
19410// "jsdoc/tag-lines": ["error"|"warn", "never"]
19411
19412/**
19413 * Some description
19414 * @param {string} a
19415 *
19416 * This is still part of `@param`.
19417 *
19418 * @returns {SomeType} An extended
19419 * description.
19420 *
19421 */
19422// "jsdoc/tag-lines": ["error"|"warn", "always"]
19423
19424/**
19425 * Some description
19426 * @param {string} a
19427 *
19428 * @returns {SomeType} An extended
19429 * description.
19430 *
19431 * This is still part of `@returns`.
19432 *
19433 */
19434// "jsdoc/tag-lines": ["error"|"warn", "always"]
19435````
19436
19437
19438<a name="eslint-plugin-jsdoc-rules-valid-types"></a>
19439### <code>valid-types</code>
19440
19441Requires all types to be valid JSDoc, Closure, or TypeScript compiler types
19442without syntax errors. Note that what determines a valid type is handled by
19443our type parsing engine, [jsdoctypeparser](https://github.com/jsdoctypeparser/jsdoctypeparser),
19444using [`settings.jsdoc.mode`](#eslint-plugin-jsdoc-settings-mode) to
19445determine whether to use jsdoctypeparser's "permissive" mode or the stricter
19446"jsdoc", "typescript", "closure" modes.
19447
19448The following tags have their "type" portions (the segment within brackets)
19449checked (though those portions may sometimes be confined to namepaths,
19450e.g., `@modifies`):
19451
194521. Tags with required types: `@type`, `@implements`
194531. Tags with required types in Closure or TypeScript: `@this`,
19454 `@define` (Closure only)
194551. Tags with optional types: `@enum`, `@member` (`@var`), `@typedef`,
19456 `@augments` (or `@extends`), `@class` (or `@constructor`), `@constant`
19457 (or `@const`), `@module` (module paths are not planned for TypeScript),
19458 `@namespace`, `@throws`, `@exception`, `@yields` (or `@yield`),
19459 `@modifies` (undocumented jsdoc); `@param` (`@arg`, `@argument`),
19460 `@property` (`@prop`), and `@returns` (`@return`) also fall into this
19461 category, but while this rule will check their type validity, we leave
19462 the requiring of the type portion to the rules `require-param-type`,
19463 `require-property-type`, and `require-returns-type`, respectively.
194641. Tags with types that are available optionally in Closure: `@export`,
19465 `@package`, `@private`, `@protected`, `@public`, `@static`;
19466 `@template` (TypeScript also)
194671. Tags with optional types that may take free text instead: `@throws`
19468
19469The following tags have their name/namepath portion (the non-whitespace
19470text after the tag name) checked:
19471
194721. Name(path)-defining tags requiring namepath: `@event`, `@callback`,
19473 `@external`, `@host`, `@name`, `@typedef`, and `@template`
19474 (TypeScript/Closure only); `@param` (`@arg`, `@argument`) and `@property`
19475 (`@prop`) also fall into this category, but while this rule will check
19476 their namepath validity, we leave the requiring of the name portion
19477 to the rules `require-param-name` and `require-property-name`,
19478 respectively.
194791. Name(path)-defining tags (which may have value without namepath or their
19480 namepath can be expressed elsewhere on the block):
19481 `@class`, `@constructor`, `@constant`, `@const`, `@function`, `@func`,
19482 `@method`, `@interface` (TypeScript tag only), `@member`, `@var`,
19483 `@mixin`, `@namespace`, `@module` (module paths are not planned for
19484 TypeScript)
194851. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`,
19486 `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
19487 (jsdoc only)
194881. Name(path)-pointing tags (which may have value without namepath or their
19489 namepath can be expressed elsewhere on the block): `@listens`, `@fires`,
19490 `@emits`.
194911. Name(path)-pointing tags which may have free text or a namepath: `@see`
194921. Name(path)-pointing tags (multiple names in one): `@borrows`
19493
19494...with the following applying to the above sets:
19495
19496- Expect tags in set 1-4 to have a valid namepath if present
19497- Prevent sets 2 and 4 from being empty by setting `allowEmptyNamepaths` to
19498 `false` as these tags might have some indicative value without a path
19499 or may allow a name expressed elsewhere on the block (but sets 1 and 3 will
19500 always fail if empty)
19501- For the special case of set 6, i.e.,
19502 `@borrows <that namepath> as <this namepath>`,
19503 check that both namepaths are present and valid and ensure there is an `as `
19504 between them. In the case of `<this namepath>`, it can be preceded by
19505 one of the name path operators, `#`, `.`, or `~`.
19506- For the special case of `@memberof` and `@memberof!` (part of set 3), as
19507 per the [specification](https://jsdoc.app/tags-memberof.html), they also
19508 allow `#`, `.`, or `~` at the end (which is not allowed at the end of
19509 normal paths).
19510
19511If you define your own tags, `settings.jsdoc.structuredTags` will allow
19512these custom tags to be checked, with the name portion of tags checked for
19513valid namepaths (based on the tag's `name` value), their type portions checked
19514for valid types (based on the tag's `type` value), and either portion checked
19515for presence (based on `false` `name` or `type` values or their `required`
19516value). See the setting for more details.
19517
19518<a name="eslint-plugin-jsdoc-rules-valid-types-options-40"></a>
19519#### Options
19520
19521- `allowEmptyNamepaths` (default: true) - Set to `false` to bulk disallow
19522 empty name paths with namepath groups 2 and 4 (these might often be
19523 expected to have an accompanying name path, though they have some
19524 indicative value without one; these may also allow names to be defined
19525 in another manner elsewhere in the block); you can use
19526 `settings.jsdoc.structuredTags` with the `required` key set to "name" if you
19527 wish to require name paths on a tag-by-tag basis.
19528
19529|||
19530|---|---|
19531|Context|everywhere|
19532|Tags|For name only unless otherwise stated: `alias`, `augments`, `borrows`, `callback`, `class` (for name and type), `constant` (for name and type), `enum` (for type), `event`, `external`, `fires`, `function`, `implements` (for type), `interface`, `lends`, `listens`, `member` (for name and type), `memberof`, `memberof!`, `mixes`, `mixin`, `modifies`, `module` (for name and type), `name`, `namespace` (for name and type), `param` (for name and type), `property` (for name and type), `returns` (for type), `see` (optionally for name), `this`, `throws` (for type), `type` (for type), `typedef` (for name and type), `yields` (for type)|
19533|Aliases|`extends`, `constructor`, `const`, `host`, `emits`, `func`, `method`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
19534|Closure-only|For type only: `package`, `private`, `protected`, `public`, `static`|
19535|Recommended|true|
19536|Options|`allowEmptyNamepaths`|
19537|Settings|`mode`, `structuredTags`|
19538
19539The following patterns are considered problems:
19540
19541````js
19542/**
19543 * @param {Array<string} foo
19544 */
19545function quux() {
19546
19547}
19548// Message: Syntax error in type: Array<string
19549
19550/**
19551 * @memberof module:namespace.SomeClass<~
19552 */
19553function quux() {
19554
19555}
19556// Message: Syntax error in namepath: module:namespace.SomeClass<~
19557
19558/**
19559 * @param someParam<~
19560 */
19561function quux() {
19562
19563}
19564// Message: Syntax error in namepath: someParam<~
19565
19566/**
19567 * @memberof module:namespace.SomeClass~<
19568 */
19569function quux() {
19570
19571}
19572// Message: Syntax error in namepath: module:namespace.SomeClass~<
19573
19574/**
19575 * @borrows foo% as bar
19576 */
19577function quux() {
19578
19579}
19580// Message: Syntax error in namepath: foo%
19581
19582/**
19583 * @borrows #foo as bar
19584 */
19585function quux() {
19586
19587}
19588// Message: Syntax error in namepath: #foo
19589
19590/**
19591 * @borrows foo as bar%
19592 */
19593function quux() {
19594
19595}
19596// Message: Syntax error in namepath: bar%
19597
19598/**
19599 * @borrows foo
19600 */
19601function quux() {
19602
19603}
19604// Message: @borrows must have an "as" expression. Found ""
19605
19606/**
19607 * @see foo%
19608 */
19609function quux() {
19610
19611}
19612// Settings: {"jsdoc":{"structuredTags":{"see":{"name":"namepath-referencing","required":["name"]}}}}
19613// Message: Syntax error in namepath: foo%
19614
19615/**
19616 * @mixes module:namespace.SomeClass~
19617 */
19618function quux() {
19619
19620}
19621// Message: Syntax error in namepath: module:namespace.SomeClass~
19622
19623/**
19624 * @callback
19625 */
19626function quux() {
19627
19628}
19629// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}]
19630// Message: Tag @callback must have a name/namepath.
19631
19632/**
19633 * @constant {str%ng}
19634 */
19635 const FOO = 'foo';
19636// Message: Syntax error in type: str%ng
19637
19638/**
19639 * @typedef {str%ng} UserString
19640 */
19641// Message: Syntax error in type: str%ng
19642
19643/**
19644 * @typedef {string} UserStr%ng
19645 */
19646// Message: Syntax error in namepath: UserStr%ng
19647
19648/**
19649 * @this
19650 */
19651 class Bar {};
19652// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}]
19653// Message: Tag @this must have either a type or namepath in "jsdoc" mode.
19654
19655/**
19656 * @aCustomTag
19657 */
19658// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"required":["typeOrNameRequired"]}}}}
19659// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}]
19660// Message: Tag @aCustomTag must have either a type or namepath.
19661
19662/**
19663 * @type
19664 */
19665 let foo;
19666// Message: Tag @type must have a type.
19667
19668/**
19669 * @modifies {bar | foo<}
19670 */
19671function quux (foo, bar, baz) {}
19672// Message: Syntax error in type: bar | foo<
19673
19674/**
19675 * @private {BadTypeChecked<}
19676 */
19677function quux () {}
19678// Settings: {"jsdoc":{"mode":"closure"}}
19679// Message: Syntax error in type: BadTypeChecked<
19680
19681/**
19682 * @this {BadTypeChecked<}
19683 */
19684function quux () {}
19685// Settings: {"jsdoc":{"mode":"closure"}}
19686// Message: Syntax error in type: BadTypeChecked<
19687
19688/**
19689 * @define
19690 */
19691 function quux () {}
19692// Settings: {"jsdoc":{"mode":"closure"}}
19693// Message: Tag @define must have a type in "closure" mode.
19694
19695/**
19696 * @this
19697 */
19698 let foo;
19699// Settings: {"jsdoc":{"mode":"closure"}}
19700// Message: Tag @this must have a type in "closure" mode.
19701
19702/**
19703 * Foo function.
19704 *
19705 * @param {[number, string]} bar - The bar array.
19706 */
19707function foo(bar) {}
19708// Settings: {"jsdoc":{"mode":"jsdoc"}}
19709// Message: Syntax error in type: [number, string]
19710
19711/**
19712 * @interface name<
19713 */
19714// Settings: {"jsdoc":{"mode":"jsdoc"}}
19715// Message: Syntax error in namepath: name<
19716
19717/**
19718 * @module name<
19719 */
19720// Settings: {"jsdoc":{"mode":"jsdoc"}}
19721// Message: Syntax error in namepath: name<
19722
19723/**
19724 * @module module:name<
19725 */
19726// Settings: {"jsdoc":{"mode":"jsdoc"}}
19727// Message: Syntax error in namepath: module:name<
19728
19729/**
19730 * @interface name
19731 */
19732// Settings: {"jsdoc":{"mode":"closure"}}
19733// Message: @interface should not have a name in "closure" mode.
19734
19735/**
19736 * @aCustomTag name
19737 */
19738// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"name":false}}}}
19739// Message: @aCustomTag should not have a name.
19740
19741/**
19742 * @typedef {SomeType}
19743 */
19744function quux () {}
19745// Settings: {"jsdoc":{"mode":"jsdoc"}}
19746// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}]
19747// Message: Tag @typedef must have a name/namepath in "jsdoc" mode.
19748
19749/**
19750 * @private {SomeType}
19751 */
19752function quux () {}
19753// Settings: {"jsdoc":{"mode":"jsdoc"}}
19754// Message: @private should not have a bracketed type in "jsdoc" mode.
19755
19756/**
19757 * @aCustomTag {SomeType}
19758 */
19759function quux () {}
19760// Settings: {"jsdoc":{"structuredTags":{"aCustomTag":{"type":false}}}}
19761// Message: @aCustomTag should not have a bracketed type.
19762
19763/**
19764 * @see foo%
19765 */
19766function quux() {
19767
19768}
19769// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["name"]}}}}
19770// Message: Cannot add "name" to `require` with the tag's `name` set to `false`
19771
19772/**
19773 * @see foo%
19774 */
19775function quux() {
19776
19777}
19778// Settings: {"jsdoc":{"structuredTags":{"see":{"required":["type"],"type":false}}}}
19779// Message: Cannot add "type" to `require` with the tag's `type` set to `false`
19780
19781/**
19782 * @see foo%
19783 */
19784function quux() {
19785
19786}
19787// Settings: {"jsdoc":{"structuredTags":{"see":{"name":false,"required":["typeOrNameRequired"]}}}}
19788// Message: Cannot add "typeOrNameRequired" to `require` with the tag's `name` set to `false`
19789
19790/**
19791 * @see foo%
19792 */
19793function quux() {
19794
19795}
19796// Settings: {"jsdoc":{"structuredTags":{"see":{"required":["typeOrNameRequired"],"type":false}}}}
19797// Message: Cannot add "typeOrNameRequired" to `require` with the tag's `type` set to `false`
19798
19799/**
19800 * @template T<~, R
19801 * @param {function(!T): !R} parser
19802 * @return {function(!Array<!T>): !Array<!R>}
19803 */
19804parseArray = function(parser) {
19805 return function(array) {
19806 return array.map(parser);
19807 };
19808};
19809// Settings: {"jsdoc":{"mode":"closure"}}
19810// Message: Syntax error in namepath: T<~
19811
19812/**
19813 * @template T, R<~
19814 * @param {function(!T): !R} parser
19815 * @return {function(!Array<!T>): !Array<!R>}
19816 */
19817parseArray = function(parser) {
19818 return function(array) {
19819 return array.map(parser);
19820 };
19821};
19822// Settings: {"jsdoc":{"mode":"closure"}}
19823// Message: Syntax error in namepath: R<~
19824
19825/**
19826 * @template T, R<~
19827 * @param {function(!T): !R} parser
19828 * @return {function(!Array<!T>): !Array<!R>}
19829 */
19830parseArray = function(parser) {
19831 return function(array) {
19832 return array.map(parser);
19833 };
19834};
19835// Settings: {"jsdoc":{"mode":"closure"}}
19836// Message: Syntax error in namepath: R<~
19837````
19838
19839The following patterns are not considered problems:
19840
19841````js
19842/**
19843 * @param {Array<string>} foo
19844 */
19845function quux() {
19846
19847}
19848
19849/**
19850 * @param {string} foo
19851 */
19852function quux() {
19853
19854}
19855
19856/**
19857 * @param foo
19858 */
19859function quux() {
19860
19861}
19862
19863/**
19864 * @borrows foo as bar
19865 */
19866function quux() {
19867
19868}
19869
19870/**
19871 * @borrows foo as #bar
19872 */
19873function quux() {
19874
19875}
19876
19877/**
19878 * @see foo%
19879 */
19880function quux() {
19881
19882}
19883
19884/**
19885 * @alias module:namespace.SomeClass#event:ext_anevent
19886 */
19887function quux() {
19888
19889}
19890
19891/**
19892 * @callback foo
19893 */
19894function quux() {
19895
19896}
19897
19898/**
19899 * @callback
19900 */
19901function quux() {
19902
19903}
19904// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":true}]
19905
19906/**
19907 * @class
19908 */
19909function quux() {
19910
19911}
19912
19913/**
19914 * @see {@link foo}
19915 */
19916function quux() {
19917
19918}
19919// Settings: {"jsdoc":{"structuredTags":{"see":{"name":"namepath-referencing","required":["name"]}}}}
19920
19921/**
19922 *
19923 * @fires {module:namespace.SomeClass#event:ext_anevent}
19924 */
19925function quux() {
19926
19927}
19928
19929/**
19930 * @memberof module:namespace.SomeClass~
19931 */
19932function quux() {
19933
19934}
19935
19936/**
19937 * @memberof! module:namespace.SomeClass.
19938 */
19939function quux() {
19940
19941}
19942
19943/**
19944 *
19945 */
19946function quux() {
19947
19948}
19949
19950/**
19951 * @aCustomTag
19952 */
19953function quux() {
19954
19955}
19956
19957/**
19958 * @constant {string}
19959 */
19960 const FOO = 'foo';
19961
19962/**
19963 * @constant {string} FOO
19964 */
19965 const FOO = 'foo';
19966
19967/**
19968 * @extends Foo
19969 */
19970 class Bar {};
19971
19972/**
19973 * @extends Foo<String>
19974 */
19975 class Bar {};
19976
19977/**
19978 * @extends {Foo<String>}
19979 */
19980 class Bar {};
19981// Settings: {"jsdoc":{"mode":"closure"}}
19982
19983/**
19984 * @typedef {number | string} UserDefinedType
19985 */
19986
19987/**
19988 * @typedef {number | string}
19989 */
19990let UserDefinedGCCType;
19991// Settings: {"jsdoc":{"mode":"closure"}}
19992
19993/**
19994 * @modifies {foo | bar}
19995 */
19996function quux (foo, bar, baz) {}
19997
19998/**
19999 * @this {Navigator}
20000 */
20001function quux () {}
20002// Settings: {"jsdoc":{"mode":"closure"}}
20003
20004/**
20005 * @export {SomeType}
20006 */
20007function quux () {}
20008// Settings: {"jsdoc":{"mode":"closure"}}
20009
20010/**
20011 * @define {boolean}
20012 */
20013function quux () {}
20014// Settings: {"jsdoc":{"mode":"closure"}}
20015
20016/**
20017 * @define
20018 */
20019 function quux () {}
20020
20021/**
20022 * Foo function.
20023 *
20024 * @interface foo
20025 */
20026function foo(bar) {}
20027// Settings: {"jsdoc":{"mode":"typescript"}}
20028
20029/**
20030 * Foo function.
20031 *
20032 * @param {[number, string]} bar - The bar array.
20033 */
20034function foo(bar) {}
20035// Settings: {"jsdoc":{"mode":"typescript"}}
20036
20037/**
20038 * Foo function.
20039 *
20040 * @param {[number, string]} bar - The bar array.
20041 */
20042function foo(bar) {}
20043
20044/**
20045 * Foo function.
20046 *
20047 * @param {[number, string]} bar - The bar array.
20048 */
20049function foo(bar) {}
20050// Settings: {"jsdoc":{"mode":"permissive"}}
20051
20052/**
20053 * @typedef {SomeType}
20054 */
20055function quux () {}
20056// Settings: {"jsdoc":{"mode":"closure"}}
20057// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}]
20058
20059/**
20060 * @private {SomeType}
20061 */
20062function quux () {}
20063// Settings: {"jsdoc":{"mode":"closure"}}
20064
20065/**
20066 * @param
20067 */
20068function quux() {
20069
20070}
20071// "jsdoc/valid-types": ["error"|"warn", {"allowEmptyNamepaths":false}]
20072
20073/**
20074 * @see
20075 */
20076function quux() {
20077
20078}
20079// Settings: {"jsdoc":{"structuredTags":{"see":{"name":"namepath-referencing"}}}}
20080
20081/**
20082 * @template T, R
20083 * @param {function(!T): !R} parser
20084 * @return {function(!Array<!T>): !Array<!R>}
20085 */
20086parseArray = function(parser) {
20087 return function(array) {
20088 return array.map(parser);
20089 };
20090};
20091// Settings: {"jsdoc":{"mode":"closure"}}
20092
20093/**
20094 * @template T, R<~
20095 * @param {function(!T): !R} parser
20096 * @return {function(!Array<!T>): !Array<!R>}
20097 */
20098parseArray = function(parser) {
20099 return function(array) {
20100 return array.map(parser);
20101 };
20102};
20103// Settings: {"jsdoc":{"mode":"jsdoc"}}
20104
20105/**
20106 * @template {string} K - K must be a string or string literal
20107 * @template {{ serious: string }} Seriousalizable - must have a serious property
20108 * @param {K} key
20109 * @param {Seriousalizable} object
20110 */
20111function seriousalize(key, object) {
20112 // ????
20113}
20114// Settings: {"jsdoc":{"mode":"typescript"}}
20115
20116/**
20117 * @module foo/bar
20118 */
20119
20120/**
20121 * @module module:foo/bar
20122 */
20123
20124/**
20125 * @template invalid namepath,T Description
20126 */
20127function f() {}
20128// Settings: {"jsdoc":{"mode":"closure"}}
20129
20130/**
20131 * Description of complicated type.
20132 *
20133 * @template T Description of the T type parameter.
20134 * @template U - Like other tags, this can have an optional hyphen before the description.
20135 * @template V,W More parameters
20136 * @template W,X - Also with a hyphen
20137 */
20138type ComplicatedType<T, U, V, W, X> = never
20139
20140/** Multi-line typedef for an options object type.
20141 *
20142 * @typedef {{
20143 * prop: number
20144 * }} MyOptions
20145 */
20146````
20147
20148
20149
\No newline at end of file