UNPKG

212 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](http://img.shields.io/npm/v/eslint-plugin-jsdoc.svg?style=flat-square)](https://www.npmjs.org/package/eslint-plugin-jsdoc)
6[![Travis build status](http://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
9JSDoc linting rules for ESLint.
10
11* [eslint-plugin-jsdoc](#eslint-plugin-jsdoc)
12 * [Installation](#eslint-plugin-jsdoc-installation)
13 * [Configuration](#eslint-plugin-jsdoc-configuration)
14 * [Options](#eslint-plugin-jsdoc-options)
15 * [Settings](#eslint-plugin-jsdoc-settings)
16 * [Allow `@private` to disable rules for that comment block](#eslint-plugin-jsdoc-settings-allow-private-to-disable-rules-for-that-comment-block)
17 * [Mode](#eslint-plugin-jsdoc-settings-mode)
18 * [Alias Preference](#eslint-plugin-jsdoc-settings-alias-preference)
19 * [`@override`/`@augments`/`@extends`/`@implements` Without Accompanying `@param`/`@description`/`@example`/`@returns`](#eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns)
20 * [Settings to Configure `check-types` and `no-undefined-types`](#eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types)
21 * [Rules](#eslint-plugin-jsdoc-rules)
22 * [`check-access`](#eslint-plugin-jsdoc-rules-check-access)
23 * [`check-alignment`](#eslint-plugin-jsdoc-rules-check-alignment)
24 * [`check-examples`](#eslint-plugin-jsdoc-rules-check-examples)
25 * [`check-indentation`](#eslint-plugin-jsdoc-rules-check-indentation)
26 * [`check-param-names`](#eslint-plugin-jsdoc-rules-check-param-names)
27 * [`check-property-names`](#eslint-plugin-jsdoc-rules-check-property-names)
28 * [`check-syntax`](#eslint-plugin-jsdoc-rules-check-syntax)
29 * [`check-tag-names`](#eslint-plugin-jsdoc-rules-check-tag-names)
30 * [`check-types`](#eslint-plugin-jsdoc-rules-check-types)
31 * [`check-values`](#eslint-plugin-jsdoc-rules-check-values)
32 * [`empty-tags`](#eslint-plugin-jsdoc-rules-empty-tags)
33 * [`implements-on-classes`](#eslint-plugin-jsdoc-rules-implements-on-classes)
34 * [`match-description`](#eslint-plugin-jsdoc-rules-match-description)
35 * [`newline-after-description`](#eslint-plugin-jsdoc-rules-newline-after-description)
36 * [`no-types`](#eslint-plugin-jsdoc-rules-no-types)
37 * [`no-undefined-types`](#eslint-plugin-jsdoc-rules-no-undefined-types)
38 * [`require-description-complete-sentence`](#eslint-plugin-jsdoc-rules-require-description-complete-sentence)
39 * [`require-description`](#eslint-plugin-jsdoc-rules-require-description)
40 * [`require-example`](#eslint-plugin-jsdoc-rules-require-example)
41 * [`require-file-overview`](#eslint-plugin-jsdoc-rules-require-file-overview)
42 * [`require-hyphen-before-param-description`](#eslint-plugin-jsdoc-rules-require-hyphen-before-param-description)
43 * [`require-jsdoc`](#eslint-plugin-jsdoc-rules-require-jsdoc)
44 * [`require-param-description`](#eslint-plugin-jsdoc-rules-require-param-description)
45 * [`require-param-name`](#eslint-plugin-jsdoc-rules-require-param-name)
46 * [`require-param-type`](#eslint-plugin-jsdoc-rules-require-param-type)
47 * [`require-param`](#eslint-plugin-jsdoc-rules-require-param)
48 * [`require-property`](#eslint-plugin-jsdoc-rules-require-property)
49 * [`require-property-description`](#eslint-plugin-jsdoc-rules-require-property-description)
50 * [`require-property-name`](#eslint-plugin-jsdoc-rules-require-property-name)
51 * [`require-property-type`](#eslint-plugin-jsdoc-rules-require-property-type)
52 * [`require-returns-check`](#eslint-plugin-jsdoc-rules-require-returns-check)
53 * [`require-returns-description`](#eslint-plugin-jsdoc-rules-require-returns-description)
54 * [`require-returns-type`](#eslint-plugin-jsdoc-rules-require-returns-type)
55 * [`require-returns`](#eslint-plugin-jsdoc-rules-require-returns)
56 * [`valid-types`](#eslint-plugin-jsdoc-rules-valid-types)
57
58
59<a name="eslint-plugin-jsdoc-installation"></a>
60## Installation
61
62Install [ESLint](https://www.github.com/eslint/eslint) either locally or globally.
63
64```sh
65npm install --save-dev eslint
66```
67
68If you have installed `ESLint` globally, you have to install JSDoc plugin globally too. Otherwise, install it locally.
69
70```sh
71npm install --save-dev eslint-plugin-jsdoc
72```
73
74<a name="eslint-plugin-jsdoc-configuration"></a>
75## Configuration
76
77Add `plugins` section and specify `eslint-plugin-jsdoc` as a plugin.
78
79```json
80{
81 "plugins": [
82 "jsdoc"
83 ]
84}
85```
86
87Finally, enable all of the rules that you would like to use.
88
89```javascript
90{
91 "rules": {
92 "jsdoc/check-alignment": 1, // Recommended
93 "jsdoc/check-examples": 1,
94 "jsdoc/check-indentation": 1,
95 "jsdoc/check-param-names": 1, // Recommended
96 "jsdoc/check-syntax": 1,
97 "jsdoc/check-tag-names": 1, // Recommended
98 "jsdoc/check-types": 1, // Recommended
99 "jsdoc/implements-on-classes": 1, // Recommended
100 "jsdoc/match-description": 1,
101 "jsdoc/newline-after-description": 1, // Recommended
102 "jsdoc/no-types": 1,
103 "jsdoc/no-undefined-types": 1, // Recommended
104 "jsdoc/require-description": 1,
105 "jsdoc/require-description-complete-sentence": 1,
106 "jsdoc/require-example": 1,
107 "jsdoc/require-hyphen-before-param-description": 1,
108 "jsdoc/require-jsdoc": 1, // Recommended
109 "jsdoc/require-param": 1, // Recommended
110 "jsdoc/require-param-description": 1, // Recommended
111 "jsdoc/require-param-name": 1, // Recommended
112 "jsdoc/require-param-type": 1, // Recommended
113 "jsdoc/require-returns": 1, // Recommended
114 "jsdoc/require-returns-check": 1, // Recommended
115 "jsdoc/require-returns-description": 1, // Recommended
116 "jsdoc/require-returns-type": 1, // Recommended
117 "jsdoc/valid-types": 1 // Recommended
118 }
119}
120```
121
122Or you can simply use the following which enables the rules commented
123above as "recommended":
124
125```json
126{
127 "extends": ["plugin:jsdoc/recommended"]
128}
129```
130
131You can then selectively add to or override the recommended rules.
132
133<a name="eslint-plugin-jsdoc-options"></a>
134## Options
135
136Rules 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,
137such as, `exemptedBy` and `contexts`, may be used across different rules.
138
139`eslint-plugin-jsdoc` options, if present, are in the form of an object
140supplied as the second argument in an array after the error level.
141
142```js
143// `.eslintrc.js`
144{
145 rules: {
146 'jsdoc/require-example': [
147 // The Error level should be `error`, `warn`, or `off` (or 2, 1, or 0)
148 'error',
149 // The options vary by rule, but are added to an options object:
150 {
151 avoidExampleOnConstructors: true,
152 exemptedBy: ['type']
153 }
154 ]
155 }
156}
157```
158
159<a name="eslint-plugin-jsdoc-settings"></a>
160## Settings
161
162<a name="eslint-plugin-jsdoc-settings-allow-private-to-disable-rules-for-that-comment-block"></a>
163### Allow <code>@private</code> to disable rules for that comment block
164
165- `settings.jsdoc.ignorePrivate` - Disables all rules for the comment block
166 on which a `@private` tag (or `@access private`) occurs. Defaults to
167 `false`. Note: This has no effect with the rule `check-access` (whose
168 purpose is to check access modifiers).
169
170<a name="eslint-plugin-jsdoc-settings-mode"></a>
171### Mode
172
173- `settings.jsdoc.mode` - Set to `jsdoc` (the default), `typescript`, or `closure`.
174 Currently is used for the following:
175 - Determine valid tags for `check-tag-names`
176 - Only check `@template` in `no-undefined-types` for types in "closure" and
177 "typescript" modes
178 - For type-checking rules, determine which tags will be checked for types
179 (Closure allows types on some tags which the others do not,
180 so these tags will additionally be checked in "closure" mode)
181 - Check preferred tag names
182
183<a name="eslint-plugin-jsdoc-settings-alias-preference"></a>
184### Alias Preference
185
186Use `settings.jsdoc.tagNamePreference` to configure a preferred alias name for a JSDoc tag. The format of the configuration is: `<primary tag name>: <preferred alias name>`, e.g.
187
188```json
189{
190 "rules": {},
191 "settings": {
192 "jsdoc": {
193 "tagNamePreference": {
194 "param": "arg",
195 "returns": "return"
196 }
197 }
198 }
199}
200```
201
202One may also use an object with a `message` and `replacement`.
203
204The following will report the message `@extends is to be used over @augments as it is more evocative of classes than @augments` upon encountering `@augments`.
205
206```json
207{
208 "rules": {},
209 "settings": {
210 "jsdoc": {
211 "tagNamePreference": {
212 "augments": {
213 "message": "@extends is to be used over @augments as it is more evocative of classes than @augments",
214 "replacement": "extends"
215 }
216 }
217 }
218 }
219}
220```
221
222If one wishes to reject a normally valid tag, e.g., `@todo`, one may set the tag to `false`:
223
224```json
225{
226 "rules": {},
227 "settings": {
228 "jsdoc": {
229 "tagNamePreference": {
230 "todo": false
231 }
232 }
233 }
234}
235```
236
237A project wishing to ensure no blocks are left excluded from entering the
238documentation, might wish to prevent the `@ignore` tag in the above manner.
239
240Or one may set the targeted tag to an object with a custom `message`, but without a `replacement` property:
241
242```json
243{
244 "rules": {},
245 "settings": {
246 "jsdoc": {
247 "tagNamePreference": {
248 "todo": {
249 "message": "We expect immediate perfection, so don't leave to-dos in your code."
250 }
251 }
252 }
253 }
254}
255```
256
257Note that the preferred tags indicated in the `settings.jsdoc.tagNamePreference`
258map will be assumed to be defined by `check-tag-names`.
259
260<a name="eslint-plugin-jsdoc-settings-alias-preference-default-preferred-aliases"></a>
261#### Default Preferred Aliases
262
263The defaults in `eslint-plugin-jsdoc` (for tags which offer
264aliases) are as follows:
265
266- `@abstract` (over `@virtual`)
267- `@augments` (over `@extends`)
268- `@class` (over `@constructor`)
269- `@constant` (over `@const`)
270- `@default` (over `@defaultvalue`)
271- `@description` (over `@desc`)
272- `@external` (over `@host`)
273- `@file` (over `@fileoverview`, `@overview`)
274- `@fires` (over `@emits`)
275- `@function` (over `@func`, `@method`)
276- `@member` (over `@var`)
277- `@param` (over `@arg`, `@argument`)
278- `@property` (over `@prop`)
279- `@returns` (over `@return`)
280- `@throws` (over `@exception`)
281- `@yields` (over `@yield`)
282
283This setting is utilized by the the rule for tag name checking
284(`check-tag-names`) as well as in the `@param` and `@require` rules:
285
286- `check-param-names`
287- `check-tag-names`
288- `require-hyphen-before-param-description`
289- `require-description`
290- `require-param`
291- `require-param-description`
292- `require-param-name`
293- `require-param-type`
294- `require-returns`
295- `require-returns-check`
296- `require-returns-description`
297- `require-returns-type`
298
299<a name="eslint-plugin-jsdoc-settings-override-augments-extends-implements-without-accompanying-param-description-example-returns"></a>
300### <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>
301
302The following settings allows the element(s) they reference to be omitted
303on the JSDoc comment block of the function or that of its parent class
304for any of the "require" rules (i.e., `require-param`, `require-description`,
305`require-example`, or `require-returns`).
306
307* `settings.jsdoc.overrideReplacesDocs` (`@override`) - Defaults to `true`
308* `settings.jsdoc.augmentsExtendsReplacesDocs` (`@augments` or its alias `@extends`) - Defaults to `false`.
309* `settings.jsdoc.implementsReplacesDocs` (`@implements`) - Defaults to `false`
310
311The format of the configuration is as follows:
312
313```json
314{
315 "rules": {},
316 "settings": {
317 "jsdoc": {
318 "overrideReplacesDocs": true,
319 "augmentsExtendsReplacesDocs": true,
320 "implementsReplacesDocs": true
321 }
322 }
323}
324```
325
326<a name="eslint-plugin-jsdoc-settings-settings-to-configure-check-types-and-no-undefined-types"></a>
327### Settings to Configure <code>check-types</code> and <code>no-undefined-types</code>
328
329- `settings.jsdoc.preferredTypes` An option map to indicate preferred
330 or forbidden types (if default types are indicated here, these will
331 have precedence over the default recommendations for `check-types`).
332 The keys of this map are the types to be replaced (or forbidden).
333 These keys may include:
334 1. The "ANY" type, `*`
335 1. The pseudo-type `[]` which we use to denote the parent (array)
336 types used in the syntax `string[]`, `number[]`, etc.
337 1. The pseudo-type `.<>` (or `.`) to represent the format `Array.<value>`
338 or `Object.<key, value>`
339 1. The pseudo-type `<>` to represent the format `Array<value>` or
340 `Object<key, value>`
341 1. A plain string type, e.g., `MyType`
342 1. A plain string type followed by one of the above pseudo-types (except
343 for `[]` which is always assumed to be an `Array`), e.g., `Array.`, or
344 `SpecialObject<>`.
345
346 If a bare pseudo-type is used, it will match all parent types of that form.
347 If a pseudo-type prefixed with a type name is used, it will only match
348 parent types of that form and type name.
349
350 The values can be:
351 - `false` to forbid the type
352 - a string to indicate the type that should be preferred in its place
353 (and which `fix` mode can replace); this can be one of the formats
354 of the keys described above.
355 - Note that the format will not be changed unless you use a pseudo-type
356 in the replacement. (For example, `'Array.<>': 'MyArray'` will change
357 `Array.<string>` to `MyArray.<string>`, preserving the dot. To get rid
358 of the dot, you must use the pseudo-type with `<>`, i.e.,
359 `'Array.<>': 'MyArray<>'`, which will change `Array.<string>` to
360 `MyArray<string>`).
361 - If you use a _bare_ pseudo-type in the replacement (e.g.,
362 `'MyArray.<>': '<>'`), the type will be converted to the format
363 of the pseudo-type without changing the type name. For example,
364 `MyArray.<string>` will become `MyArray<string>` but `Array.<string>`
365 will not be modified.
366 - an object with:
367 - the key `message` to provide a specific error message
368 when encountering the discouraged type.
369 - The message string will have the substrings with special meaning,
370 `{{tagName}}` and `{{tagValue}}`, replaced with their
371 corresponding value.
372 - an optional key `replacement` with either of the following values:
373 - a string type to be preferred in its place (and which `fix` mode
374 can replace)
375 - `false` (for forbidding the type)
376
377Note that the preferred types indicated as targets in `settings.jsdoc.preferredTypes`
378map will be assumed to be defined by `no-undefined-types`.
379
380See the option of `check-types`, `unifyParentAndChildTypeChecks`, for
381how the keys of `preferredTypes` may have `<>` or `.<>` (or just `.`)
382appended and its bearing on whether types are checked as parents/children
383only (e.g., to match `Array` if the type is `Array` vs. `Array.<string>`).
384
385<a name="eslint-plugin-jsdoc-rules"></a>
386## Rules
387
388<a name="eslint-plugin-jsdoc-rules-check-access"></a>
389### <code>check-access</code>
390
391Checks that `@access` tags use one of the following values:
392
393- "package", "private", "protected", "public"
394
395Also reports:
396
397- Mixing of `@access` with `@public`, `@private`, `@protected`, or `@package`
398 on the same doc block.
399- Use of multiple instances of `@access` (or the `@public`, etc. style tags)
400 on the same doc block.
401
402|||
403|---|---|
404|Context|everywhere|
405|Tags|`@access`|
406|Settings||
407|Options||
408
409The following patterns are considered problems:
410
411````js
412/**
413 * @access foo
414 */
415function quux (foo) {
416
417}
418// Message: Missing valid JSDoc @access level.
419
420/**
421 * @access foo
422 */
423function quux (foo) {
424
425}
426// Settings: {"jsdoc":{"ignorePrivate":true}}
427// Message: Missing valid JSDoc @access level.
428
429/**
430 * @accessLevel foo
431 */
432function quux (foo) {
433
434}
435// Settings: {"jsdoc":{"tagNamePreference":{"access":"accessLevel"}}}
436// Message: Missing valid JSDoc @accessLevel level.
437
438/**
439 * @access
440 */
441function quux (foo) {
442
443}
444// Settings: {"jsdoc":{"tagNamePreference":{"access":false}}}
445// Message: Unexpected tag `@access`
446
447class MyClass {
448 /**
449 * @access
450 */
451 myClassField = 1
452}
453// Message: Missing valid JSDoc @access level.
454
455/**
456 * @access public
457 * @public
458 */
459function quux (foo) {
460
461}
462// Message: The @access tag may not be used with specific access-control tags (@package, @private, @protected, or @public).
463
464/**
465 * @access public
466 * @access private
467 */
468function quux (foo) {
469
470}
471// Message: At most one access-control tag may be present on a jsdoc block.
472
473/**
474 * @access public
475 * @access private
476 */
477function quux (foo) {
478
479}
480// Settings: {"jsdoc":{"ignorePrivate":true}}
481// Message: At most one access-control tag may be present on a jsdoc block.
482
483/**
484 * @public
485 * @private
486 */
487function quux (foo) {
488
489}
490// Message: At most one access-control tag may be present on a jsdoc block.
491
492/**
493 * @public
494 * @private
495 */
496function quux (foo) {
497
498}
499// Settings: {"jsdoc":{"ignorePrivate":true}}
500// Message: At most one access-control tag may be present on a jsdoc block.
501
502/**
503 * @public
504 * @public
505 */
506function quux (foo) {
507
508}
509// Message: At most one access-control tag may be present on a jsdoc block.
510````
511
512The following patterns are not considered problems:
513
514````js
515/**
516 *
517 */
518function quux (foo) {
519
520}
521
522/**
523 * @access public
524 */
525function quux (foo) {
526
527}
528
529/**
530 * @accessLevel package
531 */
532function quux (foo) {
533
534}
535// Settings: {"jsdoc":{"tagNamePreference":{"access":"accessLevel"}}}
536
537class MyClass {
538 /**
539 * @access private
540 */
541 myClassField = 1
542}
543
544/**
545 * @public
546 */
547function quux (foo) {
548
549}
550
551/**
552 * @private
553 */
554function quux (foo) {
555
556}
557// Settings: {"jsdoc":{"ignorePrivate":true}}
558````
559
560
561<a name="eslint-plugin-jsdoc-rules-check-alignment"></a>
562### <code>check-alignment</code>
563
564Reports invalid alignment of JSDoc block asterisks.
565
566|||
567|---|---|
568|Context|everywhere|
569|Tags|N/A|
570
571The following patterns are considered problems:
572
573````js
574/**
575 * @param {Number} foo
576 */
577function quux (foo) {
578 // with spaces
579}
580// Message: Expected JSDoc block to be aligned.
581
582/**
583 * @param {Number} foo
584 */
585function quux (foo) {
586 // with tabs
587}
588// Message: Expected JSDoc block to be aligned.
589
590/**
591 * @param {Number} foo
592 */
593function quux (foo) {
594 // with spaces
595}
596// Message: Expected JSDoc block to be aligned.
597
598/**
599* @param {Number} foo
600*/
601function quux (foo) {
602 // with spaces
603}
604// Message: Expected JSDoc block to be aligned.
605
606/**
607 * @param {Number} foo
608 */
609function quux (foo) {
610
611}
612// Message: Expected JSDoc block to be aligned.
613
614 /**
615 * @param {Number} foo
616 */
617function quux (foo) {
618
619}
620// Message: Expected JSDoc block to be aligned.
621
622 /**
623 * @param {Number} foo
624 */
625function quux (foo) {
626
627}
628// Message: Expected JSDoc block to be aligned.
629
630/**
631 * @param {Number} foo
632 */
633 function quux (foo) {
634
635 }
636// Message: Expected JSDoc block to be aligned.
637
638/**
639 * A jsdoc not attached to any node.
640 */
641// Message: Expected JSDoc block to be aligned.
642
643class Foo {
644 /**
645 * Some method
646 * @param a
647 */
648 quux(a) {}
649}
650// Message: Expected JSDoc block to be aligned.
651````
652
653The following patterns are not considered problems:
654
655````js
656/**
657 * Desc
658 *
659 * @param {Number} foo
660 */
661function quux (foo) {
662
663}
664
665/**
666 * Desc
667 *
668 * @param {{
669 foo: Bar,
670 bar: Baz
671 * }} foo
672 *
673 */
674function quux (foo) {
675
676}
677
678/* <- JSDoc must start with 2 stars.
679 * So this is unchecked.
680 */
681function quux (foo) {}
682
683/**
684 * @param {Number} foo
685 * @private
686 */
687function quux (foo) {
688 // with spaces
689}
690// Settings: {"jsdoc":{"ignorePrivate":true}}
691
692/**
693 * @param {Number} foo
694 * @access private
695 */
696function quux (foo) {
697 // with spaces
698}
699// Settings: {"jsdoc":{"ignorePrivate":true}}
700````
701
702
703<a name="eslint-plugin-jsdoc-rules-check-examples"></a>
704### <code>check-examples</code>
705
706Ensures that (JavaScript) examples within JSDoc adhere to ESLint rules.
707
708<a name="eslint-plugin-jsdoc-rules-check-examples-options-1"></a>
709#### Options
710
711The options below all default to no-op/`false` except as noted.
712
713<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-captionrequired"></a>
714##### <code>captionRequired</code>
715
716JSDoc specs use of an optional `<caption>` element at the beginning of
717`@example`.
718
719The option `captionRequired` insists on a `<caption>` being present at
720the beginning of any `@example`.
721
722<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-examplecoderegex-and-rejectexamplecoderegex"></a>
723##### <code>exampleCodeRegex</code> and <code>rejectExampleCodeRegex</code>
724
725JSDoc does not specify a formal means for delimiting code blocks within
726`@example` (it uses generic syntax highlighting techniques for its own
727syntax highlighting). The following options determine whether a given
728`@example` tag will have the `check-examples` checks applied to it:
729
730* `exampleCodeRegex` - Regex which whitelists lintable
731 examples. If a parenthetical group is used, the first one will be used,
732 so you may wish to use `(?:...)` groups where you do not wish the
733 first such group treated as one to include. If no parenthetical group
734 exists or matches, the whole matching expression will be used.
735 An example might be ````"^```(?:js|javascript)([\\s\\S]*)```\s*$"````
736 to only match explicitly fenced JavaScript blocks. Defaults to only
737 using the `u` flag, so to add your own flags, encapsulate your
738 expression as a string, but like a literal, e.g., ````/```js.*```/gi````.
739 Note that specifying a global regular expression (i.e., with `g`) will
740 allow independent linting of matched blocks within a single `@example`.
741* `rejectExampleCodeRegex` - Regex blacklist which rejects
742 non-lintable examples (has priority over `exampleCodeRegex`). An example
743 might be ```"^`"``` to avoid linting fenced blocks which may indicate
744 a non-JavaScript language. See `exampleCodeRegex` on how to add flags
745 if the default `u` is not sufficient.
746
747If neither is in use, all examples will be matched. Note also that even if
748`captionRequired` is not set, any initial `<caption>` will be stripped out
749before doing the regex matching.
750
751<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-paddedindent"></a>
752##### <code>paddedIndent</code>
753
754This integer property allows one to add a fixed amount of whitespace at the
755beginning of the second or later lines of the example to be stripped so as
756to avoid linting issues with the decorative whitespace. For example, if set
757to a value of `4`, the initial whitespace below will not trigger `indent`
758rule errors as the extra 4 spaces on each subsequent line will be stripped
759out before evaluation.
760
761```js
762/**
763 * @example
764 * anArray.filter((a) => {
765 * return a.b;
766 * });
767 */
768```
769
770<a name="eslint-plugin-jsdoc-rules-check-examples-options-1-reportunuseddisabledirectives"></a>
771##### <code>reportUnusedDisableDirectives</code>
772
773If not set to `false`, `reportUnusedDisableDirectives` will report disabled
774directives which are not used (and thus not needed). Defaults to `true`.
775Corresponds to ESLint's [`--report-unused-disable-directives`](https://eslint.org/docs/user-guide/command-line-interface#--report-unused-disable-directives).
776
777Inline ESLint config within `@example` JavaScript is allowed, though the
778disabling of ESLint directives which are not needed by the resolved rules
779will be reported as with the ESLint `--report-unused-disable-directives`
780command.
781
782<a name="eslint-plugin-jsdoc-rules-check-examples-options-for-determining-eslint-rule-applicability-allowinlineconfig-nodefaultexamplerules-matchingfilename-configfile-eslintrcforexamples-and-baseconfig"></a>
783#### Options for Determining ESLint Rule Applicability (<code>allowInlineConfig</code>, <code>noDefaultExampleRules</code>, <code>matchingFileName</code>, <code>configFile</code>, <code>eslintrcForExamples</code>, and <code>baseConfig</code>)
784
785The following options determine which individual ESLint rules will be
786applied to the JavaScript found within the `@example` tags (as determined
787to be applicable by the above regex options). They are ordered by
788decreasing precedence:
789
790* `allowInlineConfig` - If not set to `false`, will allow
791 inline config within the `@example` to override other config. Defaults
792 to `true`.
793* `noDefaultExampleRules` - Setting to `true` will disable the
794 default rules which are expected to be troublesome for most documentation
795 use. See the section below for the specific default rules.
796* `matchingFileName` - Option for a file name (even non-existent) to trigger
797 specific rules defined in one's config; usable with ESLint `.eslintrc.*`
798 `overrides` -> `files` globs, to apply a desired subset of rules with
799 `@example` (besides allowing for rules specific to examples, this option
800 can be useful for enabling reuse of the same rules within `@example` as
801 with JavaScript Markdown lintable by
802 [other plugins](https://github.com/eslint/eslint-plugin-markdown), e.g.,
803 if one sets `matchingFileName` to `dummy.md` so that `@example` rules will
804 follow one's Markdown rules). Note that this option may come at somewhat
805 of a performance penalty as the file's existence is checked by eslint.
806* `configFile` - A config file. Corresponds to ESLint's [`-c`](https://eslint.org/docs/user-guide/command-line-interface#-c---config).
807* `eslintrcForExamples` - Defaults to `true` in adding rules
808 based on an `.eslintrc.*` file. Setting to `false` corresponds to
809 ESLint's [`--no-eslintrc`](https://eslint.org/docs/user-guide/command-line-interface#--no-eslintrc).
810* `baseConfig` - Set to an object of rules with the same schema
811 as `.eslintrc.*` for defaults.
812
813<a name="eslint-plugin-jsdoc-rules-check-examples-options-for-determining-eslint-rule-applicability-allowinlineconfig-nodefaultexamplerules-matchingfilename-configfile-eslintrcforexamples-and-baseconfig-rules-disabled-by-default-unless-nodefaultexamplerules-is-set-to-true"></a>
814##### Rules Disabled by Default Unless <code>noDefaultExampleRules</code> is Set to <code>true</code>
815
816* `eol-last` - Insisting that a newline "always" be at the end is less likely
817 to be desired in sample code as with the code file convention.
818* `no-console` - This rule is unlikely to have inadvertent temporary debugging
819 within examples.
820* `no-multiple-empty-lines` - This rule may be problematic for projects which
821 use an initial newline just to start an example. Also, projects may wish to
822 use extra lines within examples just for easier illustration
823 purposes.
824* `no-undef` - Many variables in examples will be `undefined`.
825* `no-unused-vars` - It is common to define variables for clarity without always
826 using them within examples.
827* `padded-blocks` - It can generally look nicer to pad a little even if one's
828 code follows more stringency as far as block padding.
829* `import/no-unresolved` - One wouldn't generally expect example paths to
830 resolve relative to the current JavaScript file as one would with real code.
831* `import/unambiguous` - Snippets in examples are likely too short to always
832 include full import/export info.
833* `node/no-missing-import` - See `import/no-unresolved`.
834* `node/no-missing-require` - See `import/no-unresolved`.
835
836|||
837|---|---|
838|Context|everywhere|
839|Tags|`example`|
840|Options| *See above* |
841
842The following patterns are considered problems:
843
844````js
845/**
846 * @example alert('hello')
847 */
848function quux () {
849
850}
851// Options: [{"baseConfig":{"rules":{"no-alert":2,"semi":["error","always"]}},"eslintrcForExamples":false}]
852// Message: @example error (no-alert): Unexpected alert.
853
854/**
855 * @example alert('hello')
856 */
857class quux {
858
859}
860// Options: [{"baseConfig":{"rules":{"no-alert":2,"semi":["error","always"]}},"eslintrcForExamples":false}]
861// Message: @example error (no-alert): Unexpected alert.
862
863/**
864 * @example ```js
865 alert('hello');
866 ```
867 */
868function quux () {
869
870}
871// Options: [{"baseConfig":{"rules":{"semi":["error","never"]}},"eslintrcForExamples":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
872// Message: @example error (semi): Extra semicolon.
873
874/**
875 * @example
876 *
877 * ```js alert('hello'); ```
878 */
879function quux () {
880
881}
882// Options: [{"baseConfig":{"rules":{"semi":["error","never"]}},"eslintrcForExamples":false,"exampleCodeRegex":"```js ([\\s\\S]*)```"}]
883// Message: @example error (semi): Extra semicolon.
884
885/**
886 * @example
887 * ```js alert('hello'); ```
888 */
889var quux = {
890
891};
892// Options: [{"baseConfig":{"rules":{"semi":["error","never"]}},"eslintrcForExamples":false,"exampleCodeRegex":"```js ([\\s\\S]*)```"}]
893// Message: @example error (semi): Extra semicolon.
894
895/**
896 * @example ```
897 * js alert('hello'); ```
898 */
899function quux () {
900
901}
902// Options: [{"baseConfig":{"rules":{"semi":["error","never"]}},"eslintrcForExamples":false,"exampleCodeRegex":"```\njs ([\\s\\S]*)```"}]
903// Message: @example error (semi): Extra semicolon.
904
905/**
906 * @example <b>Not JavaScript</b>
907 */
908function quux () {
909
910}
911/**
912 * @example quux2();
913 */
914function quux2 () {
915
916}
917// Options: [{"baseConfig":{"rules":{"semi":["error","never"]}},"eslintrcForExamples":false,"rejectExampleCodeRegex":"^\\s*<.*>\\s*$"}]
918// Message: @example error (semi): Extra semicolon.
919
920/**
921 * @example
922 * quux(); // does something useful
923 */
924function quux () {
925
926}
927// Options: [{"baseConfig":{"rules":{"no-undef":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":true}]
928// Message: @example error (no-undef): 'quux' is not defined.
929
930/**
931 * @example <caption>Valid usage</caption>
932 * quux(); // does something useful
933 *
934 * @example
935 * quux('random unwanted arg'); // results in an error
936 */
937function quux () {
938
939}
940// Options: [{"captionRequired":true,"eslintrcForExamples":false}]
941// Message: Caption is expected for examples.
942
943/**
944 * @example quux();
945 */
946function quux () {
947
948}
949// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
950// Message: @example error (indent): Expected indentation of 0 spaces but found 1.
951
952/**
953 * @example test() // eslint-disable-line semi
954 */
955function quux () {}
956// Options: [{"eslintrcForExamples":false,"noDefaultExampleRules":true,"reportUnusedDisableDirectives":true}]
957// Message: @example error: Unused eslint-disable directive (no problems were reported from 'semi').
958
959/**
960 * @example
961 test() // eslint-disable-line semi
962 */
963function quux () {}
964// Options: [{"allowInlineConfig":false,"baseConfig":{"rules":{"semi":["error","always"]}},"eslintrcForExamples":false,"noDefaultExampleRules":true}]
965// Message: @example error (semi): Missing semicolon.
966
967/**
968 * @example const i = 5;
969 * quux2()
970 */
971function quux2 () {
972
973}
974// Options: [{"matchingFileName":"test/jsdocUtils.js"}]
975// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
976
977/**
978 * @example const i = 5;
979 * quux2()
980 */
981function quux2 () {
982
983}
984// Options: [{"paddedIndent":2}]
985// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
986
987/**
988 * @example
989 * const i = 5;
990 * quux2()
991 */
992function quux2 () {
993
994}
995// Message: @example warning (id-length): Identifier name 'i' is too short (< 2).
996
997/**
998 * @example const i = 5;
999 * quux2()
1000 */
1001function quux2 () {
1002
1003}
1004// Options: [{"matchingFileName":"test/rules/data/dummy.js"}]
1005// Message: @example error (semi): Missing semicolon.
1006
1007/**
1008 * @example // begin
1009 alert('hello')
1010 // end
1011 */
1012function quux () {
1013
1014}
1015// Options: [{"baseConfig":{"rules":{"semi":["warn","always"]}},"eslintrcForExamples":false,"exampleCodeRegex":"// begin[\\s\\S]*// end","noDefaultExampleRules":true}]
1016// Message: @example warning (semi): Missing semicolon.
1017
1018/**
1019 *
1020 */
1021function f () {
1022
1023}
1024// Settings: {"jsdoc":{"allowInlineConfig":true,"baseConfig":{},"captionRequired":false,"configFile":"configFile.js","eslintrcForExamples":true,"exampleCodeRegex":".*?","matchingFileName":"test.md","noDefaultExampleRules":false,"rejectExampleCodeRegex":"\\W*","reportUnusedDisableDirectives":true}}
1025// Message: `settings.jsdoc.captionRequired` has been removed, use options in the rule `check-examples` instead.
1026
1027/**
1028 * @typedef {string} Foo
1029 * @example <caption></caption>
1030 * 'foo'
1031 */
1032// Options: [{"captionRequired":true,"eslintrcForExamples":false}]
1033// Message: Caption is expected for examples.
1034
1035/**
1036 * @example
1037 * const list: number[] = [1, 2, 3]
1038 * quux(list);
1039 */
1040function quux () {
1041
1042}
1043// Options: [{"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"eslintrcForExamples":false}]
1044// Message: @example error (semi): Missing semicolon.
1045
1046/**
1047 * @example <caption>Say `Hello!` to the user.</caption>
1048 * First, import the function:
1049 *
1050 * ```js
1051 * import popup from './popup'
1052 * const aConstInSameScope = 5;
1053 * ```
1054 *
1055 * Then use it like this:
1056 *
1057 * ```js
1058 * const aConstInSameScope = 7;
1059 * popup('Hello!')
1060 * ```
1061 *
1062 * Here is the result on macOS:
1063 *
1064 * ![Screenshot](path/to/screenshot.jpg)
1065 */
1066// Options: [{"baseConfig":{"parserOptions":{"ecmaVersion":2015,"sourceType":"module"},"rules":{"semi":["error","always"]}},"eslintrcForExamples":false,"exampleCodeRegex":"/^```(?:js|javascript)\\n([\\s\\S]*?)```$/gm"}]
1067// Message: @example error (semi): Missing semicolon.
1068
1069/**
1070 * @example // begin
1071 alert('hello')
1072 // end
1073 * And here is another example:
1074 // begin
1075 alert('there')
1076 // end
1077 */
1078function quux () {
1079
1080}
1081// Options: [{"baseConfig":{"rules":{"semi":["warn","always"]}},"eslintrcForExamples":false,"exampleCodeRegex":"/\\/\\/ begin[\\s\\S]*?// end/g","noDefaultExampleRules":true}]
1082// Message: @example warning (semi): Missing semicolon.
1083
1084/**
1085 * @example
1086 * quux();
1087 */
1088function quux () {
1089
1090}
1091// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
1092// Message: @example error (indent): Expected indentation of 0 spaces but found 2.
1093````
1094
1095The following patterns are not considered problems:
1096
1097````js
1098/**
1099 * @example ```js
1100 alert('hello');
1101 ```
1102 */
1103function quux () {
1104
1105}
1106// Options: [{"baseConfig":{"rules":{"semi":["error","always"]}},"eslintrcForExamples":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
1107
1108/**
1109 * @example ```js
1110 alert('hello');
1111 ```
1112 */
1113function quux () {
1114
1115}
1116// Options: [{"baseConfig":{"rules":{"semi":["error","always"]}},"eslintrcForExamples":false,"exampleCodeRegex":"/```js([\\s\\S]*)```/"}]
1117
1118/**
1119 * @example
1120 * // arbitrary example content
1121 */
1122function quux () {
1123
1124}
1125// Options: [{"eslintrcForExamples":false}]
1126
1127/**
1128 * @example
1129 * quux(); // does something useful
1130 */
1131function quux () {
1132
1133}
1134// Options: [{"baseConfig":{"rules":{"no-undef":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
1135
1136/**
1137 * @example quux();
1138 */
1139function quux () {
1140
1141}
1142// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
1143
1144/**
1145 * @example <caption>Valid usage</caption>
1146 * quux(); // does something useful
1147 *
1148 * @example <caption>Invalid usage</caption>
1149 * quux('random unwanted arg'); // results in an error
1150 */
1151function quux () {
1152
1153}
1154// Options: [{"captionRequired":true,"eslintrcForExamples":false}]
1155
1156/**
1157 * @example test() // eslint-disable-line semi
1158 */
1159function quux () {}
1160// Options: [{"eslintrcForExamples":false,"noDefaultExampleRules":true,"reportUnusedDisableDirectives":false}]
1161
1162/**
1163 * @example
1164 test() // eslint-disable-line semi
1165 */
1166function quux () {}
1167// Options: [{"allowInlineConfig":true,"baseConfig":{"rules":{"semi":["error","always"]}},"eslintrcForExamples":false,"noDefaultExampleRules":true}]
1168
1169/**
1170 * @example ```js
1171 alert('hello')
1172 ```
1173 */
1174var quux = {
1175
1176};
1177// Options: [{"baseConfig":{"rules":{"semi":["error","never"]}},"eslintrcForExamples":false,"exampleCodeRegex":"```js([\\s\\S]*)```"}]
1178
1179/**
1180 * @example
1181 * foo(function (err) {
1182 * throw err;
1183 * });
1184 */
1185function quux () {}
1186// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
1187
1188/**
1189 * @example
1190 * const list: number[] = [1, 2, 3];
1191 * quux(list);
1192 */
1193function quux () {
1194
1195}
1196// Options: [{"baseConfig":{"parser":"@typescript-eslint/parser","parserOptions":{"ecmaVersion":6},"rules":{"semi":["error","always"]}},"eslintrcForExamples":false}]
1197
1198/**
1199 * @example const ident = 5;
1200 * quux2();
1201 * bar();
1202 */
1203function quux2 () {
1204
1205}
1206// Options: [{"paddedIndent":2}]
1207
1208/**
1209 * @example
1210 * function quux() {
1211 * bar();
1212 * }
1213 */
1214function quux () {
1215
1216}
1217// Options: [{"baseConfig":{"rules":{"indent":["error"]}},"eslintrcForExamples":false,"noDefaultExampleRules":false}]
1218````
1219
1220
1221<a name="eslint-plugin-jsdoc-rules-check-indentation"></a>
1222### <code>check-indentation</code>
1223
1224Reports invalid padding inside JSDoc blocks.
1225
1226Ignores parts enclosed in Markdown "code block"'s. For example,
1227the following description is not reported:
1228
1229```js
1230/**
1231 * Some description:
1232 * ```html
1233 * <section>
1234 * <title>test</title>
1235 * </section>
1236 * ```
1237 */
1238```
1239
1240<a name="eslint-plugin-jsdoc-rules-check-indentation-options-2"></a>
1241#### Options
1242
1243This rule has an object option.
1244
1245<a name="eslint-plugin-jsdoc-rules-check-indentation-options-2-excludetags"></a>
1246##### <code>excludeTags</code>
1247
1248Array of tags (e.g., `['example', 'description']`) whose content will be
1249"hidden" from the `check-indentation` rule. Defaults to `['example']`.
1250
1251By default, the whole JSDoc block will be checked for invalid padding.
1252That would include `@example` blocks too, which can get in the way
1253of adding full, readable examples of code without ending up with multiple
1254linting issues.
1255
1256When disabled (by passing `excludeTags: []` option), the following code *will*
1257report a padding issue:
1258
1259```js
1260/**
1261 * @example
1262 * anArray.filter((a) => {
1263 * return a.b;
1264 * });
1265 */
1266```
1267
1268|||
1269|---|---|
1270|Context|everywhere|
1271|Tags|N/A|
1272|Options| `excludeTags` |
1273
1274The following patterns are considered problems:
1275
1276````js
1277/** foo */
1278function quux () {
1279
1280}
1281// Message: There must be no indentation.
1282
1283/**
1284 * foo
1285 *
1286 * @param bar
1287 * baz
1288 */
1289function quux () {
1290
1291}
1292// Message: There must be no indentation.
1293
1294/**
1295 * Foo
1296 * bar
1297 */
1298class Moo {}
1299// Message: There must be no indentation.
1300
1301/**
1302 * foo
1303 *
1304 * @example
1305 * anArray.filter((a) => {
1306 * return a.b;
1307 * });
1308 */
1309function quux () {
1310
1311}
1312// Options: [{"excludeTags":[]}]
1313// Message: There must be no indentation.
1314
1315/**
1316 * foo
1317 *
1318 * @example
1319 * aaaa
1320 * @returns
1321 * eeee
1322 */
1323function quux () {
1324
1325}
1326// Message: There must be no indentation.
1327
1328/**
1329 * foo
1330 * ```html
1331 * <section>
1332 * <title>test</title>
1333 * </section>
1334 * ```
1335 * @returns
1336 * eeee
1337 */
1338function quux () {
1339
1340}
1341// Message: There must be no indentation.
1342
1343/**
1344 * foo
1345 * ``` aaaa```
1346 * @returns
1347 * eeee
1348 */
1349function quux () {
1350
1351}
1352// Message: There must be no indentation.
1353
1354/**
1355* @example <caption>
1356* Here is a long
1357* indented summary of this
1358* example
1359* </caption>
1360* ```js
1361* function hi () {
1362* alert('Hello');
1363* }
1364* ```
1365*/
1366// Options: [{"excludeTags":[]}]
1367// Message: There must be no indentation.
1368
1369/**
1370* @example <caption>
1371* Here is a long
1372* summary of this
1373* example
1374* </caption>
1375* // Code is not wrapped into fenced code block
1376* function hi () {
1377* alert('Hello');
1378* }
1379*/
1380// Options: [{"excludeTags":[]}]
1381// Message: There must be no indentation.
1382````
1383
1384The following patterns are not considered problems:
1385
1386````js
1387/**
1388 * foo
1389 *
1390 * @param bar
1391 * baz
1392 */
1393function quux () {
1394
1395}
1396
1397/*** foo */
1398function quux () {
1399
1400}
1401
1402/**
1403 * foo
1404 *
1405 * @example
1406 * anArray.filter((a) => {
1407 * return a.b;
1408 * });
1409 */
1410function quux () {
1411
1412}
1413
1414/**
1415 * foo
1416 *
1417 * @example
1418 * anArray.filter((a) => {
1419 * return a.b;
1420 * });
1421 * @returns
1422 * eeee
1423 */
1424function quux () {
1425
1426}
1427// Options: [{"excludeTags":["example","returns"]}]
1428
1429/**
1430 * foo
1431 * ```html
1432 * <section>
1433 * <title>test</title>
1434 * </section>
1435 * ```
1436 * @returns eeee
1437 */
1438function quux () {
1439
1440}
1441
1442/**
1443 * foo
1444 * ``` aaaa```
1445 * @returns eeee
1446 */
1447function quux () {
1448
1449}
1450
1451/**
1452* @example <caption>
1453* Here is a long
1454* summary of this
1455* example
1456* </caption>
1457* ```js
1458* function hi () {
1459* alert('Hello');
1460* }
1461* ```
1462*/
1463// Options: [{"excludeTags":[]}]
1464````
1465
1466
1467<a name="eslint-plugin-jsdoc-rules-check-param-names"></a>
1468### <code>check-param-names</code>
1469
1470Ensures that parameter names in JSDoc match those in the function declaration.
1471
1472<a name="eslint-plugin-jsdoc-rules-check-param-names-options-3"></a>
1473#### Options
1474
1475<a name="eslint-plugin-jsdoc-rules-check-param-names-options-3-allowextratrailingparamdocs"></a>
1476##### <code>allowExtraTrailingParamDocs</code>
1477
1478If set to `true`, this option will allow extra `@param` definitions (e.g.,
1479representing future expected or virtual params) to be present without needing
1480their presence within the function signature. Other inconsistencies between
1481`@param`'s and present function parameters will still be reported.
1482
1483|||
1484|---|---|
1485|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
1486|Options|`allowExtraTrailingParamDocs`|
1487|Tags|`param`|
1488
1489The following patterns are considered problems:
1490
1491````js
1492/**
1493 * @param Foo
1494 */
1495function quux (foo = 'FOO') {
1496
1497}
1498// Message: Expected @param names to be "foo". Got "Foo".
1499
1500/**
1501 * @arg Foo
1502 */
1503function quux (foo = 'FOO') {
1504
1505}
1506// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
1507// Message: Expected @arg names to be "foo". Got "Foo".
1508
1509/**
1510 * @param Foo
1511 */
1512function quux (foo) {
1513
1514}
1515// Message: Expected @param names to be "foo". Got "Foo".
1516
1517/**
1518 * @param Foo.Bar
1519 */
1520function quux (foo) {
1521
1522}
1523// Message: @param path declaration ("Foo.Bar") appears before any real parameter.
1524
1525/**
1526 * @param foo
1527 * @param Foo.Bar
1528 */
1529function quux (foo) {
1530
1531}
1532// Message: @param path declaration ("Foo.Bar") root node name ("Foo") does not match previous real parameter name ("foo").
1533
1534/**
1535 * @param foo
1536 * @param foo.bar
1537 * @param bar
1538 */
1539function quux (bar, foo) {
1540
1541}
1542// Message: Expected @param names to be "bar, foo". Got "foo, bar".
1543
1544/**
1545 * @param foo
1546 * @param bar
1547 */
1548function quux (foo) {
1549
1550}
1551// Message: @param "bar" does not match an existing function parameter.
1552
1553/**
1554 * @param foo
1555 * @param foo
1556 */
1557function quux (foo) {
1558
1559}
1560// Message: Duplicate @param "foo"
1561
1562/**
1563 * @param foo
1564 * @param foo
1565 */
1566function quux (foo, bar) {
1567
1568}
1569// Message: Duplicate @param "foo"
1570
1571/**
1572 * @param foo
1573 * @param foo
1574 */
1575function quux (foo, foo) {
1576
1577}
1578// Message: Duplicate @param "foo"
1579
1580export class SomeClass {
1581 /**
1582 * @param prop
1583 */
1584 constructor(private property: string) {}
1585}
1586// Message: Expected @param names to be "property". Got "prop".
1587
1588/**
1589 * @param foo
1590 */
1591function quux (foo) {
1592
1593}
1594// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
1595// Message: Unexpected tag `@param`
1596
1597/**
1598 * @param {Error} error Exit code
1599 * @param {number} [code = 1] Exit code
1600 */
1601function quux (error, cde = 1) {
1602};
1603// Message: Expected @param names to be "error, cde". Got "error, code".
1604````
1605
1606The following patterns are not considered problems:
1607
1608````js
1609/**
1610 *
1611 */
1612function quux (foo) {
1613
1614}
1615
1616/**
1617 * @param foo
1618 */
1619function quux (foo) {
1620
1621}
1622
1623/**
1624 * @param foo
1625 * @param bar
1626 */
1627function quux (foo, bar) {
1628
1629}
1630
1631/**
1632 * @param foo
1633 * @param bar
1634 */
1635function quux (foo, bar, baz) {
1636
1637}
1638
1639/**
1640 * @param foo
1641 * @param foo.foo
1642 * @param bar
1643 */
1644function quux (foo, bar) {
1645
1646}
1647
1648/**
1649 * @param args
1650 */
1651function quux (...args) {
1652
1653}
1654
1655/**
1656 * @param foo
1657 */
1658function quux ({a, b}) {
1659
1660}
1661
1662/**
1663 * @param foo
1664 */
1665function quux ({a, b} = {}) {
1666
1667}
1668
1669/**
1670 * @param foo
1671 */
1672function quux ([a, b] = []) {
1673
1674}
1675
1676/**
1677 * Assign the project to a list of employees.
1678 * @param {object[]} employees - The employees who are responsible for the project.
1679 * @param {string} employees[].name - The name of an employee.
1680 * @param {string} employees[].department - The employee's department.
1681 */
1682function assign (employees) {
1683
1684};
1685
1686export class SomeClass {
1687 /**
1688 * @param property
1689 */
1690 constructor(private property: string) {}
1691}
1692
1693/**
1694 * @param {Error} error Exit code
1695 * @param {number} [code = 1] Exit code
1696 */
1697function quux (error, code = 1) {
1698};
1699
1700/**
1701 * @param foo
1702 * @param bar
1703 */
1704function quux (foo) {
1705
1706}
1707// Options: [{"allowExtraTrailingParamDocs":true}]
1708````
1709
1710
1711<a name="eslint-plugin-jsdoc-rules-check-param-names-deconstructing-function-parameter"></a>
1712#### Deconstructing Function Parameter
1713
1714`eslint-plugin-jsdoc` does not validate names of parameters in function deconstruction, e.g.
1715
1716```js
1717/**
1718 * @param foo
1719 */
1720function quux ({
1721 a,
1722 b
1723}) {
1724
1725}
1726```
1727
1728`{a, b}` is an [`ObjectPattern`](https://github.com/estree/estree/blob/master/es2015.md#objectpattern) AST type and does not have a name. Therefore, the associated parameter in JSDoc block can have any name.
1729
1730Likewise for the pattern `[a, b]` which is an [`ArrayPattern`](https://github.com/estree/estree/blob/master/es2015.md#arraypattern).
1731
1732<a name="eslint-plugin-jsdoc-rules-check-property-names"></a>
1733### <code>check-property-names</code>
1734
1735Ensures that property names in JSDoc are not duplicated on the same block
1736and that nested properties have defined roots.
1737
1738<a name="eslint-plugin-jsdoc-rules-check-property-names-options-4"></a>
1739#### Options
1740
1741|||
1742|---|---|
1743|Context|Everywhere|
1744|Tags|`property`|
1745
1746The following patterns are considered problems:
1747
1748````js
1749/**
1750 * @typedef (SomeType) SomeTypedef
1751 * @property Foo.Bar
1752 */
1753// Message: @property path declaration ("Foo.Bar") appears before any real property.
1754
1755/**
1756 * @typedef (SomeType) SomeTypedef
1757 * @property foo
1758 * @property Foo.Bar
1759 */
1760// Message: @property path declaration ("Foo.Bar") root node name ("Foo") does not match previous real property name ("foo").
1761
1762/**
1763 * @typedef (SomeType) SomeTypedef
1764 * @property foo
1765 * @property foo
1766 */
1767// Message: Duplicate @property "foo"
1768
1769/**
1770 * @typedef (SomeType) SomeTypedef
1771 * @prop foo
1772 * @prop foo
1773 */
1774// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
1775// Message: Duplicate @prop "foo"
1776
1777/**
1778 * @typedef (SomeType) SomeTypedef
1779 * @property foo
1780 */
1781// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
1782// Message: Unexpected tag `@property`
1783````
1784
1785The following patterns are not considered problems:
1786
1787````js
1788/**
1789 *
1790 */
1791
1792/**
1793 * @typedef (SomeType) SomeTypedef
1794 * @property foo
1795 */
1796
1797/**
1798 * @typedef (SomeType) SomeTypedef
1799 * @prop foo
1800 */
1801
1802/**
1803 * @typedef (SomeType) SomeTypedef
1804 * @property foo
1805 * @property bar
1806 */
1807
1808/**
1809 * @typedef (SomeType) SomeTypedef
1810 * @property foo
1811 * @property foo.foo
1812 * @property bar
1813 */
1814
1815/**
1816 * Assign the project to a list of employees.
1817 * @typedef (SomeType) SomeTypedef
1818 * @property {object[]} employees - The employees who are responsible for the project.
1819 * @property {string} employees[].name - The name of an employee.
1820 * @property {string} employees[].department - The employee's department.
1821 */
1822
1823/**
1824 * @typedef (SomeType) SomeTypedef
1825 * @property {Error} error Exit code
1826 * @property {number} [code = 1] Exit code
1827 */
1828
1829/**
1830 * @namespace (SomeType) SomeNamespace
1831 * @property {Error} error Exit code
1832 * @property {number} [code = 1] Exit code
1833 */
1834
1835/**
1836 * @class
1837 * @property {Error} error Exit code
1838 * @property {number} [code = 1] Exit code
1839 */
1840function quux (code = 1) {
1841 this.error = new Error('oops');
1842 this.code = code;
1843}
1844````
1845
1846
1847<a name="eslint-plugin-jsdoc-rules-check-syntax"></a>
1848### <code>check-syntax</code>
1849
1850Reports against Google Closure Compiler syntax.
1851
1852|||
1853|---|---|
1854|Context|everywhere|
1855|Tags|N/A|
1856
1857The following patterns are considered problems:
1858
1859````js
1860/**
1861 * @param {string=} foo
1862 */
1863function quux (foo) {
1864
1865}
1866// Message: Syntax should not be Google Closure Compiler style.
1867````
1868
1869The following patterns are not considered problems:
1870
1871````js
1872/**
1873 * @param {string} [foo]
1874 */
1875function quux (foo) {
1876
1877}
1878
1879/**
1880 *
1881 */
1882function quux (foo) {
1883
1884}
1885````
1886
1887
1888<a name="eslint-plugin-jsdoc-rules-check-tag-names"></a>
1889### <code>check-tag-names</code>
1890
1891Reports invalid block tag names.
1892
1893Valid [JSDoc 3 Block Tags](https://jsdoc.app/#block-tags) are:
1894
1895```
1896abstract
1897access
1898alias
1899async
1900augments
1901author
1902borrows
1903callback
1904class
1905classdesc
1906constant
1907constructs
1908copyright
1909default
1910deprecated
1911description
1912enum
1913event
1914example
1915exports
1916external
1917file
1918fires
1919function
1920generator
1921global
1922hideconstructor
1923ignore
1924implements
1925inheritdoc
1926inner
1927instance
1928interface
1929kind
1930lends
1931license
1932listens
1933member
1934memberof
1935memberof!
1936mixes
1937mixin
1938module
1939name
1940namespace
1941override
1942package
1943param
1944private
1945property
1946protected
1947public
1948readonly
1949requires
1950returns
1951see
1952since
1953static
1954summary
1955this
1956throws
1957todo
1958tutorial
1959type
1960typedef
1961variation
1962version
1963yields
1964```
1965
1966`modifies` is also supported (see [source](https://github.com/jsdoc/jsdoc/blob/master/packages/jsdoc/lib/jsdoc/tag/dictionary/definitions.js#L594)) but is undocumented.
1967
1968The following synonyms are also recognized:
1969
1970```
1971arg
1972argument
1973const
1974constructor
1975defaultvalue
1976desc
1977emits
1978exception
1979extends
1980fileoverview
1981func
1982host
1983method
1984overview
1985prop
1986return
1987var
1988virtual
1989yield
1990```
1991
1992For [TypeScript](https://www.typescriptlang.org/docs/handbook/type-checking-javascript-files.html#supported-jsdoc)
1993(or Closure), when `settings.jsdoc.mode` is set to `typescript` or `closure`,
1994one may also use the following:
1995
1996```
1997template
1998```
1999
2000And for [Closure](https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler),
2001when `settings.jsdoc.mode` is set to `closure`, one may use the following (in
2002addition to the jsdoc and TypeScript tags):
2003
2004```
2005define (synonym of `const` per jsdoc source)
2006dict
2007export
2008externs
2009final
2010implicitCast (casing distinct from that recognized by jsdoc internally)
2011inheritDoc (casing distinct from that recognized by jsdoc internally)
2012noalias
2013nocollapse
2014nocompile
2015noinline
2016nosideeffects
2017polymer
2018polymerBehavior
2019preserve
2020record (synonym of `interface` per jsdoc source)
2021struct
2022suppress
2023unrestricted
2024```
2025
2026...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):
2027
2028```
2029closurePrimitive
2030customElement
2031expose
2032hidden
2033idGenerator
2034meaning
2035mixinClass
2036mixinFunction
2037ngInject
2038owner
2039typeSummary
2040wizaction
2041```
2042
2043Note that the tags indicated as replacements in `settings.jsdoc.tagNamePreference` will automatically be considered as valid.
2044
2045<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-5"></a>
2046#### Options
2047
2048<a name="eslint-plugin-jsdoc-rules-check-tag-names-options-5-definedtags"></a>
2049##### <code>definedTags</code>
2050
2051Use an array of `definedTags` strings to configure additional, allowed tags.
2052The format is as follows:
2053
2054```json
2055{
2056 "definedTags": ["note", "record"]
2057}
2058```
2059
2060|||
2061|---|---|
2062|Context|everywhere|
2063|Tags|N/A|
2064|Options|`definedTags`|
2065|Settings|`tagNamePreference`, `mode`|
2066
2067The following patterns are considered problems:
2068
2069````js
2070/** @typoo {string} */
2071let a;
2072// Message: Invalid JSDoc tag name "typoo".
2073
2074/**
2075 * @Param
2076 */
2077function quux () {
2078
2079}
2080// Message: Invalid JSDoc tag name "Param".
2081
2082/**
2083 * @foo
2084 */
2085function quux () {
2086
2087}
2088// Message: Invalid JSDoc tag name "foo".
2089
2090/**
2091 * @arg foo
2092 */
2093function quux (foo) {
2094
2095}
2096// Message: Invalid JSDoc tag (preference). Replace "arg" JSDoc tag with "param".
2097
2098/**
2099 * @param foo
2100 */
2101function quux (foo) {
2102
2103}
2104// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
2105// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "arg".
2106
2107/**
2108 * @arg foo
2109 */
2110function quux (foo) {
2111
2112}
2113// Settings: {"jsdoc":{"tagNamePreference":{"arg":"somethingDifferent"}}}
2114// Message: Invalid JSDoc tag (preference). Replace "arg" JSDoc tag with "somethingDifferent".
2115
2116/**
2117 * @param foo
2118 */
2119function quux (foo) {
2120
2121}
2122// Settings: {"jsdoc":{"tagNamePreference":{"param":"parameter"}}}
2123// Message: Invalid JSDoc tag (preference). Replace "param" JSDoc tag with "parameter".
2124
2125/**
2126 * @bar foo
2127 */
2128function quux (foo) {
2129
2130}
2131// Message: Invalid JSDoc tag name "bar".
2132
2133/**
2134 * @baz @bar foo
2135 */
2136function quux (foo) {
2137
2138}
2139// Options: [{"definedTags":["bar"]}]
2140// Message: Invalid JSDoc tag name "baz".
2141
2142/**
2143 * @bar
2144 * @baz
2145 */
2146function quux (foo) {
2147
2148}
2149// Options: [{"definedTags":["bar"]}]
2150// Message: Invalid JSDoc tag name "baz".
2151
2152/**
2153 * @todo
2154 */
2155function quux () {
2156
2157}
2158// Settings: {"jsdoc":{"tagNamePreference":{"todo":false}}}
2159// Message: Blacklisted tag found (`@todo`)
2160
2161/**
2162 * @todo
2163 */
2164function quux () {
2165
2166}
2167// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please resolve to-dos or add to the tracker"}}}}
2168// Message: Please resolve to-dos or add to the tracker
2169
2170/**
2171 * @todo
2172 */
2173function quux () {
2174
2175}
2176// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
2177// Message: Please use x-todo instead of todo
2178
2179/**
2180 * @todo
2181 */
2182function quux () {
2183
2184}
2185// Settings: {"jsdoc":{"tagNamePreference":{"todo":{"message":"Please use x-todo instead of todo","replacement":"x-todo"}}}}
2186// Message: Please use x-todo instead of todo
2187
2188/**
2189 * @todo
2190 */
2191function quux () {
2192
2193}
2194// Settings: {"jsdoc":{"tagNamePreference":{"todo":55}}}
2195// Message: Invalid `settings.jsdoc.tagNamePreference`. Values must be falsy, a string, or an object.
2196
2197/**
2198 * @property {object} a
2199 * @prop {boolean} b
2200 */
2201function quux () {
2202
2203}
2204// Message: Invalid JSDoc tag (preference). Replace "prop" JSDoc tag with "property".
2205
2206/**
2207 * @abc foo
2208 * @abcd bar
2209 */
2210function quux () {
2211
2212}
2213// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
2214// Options: [{"definedTags":["abcd"]}]
2215// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
2216
2217/**
2218 * @abc
2219 * @abcd
2220 */
2221function quux () {
2222
2223}
2224// Settings: {"jsdoc":{"tagNamePreference":{"abc":"abcd"}}}
2225// Message: Invalid JSDoc tag (preference). Replace "abc" JSDoc tag with "abcd".
2226
2227/**
2228 * @modifies
2229 * @abstract
2230 * @access
2231 * @alias
2232 * @async
2233 * @augments
2234 * @author
2235 * @borrows
2236 * @callback
2237 * @class
2238 * @classdesc
2239 * @constant
2240 * @constructs
2241 * @copyright
2242 * @default
2243 * @deprecated
2244 * @description
2245 * @enum
2246 * @event
2247 * @example
2248 * @exports
2249 * @external
2250 * @file
2251 * @fires
2252 * @function
2253 * @generator
2254 * @global
2255 * @hideconstructor
2256 * @ignore
2257 * @implements
2258 * @inheritdoc
2259 * @inner
2260 * @instance
2261 * @interface
2262 * @kind
2263 * @lends
2264 * @license
2265 * @listens
2266 * @member
2267 * @memberof
2268 * @memberof!
2269 * @mixes
2270 * @mixin
2271 * @module
2272 * @name
2273 * @namespace
2274 * @override
2275 * @package
2276 * @param
2277 * @private
2278 * @property
2279 * @protected
2280 * @public
2281 * @readonly
2282 * @requires
2283 * @returns
2284 * @see
2285 * @since
2286 * @static
2287 * @summary
2288 * @this
2289 * @throws
2290 * @todo
2291 * @tutorial
2292 * @type
2293 * @typedef
2294 * @variation
2295 * @version
2296 * @yields
2297 */
2298function quux (foo) {}
2299// Settings: {"jsdoc":{"mode":"badMode"}}
2300// Message: Unrecognized value `badMode` for `settings.jsdoc.mode`.
2301
2302/**
2303 * @modifies
2304 * @abstract
2305 * @access
2306 * @alias
2307 * @async
2308 * @augments
2309 * @author
2310 * @borrows
2311 * @callback
2312 * @class
2313 * @classdesc
2314 * @constant
2315 * @constructs
2316 * @copyright
2317 * @default
2318 * @deprecated
2319 * @description
2320 * @enum
2321 * @event
2322 * @example
2323 * @exports
2324 * @external
2325 * @file
2326 * @fires
2327 * @function
2328 * @generator
2329 * @global
2330 * @hideconstructor
2331 * @ignore
2332 * @implements
2333 * @inheritdoc
2334 * @inner
2335 * @instance
2336 * @interface
2337 * @kind
2338 * @lends
2339 * @license
2340 * @listens
2341 * @member
2342 * @memberof
2343 * @memberof!
2344 * @mixes
2345 * @mixin
2346 * @module
2347 * @name
2348 * @namespace
2349 * @override
2350 * @package
2351 * @param
2352 * @private
2353 * @property
2354 * @protected
2355 * @public
2356 * @readonly
2357 * @requires
2358 * @returns
2359 * @see
2360 * @since
2361 * @static
2362 * @summary
2363 * @this
2364 * @throws
2365 * @todo
2366 * @tutorial
2367 * @type
2368 * @typedef
2369 * @variation
2370 * @version
2371 * @yields
2372 * @template
2373 */
2374function quux (foo) {}
2375// Message: Invalid JSDoc tag name "template".
2376
2377/**
2378 * @externs
2379 */
2380function quux (foo) {}
2381// Message: Invalid JSDoc tag name "externs".
2382````
2383
2384The following patterns are not considered problems:
2385
2386````js
2387/**
2388 * @param foo
2389 */
2390function quux (foo) {
2391
2392}
2393
2394/**
2395 * @memberof! foo
2396 */
2397function quux (foo) {
2398
2399}
2400
2401/**
2402 * @arg foo
2403 */
2404function quux (foo) {
2405
2406}
2407// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
2408
2409/**
2410 * @bar foo
2411 */
2412function quux (foo) {
2413
2414}
2415// Options: [{"definedTags":["bar"]}]
2416
2417/**
2418 * @baz @bar foo
2419 */
2420function quux (foo) {
2421
2422}
2423// Options: [{"definedTags":["baz","bar"]}]
2424
2425/**
2426 * @baz @bar foo
2427 */
2428function quux (foo) {
2429
2430}
2431// Settings: {"jsdoc":{"tagNamePreference":{"param":"baz","returns":{"message":"Prefer `bar`","replacement":"bar"},"todo":false}}}
2432
2433/**
2434 * @modifies
2435 * @abstract
2436 * @access
2437 * @alias
2438 * @async
2439 * @augments
2440 * @author
2441 * @borrows
2442 * @callback
2443 * @class
2444 * @classdesc
2445 * @constant
2446 * @constructs
2447 * @copyright
2448 * @default
2449 * @deprecated
2450 * @description
2451 * @enum
2452 * @event
2453 * @example
2454 * @exports
2455 * @external
2456 * @file
2457 * @fires
2458 * @function
2459 * @generator
2460 * @global
2461 * @hideconstructor
2462 * @ignore
2463 * @implements
2464 * @inheritdoc
2465 * @inner
2466 * @instance
2467 * @interface
2468 * @kind
2469 * @lends
2470 * @license
2471 * @listens
2472 * @member
2473 * @memberof
2474 * @memberof!
2475 * @mixes
2476 * @mixin
2477 * @module
2478 * @name
2479 * @namespace
2480 * @override
2481 * @package
2482 * @param
2483 * @private
2484 * @property
2485 * @protected
2486 * @public
2487 * @readonly
2488 * @requires
2489 * @returns
2490 * @see
2491 * @since
2492 * @static
2493 * @summary
2494 * @this
2495 * @throws
2496 * @todo
2497 * @tutorial
2498 * @type
2499 * @typedef
2500 * @variation
2501 * @version
2502 * @yields
2503 */
2504function quux (foo) {}
2505
2506/**
2507 * @modifies
2508 * @abstract
2509 * @access
2510 * @alias
2511 * @async
2512 * @augments
2513 * @author
2514 * @borrows
2515 * @callback
2516 * @class
2517 * @classdesc
2518 * @constant
2519 * @constructs
2520 * @copyright
2521 * @default
2522 * @deprecated
2523 * @description
2524 * @enum
2525 * @event
2526 * @example
2527 * @exports
2528 * @external
2529 * @file
2530 * @fires
2531 * @function
2532 * @generator
2533 * @global
2534 * @hideconstructor
2535 * @ignore
2536 * @implements
2537 * @inheritdoc
2538 * @inner
2539 * @instance
2540 * @interface
2541 * @kind
2542 * @lends
2543 * @license
2544 * @listens
2545 * @member
2546 * @memberof
2547 * @memberof!
2548 * @mixes
2549 * @mixin
2550 * @module
2551 * @name
2552 * @namespace
2553 * @override
2554 * @package
2555 * @param
2556 * @private
2557 * @property
2558 * @protected
2559 * @public
2560 * @readonly
2561 * @requires
2562 * @returns
2563 * @see
2564 * @since
2565 * @static
2566 * @summary
2567 * @this
2568 * @throws
2569 * @todo
2570 * @tutorial
2571 * @type
2572 * @typedef
2573 * @variation
2574 * @version
2575 * @yields
2576 * @template
2577 */
2578function quux (foo) {}
2579// Settings: {"jsdoc":{"mode":"typescript"}}
2580
2581/**
2582 * @externs
2583 */
2584function quux (foo) {}
2585// Settings: {"jsdoc":{"mode":"closure"}}
2586
2587/**
2588 *
2589 */
2590function quux (foo) {
2591
2592}
2593
2594/**
2595 * @todo
2596 */
2597function quux () {
2598
2599}
2600
2601/**
2602 * @extends Foo
2603 */
2604function quux () {
2605
2606}
2607// Settings: {"jsdoc":{"tagNamePreference":{"augments":{"message":"@extends is to be used over @augments.","replacement":"extends"}}}}
2608
2609/**
2610 * Registers the `target` class as a transient dependency; each time the dependency is resolved a new instance will be created.
2611 *
2612 * @param target - The class / constructor function to register as transient.
2613 *
2614 * @example ```ts
2615@transient()
2616class Foo { }
2617```
2618 * @param Time for a new tag
2619 */
2620export function transient<T>(target?: T): T {
2621 // ...
2622}
2623````
2624
2625
2626<a name="eslint-plugin-jsdoc-rules-check-types"></a>
2627### <code>check-types</code>
2628
2629Reports invalid types.
2630
2631By default, ensures that the casing of native types is the same as in this list:
2632
2633```
2634undefined
2635null
2636boolean
2637number
2638bigint
2639string
2640symbol
2641object
2642Array
2643Function
2644Date
2645RegExp
2646```
2647
2648<a name="eslint-plugin-jsdoc-rules-check-types-options-6"></a>
2649#### Options
2650
2651`check-types` allows one option:
2652
2653- An option object:
2654 - with the key `noDefaults` to insist that only the supplied option type
2655 map is to be used, and that the default preferences (such as "string"
2656 over "String") will not be enforced. The option's default is `false`.
2657 - with the key `exemptTagContexts` which will avoid reporting when a
2658 bad type is found on a specified tag. Set to an array of objects with
2659 a key `tag` set to the tag to exempt, and a `types` key which can
2660 either be `true` to indicate that any types on that tag will be allowed,
2661 or to an array of strings which will only allow specific bad types.
2662 If an array of strings is given, these must match the type exactly,
2663 e.g., if you only allow `"object"`, it will not allow
2664 `"object<string, string>"`. Note that this is different from the
2665 behavior of `settings.jsdoc.preferredTypes`. This option is useful
2666 for normally restricting generic types like `object` with
2667 `preferredTypes`, but allowing `typedef` to indicate that its base
2668 type is `object`.
2669 - with the key `unifyParentAndChildTypeChecks` which will treat
2670 `settings.jsdoc.preferredTypes` keys such as `SomeType` as matching
2671 not only child types such as an unadorned `SomeType` but also
2672 `SomeType<aChildType>`, `SomeType.<aChildType>`, or if `SomeType` is
2673 `Array` (or `[]`), it will match `aChildType[]`. If this is `false` or
2674 unset, the former format will only apply to types which are not parent
2675 types/unions whereas the latter formats will only apply for parent
2676 types/unions. The special types `[]`, `.<>` (or `.`), and `<>`
2677 act only as parent types (and will not match a bare child type such as
2678 `Array` even when unified, though, as mentioned, `Array` will match
2679 say `string[]` or `Array.<string>` when unified). The special type
2680 `*` is only a child type. Note that there is no detection of parent
2681 and child type together, e.g., you cannot specify preferences for
2682 `string[]` specifically as distinct from say `number[]`, but you can
2683 target both with `[]` or the child types `number` or `string`.
2684
2685See also the documentation on `settings.jsdoc.preferredTypes` which impacts
2686the behavior of `check-types`.
2687
2688<a name="eslint-plugin-jsdoc-rules-check-types-why-not-capital-case-everything"></a>
2689#### Why not capital case everything?
2690
2691Why are `boolean`, `number` and `string` exempt from starting with a capital letter? Let's take `string` as an example. In Javascript, everything is an object. The string Object has prototypes for string functions such as `.toUpperCase()`.
2692
2693Fortunately we don't have to write `new String()` everywhere in our code. Javascript will automatically wrap string primitives into string Objects when we're applying a string function to a string primitive. This way the memory footprint is a tiny little bit smaller, and the [GC](https://en.wikipedia.org/wiki/Garbage_collection_(computer_science)) has less work to do.
2694
2695So in a sense, there two types of strings in Javascript; `{string}` literals, also called primitives and `{String}` Objects. We use the primitives because it's easier to write and uses less memory. `{String}` and `{string}` are technically both valid, but they are not the same.
2696
2697```js
2698new String('lard') // String {0: "l", 1: "a", 2: "r", 3: "d", length: 4}
2699'lard' // "lard"
2700new String('lard') === 'lard' // false
2701```
2702
2703To make things more confusing, there are also object literals and object Objects. But object literals are still static Objects and object Objects are instantiated Objects. So an object primitive is still an object Object.
2704
2705However, `Object.create(null)` objects are not `instanceof Object`, however, so
2706in the case of this Object we lower-case to indicate possible support for
2707these objects.
2708
2709Basically, for primitives, we want to define the type as a primitive, because that's what we use in 99.9% of cases. For everything else, we use the type rather than the primitive. Otherwise it would all just be `{object}`.
2710
2711In short: It's not about consistency, rather about the 99.9% use case. (And some
2712functions might not even support the objects if they are checking for identity.)
2713
2714type name | `typeof` | check-types | testcase
2715--|--|--|--
2716**Array** | object | **Array** | `([]) instanceof Array` -> `true`
2717**Function** | function | **function** | `(function f () {}) instanceof Function` -> `true`
2718**Date** | object | **Date** | `(new Date()) instanceof Date` -> `true`
2719**RegExp** | object | **RegExp** | `(new RegExp(/.+/)) instanceof RegExp` -> `true`
2720Object | **object** | **object** | `({}) instanceof Object` -> `true` but `Object.create(null) instanceof Object` -> `false`
2721Boolean | **boolean** | **boolean** | `(true) instanceof Boolean` -> **`false`**
2722Number | **number** | **number** | `(41) instanceof Number` -> **`false`**
2723String | **string** | **string** | `("test") instanceof String` -> **`false`**
2724
2725|||
2726|---|---|
2727|Context|everywhere|
2728|Tags|`augments`, `class`, `constant`, `enum`, `implements`, `member`, `module`, `namespace`, `param`, `property`, `returns`, `throws`, `type`, `typedef`, `yields`|
2729|Aliases|`constructor`, `const`, `extends`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
2730|Closure-only|`package`, `private`, `protected`, `public`, `static`|
2731|Options|`noDefaults`, `exemptTagContexts`, `unifyParentAndChildTypeChecks`|
2732|Settings|`preferredTypes`, `mode`|
2733
2734The following patterns are considered problems:
2735
2736````js
2737/**
2738 * @param {abc} foo
2739 */
2740function quux (foo) {
2741
2742}
2743// Settings: {"jsdoc":{"preferredTypes":{"abc":100}}}
2744// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
2745
2746/**
2747 * @param {Number} foo
2748 */
2749function quux (foo) {
2750
2751}
2752// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
2753
2754/**
2755 * @arg {Number} foo
2756 */
2757function quux (foo) {
2758
2759}
2760// Message: Invalid JSDoc @arg "foo" type "Number"; prefer: "number".
2761
2762/**
2763 * @returns {Number} foo
2764 * @throws {Number} foo
2765 */
2766function quux () {
2767
2768}
2769// Message: Invalid JSDoc @returns type "Number"; prefer: "number".
2770
2771/**
2772 * @param {(Number|string|Boolean)=} foo
2773 */
2774function quux (foo, bar, baz) {
2775
2776}
2777// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
2778
2779/**
2780 * @param {Array.<Number|String>} foo
2781 */
2782function quux (foo, bar, baz) {
2783
2784}
2785// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
2786
2787/**
2788 * @param {(Number|String)[]} foo
2789 */
2790function quux (foo, bar, baz) {
2791
2792}
2793// Message: Invalid JSDoc @param "foo" type "Number"; prefer: "number".
2794
2795/**
2796 * @param {abc} foo
2797 */
2798function qux(foo) {
2799}
2800// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
2801// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
2802
2803/**
2804 * @param {abc} foo
2805 */
2806function qux(foo) {
2807}
2808// Settings: {"jsdoc":{"preferredTypes":{"abc":{"replacement":"Abc"},"string":"Str"}}}
2809// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
2810
2811/**
2812 * @param {abc} foo
2813 */
2814function qux(foo) {
2815}
2816// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"; prefer: \"Abc\".","replacement":"Abc"},"string":"Str"}}}
2817// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
2818
2819/**
2820 * @param {abc} foo
2821 * @param {cde} bar
2822 * @param {object} baz
2823 */
2824function qux(foo, bar, baz) {
2825}
2826// 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"}}}
2827// Message: Messed up JSDoc @param "foo" type "abc"; prefer: "Abc".
2828
2829/**
2830 * @param {abc} foo
2831 */
2832function qux(foo) {
2833}
2834// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\".","replacement":false},"string":"Str"}}}
2835// Message: Messed up JSDoc @param "foo" type "abc".
2836
2837/**
2838 * @param {abc} foo
2839 */
2840function qux(foo) {
2841}
2842// Settings: {"jsdoc":{"preferredTypes":{"abc":{"message":"Messed up JSDoc @{{tagName}}{{tagValue}} type \"abc\"."},"string":"Str"}}}
2843// Message: Messed up JSDoc @param "foo" type "abc".
2844
2845/**
2846 * @param {abc} foo
2847 * @param {Number} bar
2848 */
2849function qux(foo, bar) {
2850}
2851// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
2852// Options: [{"noDefaults":true}]
2853// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
2854
2855/**
2856 * @param {abc} foo
2857 * @param {Number} bar
2858 */
2859function qux(foo, bar) {
2860}
2861// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
2862// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
2863
2864/**
2865 * @param {abc} foo
2866 */
2867function qux(foo) {
2868}
2869// Settings: {"jsdoc":{"preferredTypes":{"abc":false,"string":"Str"}}}
2870// Message: Invalid JSDoc @param "foo" type "abc".
2871
2872/**
2873 * @param {abc} foo
2874 */
2875function qux(foo) {
2876}
2877// Settings: {"jsdoc":{"preferredTypes":{"abc":false}}}
2878// Message: Invalid JSDoc @param "foo" type "abc".
2879
2880/**
2881 * @param {*} baz
2882 */
2883function qux(baz) {
2884}
2885// Settings: {"jsdoc":{"preferredTypes":{"*":false,"abc":"Abc","string":"Str"}}}
2886// Message: Invalid JSDoc @param "baz" type "*".
2887
2888/**
2889 * @param {*} baz
2890 */
2891function qux(baz) {
2892}
2893// Settings: {"jsdoc":{"preferredTypes":{"*":"aaa","abc":"Abc","string":"Str"}}}
2894// Message: Invalid JSDoc @param "baz" type "*"; prefer: "aaa".
2895
2896/**
2897 * @param {abc} foo
2898 * @param {Number} bar
2899 */
2900function qux(foo, bar) {
2901}
2902// Settings: {"jsdoc":{"preferredTypes":{"abc":"Abc","string":"Str"}}}
2903// Message: Invalid JSDoc @param "foo" type "abc"; prefer: "Abc".
2904
2905/**
2906 * @param {Array} foo
2907 */
2908function quux (foo) {
2909
2910}
2911// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
2912// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
2913
2914/**
2915 * @param {Array} foo
2916 */
2917function quux (foo) {
2918
2919}
2920// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray","Array.<>":"GenericArray"}}}
2921// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
2922
2923/**
2924 * @param {Array.<string>} foo
2925 */
2926function quux (foo) {
2927
2928}
2929// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"GenericArray"}}}
2930// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
2931
2932/**
2933 * @param {Array<string>} foo
2934 */
2935function quux (foo) {
2936
2937}
2938// Settings: {"jsdoc":{"preferredTypes":{"Array<>":"GenericArray"}}}
2939// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "GenericArray".
2940
2941/**
2942 * @param {string[]} foo
2943 */
2944function quux (foo) {
2945
2946}
2947// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
2948// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "SpecialTypeArray".
2949
2950/**
2951 * @param {string[]} foo
2952 */
2953function quux (foo) {
2954
2955}
2956// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
2957// Options: [{"unifyParentAndChildTypeChecks":true}]
2958// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "SpecialTypeArray".
2959
2960/**
2961 * @param {string[]} foo
2962 */
2963function quux (foo) {
2964
2965}
2966// Settings: {"jsdoc":{"preferredTypes":{"Array":"SpecialTypeArray"}}}
2967// Options: [{"unifyParentAndChildTypeChecks":true}]
2968// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "SpecialTypeArray".
2969
2970/**
2971 * @param {object} foo
2972 */
2973function quux (foo) {
2974
2975}
2976// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
2977// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
2978
2979/**
2980 * @param {object} foo
2981 */
2982function quux (foo) {
2983
2984}
2985// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject","object.<>":"GenericObject"}}}
2986// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
2987
2988/**
2989 * @param {object} foo
2990 */
2991function quux (foo) {
2992
2993}
2994// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject","object<>":"GenericObject"}}}
2995// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
2996
2997/**
2998 * @param {object.<string>} foo
2999 */
3000function quux (foo) {
3001
3002}
3003// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
3004// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3005
3006/**
3007 * @param {object<string>} foo
3008 */
3009function quux (foo) {
3010
3011}
3012// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
3013// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3014
3015/**
3016 * @param {object.<string, number>} foo
3017 */
3018function quux (foo) {
3019
3020}
3021// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
3022// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3023
3024/**
3025 * @param {object<string, number>} foo
3026 */
3027function quux (foo) {
3028
3029}
3030// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
3031// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3032
3033/**
3034 * @param {object.<string>} foo
3035 */
3036function quux (foo) {
3037
3038}
3039// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3040// Options: [{"unifyParentAndChildTypeChecks":true}]
3041// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3042
3043/**
3044 * @param {object<string>} foo
3045 */
3046function quux (foo) {
3047
3048}
3049// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3050// Options: [{"unifyParentAndChildTypeChecks":true}]
3051// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3052
3053/**
3054 * @param {object} foo
3055 */
3056function quux (foo) {
3057
3058}
3059// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3060// Options: [{"unifyParentAndChildTypeChecks":true}]
3061// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3062
3063/**
3064 * @param {object} foo
3065 */
3066function quux (foo) {
3067
3068}
3069// Settings: {"jsdoc":{"preferredTypes":{"object":false}}}
3070// Options: [{"unifyParentAndChildTypeChecks":true}]
3071// Message: Invalid JSDoc @param "foo" type "object".
3072
3073/**
3074 * @param {object} foo
3075 */
3076function quux (foo) {
3077
3078}
3079// Settings: {"jsdoc":{"preferredTypes":{"object":false}}}
3080// Message: Invalid JSDoc @param "foo" type "object".
3081
3082/**
3083 * @param {object.<string, number>} foo
3084 */
3085function quux (foo) {
3086
3087}
3088// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3089// Options: [{"unifyParentAndChildTypeChecks":true}]
3090// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3091
3092/**
3093 * @param {object<string, number>} foo
3094 */
3095function quux (foo) {
3096
3097}
3098// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3099// Options: [{"unifyParentAndChildTypeChecks":true}]
3100// Message: Invalid JSDoc @param "foo" type "object"; prefer: "GenericObject".
3101
3102/**
3103 *
3104 * @param {string[][]} foo
3105 */
3106function quux (foo) {
3107
3108}
3109// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array."}}}
3110// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array.".
3111
3112/**
3113 *
3114 * @param {string[][]} foo
3115 */
3116function quux (foo) {
3117
3118}
3119// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array.<>"}}}
3120// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array.<>".
3121
3122/**
3123 *
3124 * @param {string[][]} foo
3125 */
3126function quux (foo) {
3127
3128}
3129// Settings: {"jsdoc":{"preferredTypes":{"[]":"Array<>"}}}
3130// Message: Invalid JSDoc @param "foo" type "[]"; prefer: "Array<>".
3131
3132/**
3133 *
3134 * @param {object.<string, object.<string, string>>} foo
3135 */
3136function quux (foo) {
3137
3138}
3139// Settings: {"jsdoc":{"preferredTypes":{"object.":"Object"}}}
3140// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object".
3141
3142/**
3143 *
3144 * @param {object.<string, object.<string, string>>} foo
3145 */
3146function quux (foo) {
3147
3148}
3149// Settings: {"jsdoc":{"preferredTypes":{"object.":"Object<>"}}}
3150// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object<>".
3151
3152/**
3153 *
3154 * @param {object<string, object<string, string>>} foo
3155 */
3156function quux (foo) {
3157
3158}
3159// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object."}}}
3160// Message: Invalid JSDoc @param "foo" type "object"; prefer: "Object.".
3161
3162/**
3163 *
3164 * @param {Array.<Array.<string>>} foo
3165 */
3166function quux (foo) {
3167
3168}
3169// Settings: {"jsdoc":{"preferredTypes":{"Array.":"[]"}}}
3170// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
3171
3172/**
3173 *
3174 * @param {Array.<Array.<string>>} foo
3175 */
3176function quux (foo) {
3177
3178}
3179// Settings: {"jsdoc":{"preferredTypes":{"Array.":"Array<>"}}}
3180// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array<>".
3181
3182/**
3183 *
3184 * @param {Array.<Array.<string>>} foo
3185 */
3186function quux (foo) {
3187
3188}
3189// Settings: {"jsdoc":{"preferredTypes":{"Array.":"<>"}}}
3190// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "<>".
3191
3192/**
3193 *
3194 * @param {Array.<MyArray.<string>>} foo
3195 */
3196function quux (foo) {
3197
3198}
3199// Settings: {"jsdoc":{"preferredTypes":{"Array.":"<>"}}}
3200// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "<>".
3201
3202/**
3203 *
3204 * @param {Array.<MyArray.<string>>} foo
3205 */
3206function quux (foo) {
3207
3208}
3209// Settings: {"jsdoc":{"preferredTypes":{"MyArray.":"<>"}}}
3210// Message: Invalid JSDoc @param "foo" type "MyArray"; prefer: "<>".
3211
3212/**
3213 *
3214 * @param {Array<Array<string>>} foo
3215 */
3216function quux (foo) {
3217
3218}
3219// Settings: {"jsdoc":{"preferredTypes":{"<>":"Array."}}}
3220// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array.".
3221
3222/**
3223 *
3224 * @param {Array<Array<string>>} foo
3225 */
3226function quux (foo) {
3227
3228}
3229// Settings: {"jsdoc":{"preferredTypes":{"Array":"Array."}}}
3230// Options: [{"unifyParentAndChildTypeChecks":true}]
3231// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "Array.".
3232
3233/**
3234 *
3235 * @param {Array<Array<string>>} foo
3236 */
3237function quux (foo) {
3238
3239}
3240// Settings: {"jsdoc":{"preferredTypes":{"<>":"[]"}}}
3241// Message: Invalid JSDoc @param "foo" type "Array"; prefer: "[]".
3242
3243/** @typedef {String} foo */
3244// Message: Invalid JSDoc @typedef "foo" type "String"; prefer: "string".
3245
3246/**
3247 * @this {array}
3248 */
3249function quux () {}
3250// Settings: {"jsdoc":{"mode":"closure"}}
3251// Message: Invalid JSDoc @this type "array"; prefer: "Array".
3252
3253/**
3254 * @export {array}
3255 */
3256function quux () {}
3257// Settings: {"jsdoc":{"mode":"closure"}}
3258// Message: Invalid JSDoc @export type "array"; prefer: "Array".
3259
3260/**
3261 * @typedef {object} foo
3262 * @property {object} bar
3263 */
3264// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
3265// Options: [{"exemptTagContexts":[{"tag":"typedef","types":true}]}]
3266// Message: Invalid JSDoc @property "bar" type "object"; prefer: "Object".
3267
3268/** @typedef {object} foo */
3269// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
3270// Options: [{"exemptTagContexts":[{"tag":"typedef","types":["array"]}]}]
3271// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object".
3272
3273/**
3274 * @typedef {object} foo
3275 * @property {object} bar
3276 */
3277// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
3278// Options: [{"exemptTagContexts":[{"tag":"typedef","types":["object"]}]}]
3279// Message: Invalid JSDoc @property "bar" type "object"; prefer: "Object".
3280
3281/** @typedef {object<string, string>} foo */
3282// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object<>"}}}
3283// Options: [{"exemptTagContexts":[{"tag":"typedef","types":["object"]}]}]
3284// Message: Invalid JSDoc @typedef "foo" type "object"; prefer: "Object<>".
3285````
3286
3287The following patterns are not considered problems:
3288
3289````js
3290/**
3291 * @param {number} foo
3292 * @param {Bar} bar
3293 * @param {*} baz
3294 */
3295function quux (foo, bar, baz) {
3296
3297}
3298
3299/**
3300 * @arg {number} foo
3301 * @arg {Bar} bar
3302 * @arg {*} baz
3303 */
3304function quux (foo, bar, baz) {
3305
3306}
3307
3308/**
3309 * @param {(number|string|boolean)=} foo
3310 */
3311function quux (foo, bar, baz) {
3312
3313}
3314
3315/**
3316 * @param {typeof bar} foo
3317 */
3318function qux(foo) {
3319}
3320
3321/**
3322 * @param {import('./foo').bar.baz} foo
3323 */
3324function qux(foo) {
3325}
3326
3327/**
3328 * @param {(x: number, y: string) => string} foo
3329 */
3330function qux(foo) {
3331}
3332
3333/**
3334 * @param {() => string} foo
3335 */
3336function qux(foo) {
3337}
3338
3339/**
3340 * @returns {Number} foo
3341 * @throws {Number} foo
3342 */
3343function quux () {
3344
3345}
3346// Options: [{"noDefaults":true}]
3347
3348/**
3349 * @param {Object} foo
3350 */
3351function quux (foo) {
3352
3353}
3354// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
3355
3356/**
3357 * @param {Array} foo
3358 */
3359function quux (foo) {
3360
3361}
3362
3363/**
3364 * @param {Array.<string>} foo
3365 */
3366function quux (foo) {
3367
3368}
3369// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
3370
3371/**
3372 * @param {Array<string>} foo
3373 */
3374function quux (foo) {
3375
3376}
3377// Settings: {"jsdoc":{"preferredTypes":{"Array":"GenericArray"}}}
3378
3379/**
3380 * @param {string[]} foo
3381 */
3382function quux (foo) {
3383
3384}
3385// Settings: {"jsdoc":{"preferredTypes":{"Array":"SpecialTypeArray","Array.<>":"SpecialTypeArray","Array<>":"SpecialTypeArray"}}}
3386
3387/**
3388 * @param {string[]} foo
3389 */
3390function quux (foo) {
3391
3392}
3393// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"SpecialTypeArray","Array<>":"SpecialTypeArray"}}}
3394// Options: [{"unifyParentAndChildTypeChecks":true}]
3395
3396/**
3397 * @param {Array} foo
3398 */
3399function quux (foo) {
3400
3401}
3402// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
3403
3404/**
3405 * @param {Array} foo
3406 */
3407function quux (foo) {
3408
3409}
3410// Settings: {"jsdoc":{"preferredTypes":{"[]":"SpecialTypeArray"}}}
3411// Options: [{"unifyParentAndChildTypeChecks":true}]
3412
3413/**
3414 * @param {Array} foo
3415 */
3416function quux (foo) {
3417
3418}
3419// Settings: {"jsdoc":{"preferredTypes":{"Array.<>":"GenericArray"}}}
3420
3421/**
3422 * @param {Array} foo
3423 */
3424function quux (foo) {
3425
3426}
3427// Settings: {"jsdoc":{"preferredTypes":{"Array<>":"GenericArray"}}}
3428
3429/**
3430 * @param {object} foo
3431 */
3432function quux (foo) {
3433
3434}
3435
3436/**
3437 * @param {object.<string>} foo
3438 */
3439function quux (foo) {
3440
3441}
3442// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3443
3444/**
3445 * @param {object<string>} foo
3446 */
3447function quux (foo) {
3448
3449}
3450// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3451
3452/**
3453 * @param {object.<string, number>} foo
3454 */
3455function quux (foo) {
3456
3457}
3458// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3459
3460/**
3461 * @param {object<string, number>} foo
3462 */
3463function quux (foo) {
3464
3465}
3466// Settings: {"jsdoc":{"preferredTypes":{"object":"GenericObject"}}}
3467
3468/**
3469 * @param {object} foo
3470 */
3471function quux (foo) {
3472
3473}
3474// Settings: {"jsdoc":{"preferredTypes":{"object.<>":"GenericObject"}}}
3475
3476/**
3477 * @param {object} foo
3478 */
3479function quux (foo) {
3480
3481}
3482// Settings: {"jsdoc":{"preferredTypes":{"object<>":"GenericObject"}}}
3483
3484/**
3485 * @param {Number<} Ignore the error as not a validating rule
3486 */
3487function quux (foo) {
3488
3489}
3490
3491/** @param {function(...)} callback The function to invoke. */
3492var subscribe = function(callback) {};
3493
3494/**
3495 * @this {Array}
3496 */
3497function quux () {}
3498// Settings: {"jsdoc":{"mode":"closure"}}
3499
3500/**
3501 * @export {Array}
3502 */
3503function quux () {}
3504// Settings: {"jsdoc":{"mode":"closure"}}
3505
3506/** @type {new() => EntityBase} */
3507
3508/** @typedef {object} foo */
3509// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
3510// Options: [{"exemptTagContexts":[{"tag":"typedef","types":true}]}]
3511
3512/** @typedef {object<string, string>} foo */
3513// Settings: {"jsdoc":{"preferredTypes":{"object":"Object"}}}
3514
3515/** @typedef {object<string, string>} foo */
3516// Settings: {"jsdoc":{"preferredTypes":{"object<>":"Object<>"}}}
3517// Options: [{"exemptTagContexts":[{"tag":"typedef","types":["object<string, string>"]}]}]
3518````
3519
3520
3521<a name="eslint-plugin-jsdoc-rules-check-values"></a>
3522### <code>check-values</code>
3523
3524This rule checks the values for a handful of tags:
3525
35261. `@version` - Checks that there is a present and valid
3527 [semver](https://semver.org/) version value.
35282. `@since` - As with `@version`
35293. `@license` - Checks that there is a present and valid SPDX identifier
3530 or is present within an `allowedLicenses` option.
35314. `@author` - Checks there is a value present, and if the option
3532 `allowedAuthors` is present, ensure that the author value is one
3533 of these array items.
3534
3535<a name="eslint-plugin-jsdoc-rules-check-values-options-7"></a>
3536#### Options
3537
3538<a name="eslint-plugin-jsdoc-rules-check-values-options-7-allowedauthors"></a>
3539##### <code>allowedAuthors</code>
3540
3541An array of allowable author values. If absent, only non-whitespace will
3542be checked for.
3543
3544<a name="eslint-plugin-jsdoc-rules-check-values-options-7-allowedlicenses"></a>
3545##### <code>allowedLicenses</code>
3546
3547An array of allowable license values or `true` to allow any license text.
3548If present as an array, will be used in place of SPDX identifiers.
3549
3550<a name="eslint-plugin-jsdoc-rules-check-values-options-7-licensepattern"></a>
3551##### <code>licensePattern</code>
3552
3553A string to be converted into a `RegExp` (with `u` flag) and whose first
3554parenthetical grouping, if present, will match the portion of the license
3555description to check (if no grouping is present, then the whole portion
3556matched will be used). Defaults to `([^\n]*)`, i.e., the SPDX expression
3557is expected before any line breaks.
3558
3559|||
3560|---|---|
3561|Context|everywhere|
3562|Tags|`@version`, `@since`, `@license`, `@author`|
3563|Options|`allowedAuthors`, `allowedLicenses`, `licensePattern`|
3564|Settings|`tagNamePreference`|
3565
3566The following patterns are considered problems:
3567
3568````js
3569/**
3570 * @version
3571 */
3572function quux (foo) {
3573
3574}
3575// Message: Missing JSDoc @version.
3576
3577/**
3578 * @version 3.1
3579 */
3580function quux (foo) {
3581
3582}
3583// Message: Invalid JSDoc @version: "3.1".
3584
3585/**
3586 * @since
3587 */
3588function quux (foo) {
3589
3590}
3591// Message: Missing JSDoc @since.
3592
3593/**
3594 * @since 3.1
3595 */
3596function quux (foo) {
3597
3598}
3599// Message: Invalid JSDoc @since: "3.1".
3600
3601/**
3602 * @license
3603 */
3604function quux (foo) {
3605
3606}
3607// Message: Missing JSDoc @license.
3608
3609/**
3610 * @license FOO
3611 */
3612function quux (foo) {
3613
3614}
3615// Message: Invalid JSDoc @license: "FOO"; expected SPDX expression: https://spdx.org/licenses/.
3616
3617/**
3618 * @license FOO
3619 */
3620function quux (foo) {
3621
3622}
3623// Options: [{"allowedLicenses":["BAR","BAX"]}]
3624// Message: Invalid JSDoc @license: "FOO"; expected one of BAR, BAX.
3625
3626/**
3627 * @license MIT-7
3628 * Some extra text...
3629 */
3630function quux (foo) {
3631
3632}
3633// Message: Invalid JSDoc @license: "MIT-7"; expected SPDX expression: https://spdx.org/licenses/.
3634
3635/**
3636 * @license (MIT OR GPL-2.5)
3637 */
3638function quux (foo) {
3639
3640}
3641// Message: Invalid JSDoc @license: "(MIT OR GPL-2.5)"; expected SPDX expression: https://spdx.org/licenses/.
3642
3643/**
3644 * @license MIT
3645 * Some extra text
3646 */
3647function quux (foo) {
3648
3649}
3650// Options: [{"licensePattern":"[\\s\\S]*"}]
3651// Message: Invalid JSDoc @license: "MIT
3652Some extra text"; expected SPDX expression: https://spdx.org/licenses/.
3653
3654/**
3655 * @author
3656 */
3657function quux (foo) {
3658
3659}
3660// Message: Missing JSDoc @author.
3661
3662/**
3663 * @author Brett Zamir
3664 */
3665function quux (foo) {
3666
3667}
3668// Options: [{"allowedAuthors":["Gajus Kuizinas","golopot"]}]
3669// Message: Invalid JSDoc @author: "Brett Zamir"; expected one of Gajus Kuizinas, golopot.
3670````
3671
3672The following patterns are not considered problems:
3673
3674````js
3675/**
3676 * @version 3.4.1
3677 */
3678function quux (foo) {
3679
3680}
3681
3682/**
3683 * @since 3.4.1
3684 */
3685function quux (foo) {
3686
3687}
3688
3689/**
3690 * @license MIT
3691 */
3692function quux (foo) {
3693
3694}
3695
3696/**
3697 * @license MIT
3698 * Some extra text...
3699 */
3700function quux (foo) {
3701
3702}
3703
3704/**
3705 * @license (MIT OR GPL-2.0)
3706 */
3707function quux (foo) {
3708
3709}
3710
3711/**
3712 * @license FOO
3713 */
3714function quux (foo) {
3715
3716}
3717// Options: [{"allowedLicenses":["FOO","BAR","BAX"]}]
3718
3719/**
3720 * @license FOO
3721 */
3722function quux (foo) {
3723
3724}
3725// Options: [{"allowedLicenses":true}]
3726
3727/**
3728 * @license MIT
3729 * Some extra text
3730 */
3731function quux (foo) {
3732
3733}
3734// Options: [{"licensePattern":"[^\n]*"}]
3735
3736/**
3737 * @author Gajus Kuizinas
3738 */
3739function quux (foo) {
3740
3741}
3742
3743/**
3744 * @author Brett Zamir
3745 */
3746function quux (foo) {
3747
3748}
3749// Options: [{"allowedAuthors":["Gajus Kuizinas","golopot","Brett Zamir"]}]
3750````
3751
3752
3753<a name="eslint-plugin-jsdoc-rules-empty-tags"></a>
3754### <code>empty-tags</code>
3755
3756Expects the following tags to be empty of any content:
3757
3758- `@abstract`
3759- `@async`
3760- `@generator`
3761- `@global`
3762- `@hideconstructor`
3763- `@ignore`
3764- `@inheritdoc`
3765- `@inner`
3766- `@instance`
3767- `@override`
3768- `@readonly`
3769
3770The following will also be expected to be empty unless `settings.jsdoc.mode`
3771is set to "closure" (which allows types).
3772
3773- `@package`
3774- `@private`
3775- `@protected`
3776- `@public`
3777- `@static`
3778
3779Note that `@private` will still be checked for content by this rule even with
3780`settings.jsdoc.ignorePrivate` set to `true` (a setting which normally
3781causes rules not to take effect).
3782
3783<a name="eslint-plugin-jsdoc-rules-empty-tags-options-8"></a>
3784#### Options
3785
3786<a name="eslint-plugin-jsdoc-rules-empty-tags-options-8-tags"></a>
3787##### <code>tags</code>
3788
3789If you want additional tags to be checked for their descriptions, you may
3790add them within this option.
3791
3792```js
3793{
3794 'jsdoc/empty-tags': ['error', {tags: ['event']}]
3795}
3796```
3797
3798|||
3799|---|---|
3800|Context|everywhere|
3801|Tags| and others added by `tags`|
3802|Aliases||
3803|Options|`tags`|
3804The following patterns are considered problems:
3805
3806````js
3807/**
3808 * @abstract extra text
3809 */
3810function quux () {
3811
3812}
3813// Message: @abstract should be empty.
3814
3815/**
3816 * @abstract extra text
3817 * @inheritdoc
3818 * @async out of place
3819 */
3820function quux () {
3821
3822}
3823// Message: @abstract should be empty.
3824
3825/**
3826 * @event anEvent
3827 */
3828function quux () {
3829
3830}
3831// Options: [{"tags":["event"]}]
3832// Message: @event should be empty.
3833
3834/**
3835 * @private {someType}
3836 */
3837function quux () {
3838
3839}
3840// Message: @private should be empty.
3841
3842/**
3843 * @private {someType}
3844 */
3845function quux () {
3846
3847}
3848// Settings: {"jsdoc":{"ignorePrivate":true}}
3849// Message: @private should be empty.
3850````
3851
3852The following patterns are not considered problems:
3853
3854````js
3855/**
3856 * @abstract
3857 */
3858function quux () {
3859
3860}
3861
3862/**
3863 *
3864 */
3865function quux () {
3866
3867}
3868
3869/**
3870 * @param aName
3871 */
3872function quux () {
3873
3874}
3875
3876/**
3877 * @abstract
3878 * @inheritdoc
3879 * @async
3880 */
3881function quux () {
3882
3883}
3884
3885/**
3886 * @private {someType}
3887 */
3888function quux () {
3889
3890}
3891// Settings: {"jsdoc":{"mode":"closure"}}
3892
3893/**
3894 * @private
3895 */
3896function quux () {
3897
3898}
3899````
3900
3901
3902<a name="eslint-plugin-jsdoc-rules-implements-on-classes"></a>
3903### <code>implements-on-classes</code>
3904
3905Reports an issue with any non-constructor function using `@implements`.
3906
3907Constructor functions, whether marked with `@class`, `@constructs`, or being
3908an ES6 class constructor, will not be flagged.
3909
3910To indicate that a function follows another function's signature, one might
3911instead use `@type` to indicate the `@function` or `@callback` to which the
3912funciton is adhering.
3913
3914<a name="eslint-plugin-jsdoc-rules-implements-on-classes-options-9"></a>
3915#### Options
3916
3917<a name="eslint-plugin-jsdoc-rules-implements-on-classes-options-9-contexts"></a>
3918##### <code>contexts</code>
3919
3920Set this to an array of strings representing the AST context
3921where you wish the rule to be applied.
3922Overrides the default contexts (see below). Set to `"any"` if you want
3923the rule to apply to any jsdoc block throughout your files (as is necessary
3924for finding function blocks not attached to a function declaration or
3925expression, i.e., `@callback` or `@function` (or its aliases `@func` or
3926`@method`) (including those associated with an `@interface`).
3927
3928|||
3929|---|---|
3930|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
3931|Tags|`implements` (prevented)|
3932
3933The following patterns are considered problems:
3934
3935````js
3936/**
3937 * @implements {SomeClass}
3938 */
3939function quux () {
3940
3941}
3942// Message: @implements used on a non-constructor function
3943
3944/**
3945 * @implements {SomeClass}
3946 */
3947function quux () {
3948
3949}
3950// Options: [{"contexts":["any"]}]
3951// Message: @implements used on a non-constructor function
3952
3953/**
3954 * @function
3955 * @implements {SomeClass}
3956 */
3957function quux () {
3958
3959}
3960// Options: [{"contexts":["any"]}]
3961// Message: @implements used on a non-constructor function
3962
3963/**
3964 * @callback
3965 * @implements {SomeClass}
3966 */
3967// Options: [{"contexts":["any"]}]
3968// Message: @implements used on a non-constructor function
3969
3970/**
3971 * @implements {SomeClass}
3972 */
3973function quux () {
3974
3975}
3976// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
3977// Message: Unexpected tag `@implements`
3978````
3979
3980The following patterns are not considered problems:
3981
3982````js
3983/**
3984 * @implements {SomeClass}
3985 * @class
3986 */
3987function quux () {
3988
3989}
3990
3991/**
3992 * @implements {SomeClass}
3993 * @class
3994 */
3995function quux () {
3996
3997}
3998// Options: [{"contexts":["any"]}]
3999
4000/**
4001 * @implements {SomeClass}
4002 */
4003// Options: [{"contexts":["any"]}]
4004
4005/**
4006 * @implements {SomeClass}
4007 * @constructor
4008 */
4009function quux () {
4010
4011}
4012
4013/**
4014 *
4015 */
4016class quux {
4017 /**
4018 * @implements {SomeClass}
4019 */
4020 constructor () {
4021
4022 }
4023}
4024
4025/**
4026 *
4027 */
4028const quux = class {
4029 /**
4030 * @implements {SomeClass}
4031 */
4032 constructor () {
4033
4034 }
4035}
4036
4037/**
4038 *
4039 */
4040function quux () {
4041
4042}
4043
4044/**
4045 *
4046 */
4047function quux () {
4048
4049}
4050// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
4051
4052/**
4053 * @function
4054 * @implements {SomeClass}
4055 */
4056
4057/**
4058 * @callback
4059 * @implements {SomeClass}
4060 */
4061````
4062
4063
4064<a name="eslint-plugin-jsdoc-rules-match-description"></a>
4065### <code>match-description</code>
4066
4067Enforces a regular expression pattern on descriptions.
4068
4069The default is this basic expression to match English sentences (Support
4070for Unicode upper case may be added in a future version when it can be handled
4071by our supported Node versions):
4072
4073``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$``
4074
4075Applies to the jsdoc block description and `@description` (or `@desc`)
4076by default but the `tags` option (see below) may be used to match other tags.
4077
4078<a name="eslint-plugin-jsdoc-rules-match-description-options-10"></a>
4079#### Options
4080
4081<a name="eslint-plugin-jsdoc-rules-match-description-options-10-matchdescription"></a>
4082##### <code>matchDescription</code>
4083
4084You can supply your own expression to override the default, passing a
4085`matchDescription` string on the options object.
4086
4087```js
4088{
4089 'jsdoc/match-description': ['error', {matchDescription: '[A-Z].*\\.'}]
4090}
4091```
4092
4093As with the default, the supplied regular expression will be applied with the
4094Unicode (`"u"`) flag and is *not* case-insensitive.
4095
4096<a name="eslint-plugin-jsdoc-rules-match-description-options-10-tags-1"></a>
4097##### <code>tags</code>
4098
4099If you want different regular expressions to apply to tags, you may use
4100the `tags` option object:
4101
4102```js
4103{
4104 'jsdoc/match-description': ['error', {tags: {
4105 param: '\\- [A-Z].*\\.',
4106 returns: '[A-Z].*\\.'
4107 }}]
4108}
4109```
4110
4111In place of a string, you can also add `true` to indicate that a particular
4112tag should be linted with the `matchDescription` value (or the default).
4113
4114```js
4115{
4116 'jsdoc/match-description': ['error', {tags: {
4117 param: true,
4118 returns: true
4119 }}]
4120}
4121```
4122
4123The tags `@param`/`@arg`/`@argument` and `@property`/`@prop` will be properly
4124parsed to ensure that the matched "description" text includes only the text
4125after the name.
4126
4127All other tags will treat the text following the tag name, a space, and
4128an optional curly-bracketed type expression (and another space) as part of
4129its "description" (e.g., for `@returns {someType} some description`, the
4130description is `some description` while for `@some-tag xyz`, the description
4131is `xyz`).
4132
4133<a name="eslint-plugin-jsdoc-rules-match-description-options-10-maindescription"></a>
4134##### <code>mainDescription</code>
4135
4136If you wish to override the main function description without changing the
4137default `match-description`, you may use `mainDescription`:
4138
4139```js
4140{
4141 'jsdoc/match-description': ['error', {
4142 mainDescription: '[A-Z].*\\.',
4143 tags: {
4144 param: true,
4145 returns: true
4146 }
4147 }]
4148}
4149```
4150
4151There is no need to add `mainDescription: true`, as by default, the main
4152function (and only the main function) is linted, though you may disable checking
4153it by setting it to `false`.
4154
4155<a name="eslint-plugin-jsdoc-rules-match-description-options-10-contexts-1"></a>
4156##### <code>contexts</code>
4157
4158Set this to an array of strings representing the AST context
4159where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6 classes).
4160Overrides the default contexts (see below). Set to `"any"` if you want
4161the rule to apply to any jsdoc block throughout your files.
4162
4163|||
4164|---|---|
4165|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
4166|Tags|docblock and `@description` by default but more with `tags`|
4167|Aliases|`@desc`|
4168|Settings||
4169|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`|
4170
4171The following patterns are considered problems:
4172
4173````js
4174/**
4175 * foo.
4176 */
4177const q = class {
4178
4179}
4180// Options: [{"contexts":["ClassExpression"]}]
4181// Message: JSDoc description does not satisfy the regex pattern.
4182
4183/**
4184 * foo.
4185 */
4186// Options: [{"contexts":["any"]}]
4187// Message: JSDoc description does not satisfy the regex pattern.
4188
4189/**
4190 * foo.
4191 */
4192// Options: [{"contexts":["any"]}]
4193// Message: JSDoc description does not satisfy the regex pattern.
4194
4195/**
4196 * foo.
4197 */
4198const q = {
4199
4200};
4201// Options: [{"contexts":["ObjectExpression"]}]
4202// Message: JSDoc description does not satisfy the regex pattern.
4203
4204/**
4205 * foo.
4206 */
4207function quux () {
4208
4209}
4210// Message: JSDoc description does not satisfy the regex pattern.
4211
4212/**
4213 * Foo)
4214 */
4215function quux () {
4216
4217}
4218// Message: JSDoc description does not satisfy the regex pattern.
4219
4220/**
4221 * тест.
4222 */
4223function quux () {
4224
4225}
4226// Options: [{"matchDescription":"[А-Я][А-я]+\\."}]
4227// Message: JSDoc description does not satisfy the regex pattern.
4228
4229/**
4230 * Abc.
4231 */
4232function quux () {
4233
4234}
4235// Options: [{"mainDescription":"[А-Я][А-я]+\\.","tags":{"param":true}}]
4236// Message: JSDoc description does not satisfy the regex pattern.
4237
4238/**
4239 * Foo
4240 */
4241function quux () {
4242
4243}
4244// Message: JSDoc description does not satisfy the regex pattern.
4245
4246/**
4247 * Foo.
4248 *
4249 * @param foo foo.
4250 */
4251function quux (foo) {
4252
4253}
4254// Options: [{"tags":{"param":true}}]
4255// Message: JSDoc description does not satisfy the regex pattern.
4256
4257/**
4258 * Foo.
4259 *
4260 * @prop foo foo.
4261 */
4262function quux (foo) {
4263
4264}
4265// Options: [{"tags":{"prop":true}}]
4266// Message: JSDoc description does not satisfy the regex pattern.
4267
4268/**
4269 * Foo.
4270 *
4271 * @summary foo.
4272 */
4273function quux () {
4274
4275}
4276// Options: [{"tags":{"summary":true}}]
4277// Message: JSDoc description does not satisfy the regex pattern.
4278
4279/**
4280 * Foo.
4281 *
4282 * @author
4283 */
4284function quux () {
4285
4286}
4287// Options: [{"tags":{"author":".+"}}]
4288// Message: JSDoc description does not satisfy the regex pattern.
4289
4290/**
4291 * Foo.
4292 *
4293 * @x-tag
4294 */
4295function quux () {
4296
4297}
4298// Options: [{"tags":{"x-tag":".+"}}]
4299// Message: JSDoc description does not satisfy the regex pattern.
4300
4301/**
4302 * Foo.
4303 *
4304 * @description foo foo.
4305 */
4306function quux (foo) {
4307
4308}
4309// Options: [{"tags":{"description":true}}]
4310// Message: JSDoc description does not satisfy the regex pattern.
4311
4312/**
4313 * Foo
4314 *
4315 * @param foo foo.
4316 */
4317function quux (foo) {
4318
4319}
4320// Options: [{"mainDescription":"^[a-zA-Z]*$","tags":{"param":true}}]
4321// Message: JSDoc description does not satisfy the regex pattern.
4322
4323/**
4324 * Foo
4325 *
4326 * @param foo foo.
4327 */
4328function quux (foo) {
4329
4330}
4331// Options: [{"mainDescription":false,"tags":{"param":true}}]
4332// Message: JSDoc description does not satisfy the regex pattern.
4333
4334/**
4335 * Foo.
4336 *
4337 * @param foo bar
4338 */
4339function quux (foo) {
4340
4341}
4342// Options: [{"tags":{"param":true}}]
4343// Message: JSDoc description does not satisfy the regex pattern.
4344
4345/**
4346 * {@see Foo.bar} buz
4347 */
4348function quux (foo) {
4349
4350}
4351// Message: JSDoc description does not satisfy the regex pattern.
4352
4353/**
4354 * Foo.
4355 *
4356 * @returns {number} foo
4357 */
4358function quux (foo) {
4359
4360}
4361// Options: [{"tags":{"returns":true}}]
4362// Message: JSDoc description does not satisfy the regex pattern.
4363
4364/**
4365 * Foo.
4366 *
4367 * @returns foo.
4368 */
4369function quux (foo) {
4370
4371}
4372// Options: [{"tags":{"returns":true}}]
4373// Message: JSDoc description does not satisfy the regex pattern.
4374
4375/**
4376 * lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
4377 * iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
4378 * tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
4379 * vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
4380 * proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
4381 * consequat auctor magna. duis pharetra purus in porttitor mollis.
4382 */
4383function longDescription (foo) {
4384
4385}
4386// Message: JSDoc description does not satisfy the regex pattern.
4387
4388/**
4389 * @arg {number} foo - Foo
4390 */
4391function quux (foo) {
4392
4393}
4394// Options: [{"tags":{"arg":true}}]
4395// Message: JSDoc description does not satisfy the regex pattern.
4396
4397/**
4398 * @argument {number} foo - Foo
4399 */
4400function quux (foo) {
4401
4402}
4403// Options: [{"tags":{"argument":true}}]
4404// Message: JSDoc description does not satisfy the regex pattern.
4405
4406/**
4407 * @return {number} foo
4408 */
4409function quux (foo) {
4410
4411}
4412// Options: [{"tags":{"return":true}}]
4413// Message: JSDoc description does not satisfy the regex pattern.
4414
4415/**
4416 * Returns bar.
4417 *
4418 * @return {number} bar
4419 */
4420function quux (foo) {
4421
4422}
4423// Options: [{"tags":{"return":true}}]
4424// Message: JSDoc description does not satisfy the regex pattern.
4425
4426/**
4427 * @param notRet
4428 * @returns Тест.
4429 */
4430function quux () {
4431
4432}
4433// Options: [{"tags":{"param":"[А-Я][А-я]+\\."}}]
4434// Message: JSDoc description does not satisfy the regex pattern.
4435
4436/**
4437 * @description notRet
4438 * @returns Тест.
4439 */
4440function quux () {
4441
4442}
4443// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
4444// Message: JSDoc description does not satisfy the regex pattern.
4445
4446/**
4447 * foo.
4448 */
4449class quux {
4450
4451}
4452// Options: [{"contexts":["ClassDeclaration"]}]
4453// Message: JSDoc description does not satisfy the regex pattern.
4454
4455class MyClass {
4456 /**
4457 * Abc
4458 */
4459 myClassField = 1
4460}
4461// Options: [{"contexts":["ClassProperty"]}]
4462// Message: JSDoc description does not satisfy the regex pattern.
4463
4464/**
4465 * foo.
4466 */
4467interface quux {
4468
4469}
4470// Options: [{"contexts":["TSInterfaceDeclaration"]}]
4471// Message: JSDoc description does not satisfy the regex pattern.
4472
4473const myObject = {
4474 /**
4475 * Bad description
4476 */
4477 myProp: true
4478};
4479// Options: [{"contexts":["Property"]}]
4480// Message: JSDoc description does not satisfy the regex pattern.
4481
4482/**
4483 * @param foo Foo bar
4484 */
4485function quux (foo) {
4486
4487}
4488// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4489// Options: [{"tags":{"param":true}}]
4490// Message: JSDoc description does not satisfy the regex pattern.
4491
4492/**
4493 * Foo bar
4494 */
4495function quux (foo) {
4496
4497}
4498// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4499// Message: JSDoc description does not satisfy the regex pattern.
4500````
4501
4502The following patterns are not considered problems:
4503
4504````js
4505/**
4506 *
4507 */
4508
4509/**
4510 *
4511 */
4512 function quux () {
4513
4514 }
4515
4516/**
4517 * @param foo - Foo.
4518 */
4519function quux () {
4520
4521}
4522// Options: [{"tags":{"param":true}}]
4523
4524/**
4525 * Foo.
4526 */
4527function quux () {
4528
4529}
4530
4531/**
4532 * Foo.
4533 * Bar.
4534 */
4535function quux () {
4536
4537}
4538
4539/**
4540 * Foo.
4541 *
4542 * Bar.
4543 */
4544function quux () {
4545
4546}
4547
4548/**
4549 * Тест.
4550 */
4551function quux () {
4552
4553}
4554// Options: [{"matchDescription":"[А-Я][А-я]+\\."}]
4555
4556/**
4557 * @param notRet
4558 * @returns Тест.
4559 */
4560function quux () {
4561
4562}
4563// Options: [{"tags":{"returns":"[А-Я][А-я]+\\."}}]
4564
4565/**
4566 * @param notRet
4567 * @description Тест.
4568 */
4569function quux () {
4570
4571}
4572// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
4573
4574/**
4575 * Foo
4576 * bar.
4577 */
4578function quux () {
4579
4580}
4581
4582/**
4583 * @returns Foo bar.
4584 */
4585function quux () {
4586
4587}
4588// Options: [{"tags":{"returns":true}}]
4589
4590/**
4591 * @returns {type1} Foo bar.
4592 */
4593function quux () {
4594
4595}
4596// Options: [{"tags":{"returns":true}}]
4597
4598/**
4599 * @description Foo bar.
4600 */
4601function quux () {
4602
4603}
4604// Options: [{"tags":{"description":true}}]
4605
4606/**
4607 * Foo. {@see Math.sin}.
4608 */
4609function quux () {
4610
4611}
4612
4613/**
4614 * Foo {@see Math.sin} bar.
4615 */
4616function quux () {
4617
4618}
4619
4620/**
4621 * Foo?
4622 *
4623 * Bar!
4624 *
4625 * Baz:
4626 * 1. Foo.
4627 * 2. Bar.
4628 */
4629function quux () {
4630
4631}
4632
4633/**
4634 * Hello:
4635 * World.
4636 */
4637function quux () {
4638
4639}
4640
4641/**
4642 * Hello: world.
4643 */
4644function quux () {
4645
4646}
4647
4648/**
4649 * Foo
4650 * Bar.
4651 */
4652function quux () {
4653
4654}
4655
4656/**
4657 * Foo.
4658 *
4659 * foo.
4660 */
4661function quux () {
4662
4663}
4664
4665/**
4666 * foo.
4667 */
4668function quux () {
4669
4670}
4671// Options: [{"mainDescription":false}]
4672
4673/**
4674 * foo.
4675 */
4676class quux {
4677
4678}
4679
4680/**
4681 * foo.
4682 */
4683class quux {
4684
4685}
4686// Options: [{"mainDescription":true}]
4687
4688class MyClass {
4689 /**
4690 * Abc.
4691 */
4692 myClassField = 1
4693}
4694// Options: [{"contexts":["ClassProperty"]}]
4695
4696/**
4697 * Foo.
4698 */
4699interface quux {
4700
4701}
4702// Options: [{"contexts":["TSInterfaceDeclaration"]}]
4703
4704const myObject = {
4705 /**
4706 * Bad description
4707 */
4708 myProp: true
4709};
4710// Options: [{"contexts":[]}]
4711
4712/**
4713 * foo.
4714 */
4715const q = class {
4716
4717}
4718// Options: [{"contexts":[]}]
4719
4720/**
4721 * foo.
4722 */
4723const q = {
4724
4725};
4726// Options: [{"contexts":[]}]
4727
4728/**
4729 * @description foo.
4730 */
4731function quux () {
4732
4733}
4734// Options: [{"tags":{"param":true}}]
4735
4736/**
4737 * Foo.
4738 *
4739 * @summary Foo.
4740 */
4741function quux () {
4742
4743}
4744// Options: [{"tags":{"summary":true}}]
4745
4746/**
4747 * Foo.
4748 *
4749 * @author Somebody
4750 */
4751function quux () {
4752
4753}
4754// Options: [{"tags":{"author":".+"}}]
4755
4756/**
4757 * Foo.
4758 *
4759 * @x-tag something
4760 */
4761function quux () {
4762
4763}
4764// Options: [{"tags":{"x-tag":".+"}}]
4765
4766/**
4767 * Foo.
4768 *
4769 * @prop foo Foo.
4770 */
4771function quux (foo) {
4772
4773}
4774// Options: [{"tags":{"prop":true}}]
4775
4776/**
4777 * @param foo Foo bar.
4778 */
4779function quux (foo) {
4780
4781}
4782// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4783
4784/**
4785 *
4786 */
4787function quux () {
4788
4789}
4790// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4791````
4792
4793
4794<a name="eslint-plugin-jsdoc-rules-newline-after-description"></a>
4795### <code>newline-after-description</code>
4796
4797Enforces a consistent padding of the block description.
4798
4799<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-11"></a>
4800#### Options
4801
4802This rule allows one optional string argument. If it is `"always"` then a problem is raised when there is no newline after the description. If it is `"never"` then a problem is raised when there is a newline after the description. The default value is `"always"`.
4803
4804|||
4805|---|---|
4806|Context|everywhere|
4807|Options|(a string matching `"always"|"never"`)|
4808|Tags|N/A (doc block)|
4809
4810The following patterns are considered problems:
4811
4812````js
4813/**
4814 * Foo.
4815 *
4816 * Foo.
4817 * @foo
4818 */
4819function quux () {
4820
4821}
4822// Options: ["always"]
4823// Message: There must be a newline after the description of the JSDoc block.
4824
4825/**
4826 * Foo.
4827 * @foo
4828 *
4829 * Foo.
4830 */
4831function quux () {
4832
4833}
4834// Options: ["always"]
4835// Message: There must be a newline after the description of the JSDoc block.
4836
4837/**
4838 * Foo.
4839 *
4840 * Foo.
4841 * @foo
4842 */
4843function quux () {
4844
4845}
4846// Message: There must be a newline after the description of the JSDoc block.
4847
4848/**
4849 * Bar.
4850 *
4851 * Bar.
4852 *
4853 * @bar
4854 */
4855function quux () {
4856
4857}
4858// Options: ["never"]
4859// Message: There must be no newline after the description of the JSDoc block.
4860
4861/**
4862 * Bar.
4863 *
4864 * @bar
4865 *
4866 * Bar.
4867 */
4868function quux () {
4869
4870}
4871// Options: ["never"]
4872// Message: There must be no newline after the description of the JSDoc block.
4873
4874
4875 /**
4876 * Bar.
4877 *
4878 * Bar.
4879 *
4880 * @bar
4881 */
4882 function quux () {
4883
4884 }
4885// Options: ["never"]
4886// Message: There must be no newline after the description of the JSDoc block.
4887
4888/**
4889 * A.
4890 *
4891 * @typedef {object} A
4892 * @prop {boolean} a A.
4893 */
4894// Options: ["never"]
4895// Message: There must be no newline after the description of the JSDoc block.
4896
4897/**
4898 * A.
4899 * @typedef {object} A
4900 * @prop {boolean} a A.
4901 */
4902// Options: ["always"]
4903// Message: There must be a newline after the description of the JSDoc block.
4904
4905
4906 /**
4907 * Service for fetching symbols.
4908 * @param {object} $http - Injected http helper.
4909 * @param {object} $q - Injected Promise api helper.
4910 * @param {object} $location - Injected window location object.
4911 * @param {object} REPORT_DIALOG_CONSTANTS - Injected handle.
4912 */
4913// Message: There must be a newline after the description of the JSDoc block.
4914````
4915
4916The following patterns are not considered problems:
4917
4918````js
4919/**
4920 * Foo.
4921 */
4922function quux () {
4923
4924}
4925// Options: ["always"]
4926
4927/**
4928 * Bar.
4929 */
4930function quux () {
4931
4932}
4933// Options: ["never"]
4934
4935/**
4936 * Foo.
4937 *
4938 * @foo
4939 */
4940function quux () {
4941
4942}
4943// Options: ["always"]
4944
4945/**
4946 * Bar.
4947 * @bar
4948 */
4949function quux () {
4950
4951}
4952// Options: ["never"]
4953
4954
4955 /**
4956 * @foo
4957 * Test 
4958 * abc 
4959 * @bar 
4960 */
4961
4962
4963 /**
4964 *
4965 * @foo
4966 * Test 
4967 * abc 
4968 * @bar 
4969 */
4970
4971/***
4972 *
4973 */
4974function quux () {
4975
4976}
4977// Options: ["always"]
4978
4979/**
4980 * Parses query string to object containing URL parameters
4981 *
4982 * @param queryString
4983 * Input string
4984 *
4985 * @returns
4986 * Object containing URL parameters
4987 */
4988export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails
4989
4990}
4991````
4992
4993
4994<a name="eslint-plugin-jsdoc-rules-no-types"></a>
4995### <code>no-types</code>
4996
4997This rule reports types being used on `@param` or `@returns`.
4998
4999The rule is intended to prevent the indication of types on tags where
5000the type information would be redundant with TypeScript.
5001
5002<a name="eslint-plugin-jsdoc-rules-no-types-options-12"></a>
5003#### Options
5004
5005<a name="eslint-plugin-jsdoc-rules-no-types-options-12-contexts-2"></a>
5006##### <code>contexts</code>
5007
5008Set this to an array of strings representing the AST context
5009where you wish the rule to be applied.
5010Overrides the default contexts (see below). Set to `"any"` if you want
5011the rule to apply to any jsdoc block throughout your files (as is necessary
5012for finding function blocks not attached to a function declaration or
5013expression, i.e., `@callback` or `@function` (or its aliases `@func` or
5014`@method`) (including those associated with an `@interface`).
5015
5016|||
5017|---|---|
5018|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
5019|Tags|`param`, `returns`|
5020|Aliases|`arg`, `argument`, `return`|
5021
5022The following patterns are considered problems:
5023
5024````js
5025/**
5026 * @param {number} foo
5027 */
5028function quux (foo) {
5029
5030}
5031// Message: Types are not permitted on @param.
5032
5033/**
5034 * @param {number} foo
5035 */
5036function quux (foo) {
5037
5038}
5039// Options: [{"contexts":["any"]}]
5040// Message: Types are not permitted on @param.
5041
5042/**
5043 * @function
5044 * @param {number} foo
5045 */
5046// Options: [{"contexts":["any"]}]
5047// Message: Types are not permitted on @param.
5048
5049/**
5050 * @callback
5051 * @param {number} foo
5052 */
5053// Options: [{"contexts":["any"]}]
5054// Message: Types are not permitted on @param.
5055
5056/**
5057 * @returns {number}
5058 */
5059function quux () {
5060
5061}
5062// Message: Types are not permitted on @returns.
5063````
5064
5065The following patterns are not considered problems:
5066
5067````js
5068/**
5069 * @param foo
5070 */
5071function quux (foo) {
5072
5073}
5074
5075/**
5076 * @param foo
5077 */
5078// Options: [{"contexts":["any"]}]
5079
5080/**
5081 * @function
5082 * @param {number} foo
5083 */
5084
5085/**
5086 * @callback
5087 * @param {number} foo
5088 */
5089````
5090
5091
5092<a name="eslint-plugin-jsdoc-rules-no-undefined-types"></a>
5093### <code>no-undefined-types</code>
5094
5095Checks that types in jsdoc comments are defined. This can be used to check
5096unimported types.
5097
5098When enabling this rule, types in jsdoc comments will resolve as used
5099variables, i.e. will not be marked as unused by `no-unused-vars`.
5100
5101In addition to considering globals found in code (or in ESLint-indicated
5102`globals`) as defined, the following tags will also be checked for
5103name(path) definitions to also serve as a potential "type" for checking
5104the tag types in the table below:
5105
5106`@callback`, `@class` (or `@constructor`), `@constant` (or `@const`), `@event`, `@external` (or `@host`), `@function` (or `@func` or `@method`), `@interface`, `@member` (or `@var`), `@mixin`, `@name`, `@namespace`, `@template` (for "closure" or "typescript" `settings.jsdoc.mode` only), `@typedef`.
5107
5108The following tags will also be checked but only when the mode is `closure`:
5109
5110`@package`, `@private`, `@protected`, `@public`, `@static`
5111
5112The following types are always considered defined.
5113
5114- `null`, `undefined`, `void`, `string`, `boolean`, `object`, `function`
5115- `number`, `NaN`, `Infinity`
5116- `any`, `*`
5117- `Array`, `Object`, `RegExp`, `Date`, `Function`
5118
5119Note that preferred types indicated within `settings.jsdoc.preferredTypes` will
5120also be assumed to be defined.
5121
5122<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-13"></a>
5123#### Options
5124
5125An option object may have the following key:
5126
5127- `definedTypes` - This array can be populated to indicate other types which
5128 are automatically considered as defined (in addition to globals, etc.).
5129 Defaults to an empty array.
5130
5131|||
5132|---|---|
5133|Context|everywhere|
5134|Tags|`augments`, `class`, `constant`, `enum`, `implements`, `member`, `module`, `namespace`, `param`, `property`, `returns`, `throws`, `type`, `typedef`, `yields`|
5135|Aliases|`constructor`, `const`, `extends`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
5136|Closure-only|`package`, `private`, `protected`, `public`, `static`|
5137|Options|`definedTypes`|
5138|Settings|`preferredTypes`, `mode`|
5139
5140The following patterns are considered problems:
5141
5142````js
5143/**
5144 * @param {HerType} baz - Foo.
5145 */
5146function quux(foo, bar, baz) {
5147
5148}
5149// Settings: {"jsdoc":{"preferredTypes":{"HerType":1000}}}
5150// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
5151
5152/**
5153 * @param {HerType} baz - Foo.
5154 */
5155function quux(foo, bar, baz) {
5156
5157}
5158// Settings: {"jsdoc":{"preferredTypes":{"HerType":false}}}
5159// Message: The type 'HerType' is undefined.
5160
5161/**
5162 * @param {strnig} foo - Bar.
5163 */
5164function quux(foo) {
5165
5166}
5167// Message: The type 'strnig' is undefined.
5168
5169/**
5170 * @param {MyType} foo - Bar.
5171 * @param {HisType} bar - Foo.
5172 */
5173function quux(foo, bar) {
5174
5175}
5176// Options: [{"definedTypes":["MyType"]}]
5177// Message: The type 'HisType' is undefined.
5178
5179/**
5180 * @param {MyType} foo - Bar.
5181 * @param {HisType} bar - Foo.
5182 * @param {HerType} baz - Foo.
5183 */
5184function quux(foo, bar, baz) {
5185
5186}
5187// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"}}}}
5188// Options: [{"definedTypes":["MyType"]}]
5189// Message: The type 'HisType' is undefined.
5190
5191 /**
5192 * @param {MyType} foo - Bar.
5193 * @param {HisType} bar - Foo.
5194 * @param {HerType} baz - Foo.
5195 */
5196function quux(foo, bar, baz) {
5197
5198}
5199// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":false},"histype":"HisType"}}}
5200// Options: [{"definedTypes":["MyType"]}]
5201// Message: The type 'HerType' is undefined.
5202
5203/**
5204 * @template TEMPLATE_TYPE
5205 * @param {WRONG_TEMPLATE_TYPE} bar
5206 */
5207function foo (bar) {
5208};
5209// Settings: {"jsdoc":{"mode":"closure"}}
5210// Message: The type 'WRONG_TEMPLATE_TYPE' is undefined.
5211
5212class Foo {
5213 /**
5214 * @return {TEMPLATE_TYPE}
5215 */
5216 bar () {
5217 }
5218}
5219// Message: The type 'TEMPLATE_TYPE' is undefined.
5220
5221class Foo {
5222 /**
5223 * @return {TEMPLATE_TYPE}
5224 */
5225 invalidTemplateReference () {
5226 }
5227}
5228
5229/**
5230 * @template TEMPLATE_TYPE
5231 */
5232class Bar {
5233 /**
5234 * @return {TEMPLATE_TYPE}
5235 */
5236 validTemplateReference () {
5237 }
5238}
5239// Settings: {"jsdoc":{"mode":"typescript"}}
5240// Message: The type 'TEMPLATE_TYPE' is undefined.
5241
5242/**
5243 * @type {strnig}
5244 */
5245var quux = {
5246
5247};
5248// Message: The type 'strnig' is undefined.
5249
5250/**
5251 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
5252 */
5253class Foo {
5254 /**
5255 * @param {TEMPLATE_TYPE_A} baz
5256 * @return {TEMPLATE_TYPE_B}
5257 */
5258 bar (baz) {
5259 }
5260}
5261// Message: The type 'TEMPLATE_TYPE_A' is undefined.
5262
5263/**
5264 * @param {...VAR_TYPE} varargs
5265 */
5266function quux (varargs) {
5267}
5268// Message: The type 'VAR_TYPE' is undefined.
5269
5270/**
5271 * @this {Navigator}
5272 */
5273function quux () {}
5274// Settings: {"jsdoc":{"mode":"closure"}}
5275// Message: The type 'Navigator' is undefined.
5276
5277/**
5278 * @export {SomeType}
5279 */
5280function quux () {}
5281// Settings: {"jsdoc":{"mode":"closure"}}
5282// Message: The type 'SomeType' is undefined.
5283````
5284
5285The following patterns are not considered problems:
5286
5287````js
5288/**
5289 * @param {string} foo - Bar.
5290 */
5291function quux(foo) {
5292
5293}
5294
5295/**
5296 * @param {Promise} foo - Bar.
5297 */
5298function quux(foo) {
5299
5300}
5301
5302class MyClass {}
5303
5304/**
5305 * @param {MyClass} foo - Bar.
5306 */
5307function quux(foo) {
5308 console.log(foo);
5309}
5310
5311quux(0);
5312
5313const MyType = require('my-library').MyType;
5314
5315/**
5316 * @param {MyType} foo - Bar.
5317 */
5318 function quux(foo) {
5319
5320}
5321
5322const MyType = require('my-library').MyType;
5323
5324/**
5325 * @param {MyType} foo - Bar.
5326 */
5327 function quux(foo) {
5328
5329}
5330
5331import {MyType} from 'my-library';
5332
5333/**
5334 * @param {MyType} foo - Bar.
5335 * @param {object<string, number>} foo
5336 * @param {Array<string>} baz
5337 */
5338 function quux(foo, bar, baz) {
5339
5340}
5341
5342/*globals MyType*/
5343
5344/**
5345 * @param {MyType} foo - Bar.
5346 * @param {HisType} bar - Foo.
5347 */
5348 function quux(foo, bar) {
5349
5350}
5351
5352/**
5353 * @typedef {object} hello
5354 * @property {string} a - a.
5355 */
5356
5357/**
5358 * @param {hello} foo
5359 */
5360function quux(foo) {
5361
5362}
5363
5364/**
5365 * @param {Array<syntaxError} foo
5366 */
5367function quux(foo) {
5368
5369}
5370
5371/**
5372 * Callback test.
5373 *
5374 * @callback addStuffCallback
5375 * @param {String} sum - An test integer.
5376 */
5377/**
5378 * Test Eslint.
5379 *
5380 * @param {addStuffCallback} callback - A callback to run.
5381 */
5382function testFunction(callback) {
5383 callback();
5384}
5385
5386/**
5387 *
5388 *
5389 */
5390function foo () {
5391
5392}
5393
5394/**
5395 *
5396 *
5397 */
5398function foo () {
5399
5400}
5401
5402/**
5403 * @param {MyType} foo - Bar.
5404 * @param {HisType} bar - Foo.
5405 */
5406function quux(foo, bar) {
5407
5408}
5409// Options: [{"definedTypes":["MyType","HisType"]}]
5410
5411/**
5412 * @param {MyType} foo - Bar.
5413 * @param {HisType} bar - Foo.
5414 * @param {HerType} baz - Foo.
5415 */
5416function quux(foo, bar, baz) {
5417
5418}
5419// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"},"histype":"HisType"}}}
5420// Options: [{"definedTypes":["MyType"]}]
5421
5422/**
5423 * @param {MyType} foo - Bar.
5424 * @param {HisType} bar - Foo.
5425 * @param {HerType} baz - Foo.
5426 */
5427function quux(foo, bar, baz) {
5428
5429}
5430// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType<>"},"histype":"HisType.<>"}}}
5431// Options: [{"definedTypes":["MyType"]}]
5432
5433/**
5434 * @template TEMPLATE_TYPE
5435 * @param {TEMPLATE_TYPE} bar
5436 * @return {TEMPLATE_TYPE}
5437 */
5438function foo (bar) {
5439};
5440// Settings: {"jsdoc":{"mode":"closure"}}
5441
5442/**
5443 * @template TEMPLATE_TYPE
5444 */
5445class Foo {
5446 /**
5447 * @return {TEMPLATE_TYPE}
5448 */
5449 bar () {
5450 }
5451}
5452// Settings: {"jsdoc":{"mode":"closure"}}
5453
5454/**
5455 * @template TEMPLATE_TYPE
5456 */
5457class Foo {
5458 /**
5459 * @return {TEMPLATE_TYPE}
5460 */
5461 bar () {}
5462
5463 /**
5464 * @return {TEMPLATE_TYPE}
5465 */
5466 baz () {}
5467}
5468// Settings: {"jsdoc":{"mode":"closure"}}
5469
5470/**
5471 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
5472 */
5473class Foo {
5474 /**
5475 * @param {TEMPLATE_TYPE_A} baz
5476 * @return {TEMPLATE_TYPE_B}
5477 */
5478 bar (baz) {
5479 }
5480}
5481// Settings: {"jsdoc":{"mode":"closure"}}
5482
5483/****/
5484
5485/**
5486 *
5487 */
5488function quux () {
5489
5490}
5491
5492/**
5493 * Run callback when hooked method is called.
5494 *
5495 * @template {BaseObject} T
5496 * @param {T} obj - object whose method should be hooked.
5497 * @param {string} method - method which should be hooked.
5498 * @param {(sender: T) => void} callback - callback which should
5499 * be called when the hooked method was invoked.
5500 */
5501function registerEvent(obj, method, callback) {
5502
5503}
5504// Settings: {"jsdoc":{"mode":"typescript"}}
5505
5506 /**
5507 * @param {...} varargs
5508 */
5509function quux (varargs) {
5510}
5511
5512/**
5513 * @param {...number} varargs
5514 */
5515function quux (varargs) {
5516}
5517
5518class Navigator {}
5519/**
5520 * @this {Navigator}
5521 */
5522function quux () {}
5523// Settings: {"jsdoc":{"mode":"closure"}}
5524
5525class SomeType {}
5526/**
5527 * @export {SomeType}
5528 */
5529function quux () {}
5530// Settings: {"jsdoc":{"mode":"closure"}}
5531````
5532
5533
5534<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence"></a>
5535### <code>require-description-complete-sentence</code>
5536
5537Requires that block description, explicit `@description`, and `@param`/`@returns`
5538tag descriptions are written in complete sentences, i.e.,
5539
5540* Description must start with an uppercase alphabetical character.
5541* Paragraphs must start with an uppercase alphabetical character.
5542* Sentences must end with a period.
5543* Every line in a paragraph (except the first) which starts with an uppercase
5544 character must be preceded by a line ending with a period.
5545* A colon or semi-colon followed by two line breaks is still part of the
5546 containing paragraph (unlike normal dual line breaks).
5547* Text within inline tags `{...}` are not checked for sentence divisions.
5548* Periods after items within the `abbreviations` option array are not treated
5549 as sentence endings.
5550
5551<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-14"></a>
5552#### Options
5553
5554<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-14-tags-2"></a>
5555##### <code>tags</code>
5556
5557If you want additional tags to be checked for their descriptions, you may
5558add them within this option.
5559
5560```js
5561{
5562 'jsdoc/require-description-complete-sentence': ['error', {tags: ['see', 'copyright']}]
5563}
5564```
5565
5566The tags `@param`/`@arg`/`@argument` and `@property`/`@prop` will be properly
5567parsed to ensure that the checked "description" text includes only the text
5568after the name.
5569
5570All other tags will treat the text following the tag name, a space, and
5571an optional curly-bracketed type expression (and another space) as part of
5572its "description" (e.g., for `@returns {someType} some description`, the
5573description is `some description` while for `@some-tag xyz`, the description
5574is `xyz`).
5575
5576<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-14-abbreviations"></a>
5577##### <code>abbreviations</code>
5578
5579You can provide an `abbreviations` options array to avoid such strings of text
5580being treated as sentence endings when followed by dots. The `.` is not
5581necessary at the end of the array items.
5582
5583|||
5584|---|---|
5585|Context|everywhere|
5586|Tags|doc block, `param`, `returns`, `description`, `property`, `summary`, `file`, `classdesc`, `todo`, `deprecated`, `throws`, 'yields' and others added by `tags`|
5587|Aliases|`arg`, `argument`, `return`, `desc`, `prop`, `fileoverview`, `overview`, `exception`, `yield`|
5588|Options|`tags`, `abbreviations`|
5589The following patterns are considered problems:
5590
5591````js
5592/**
5593 * foo.
5594 */
5595function quux () {
5596
5597}
5598// Message: Sentence should start with an uppercase character.
5599
5600/**
5601 * foo?
5602 */
5603function quux () {
5604
5605}
5606// Message: Sentence should start with an uppercase character.
5607
5608/**
5609 * @description foo.
5610 */
5611function quux () {
5612
5613}
5614// Message: Sentence should start with an uppercase character.
5615
5616/**
5617 * Foo)
5618 */
5619function quux () {
5620
5621}
5622// Message: Sentence must end with a period.
5623
5624/**
5625 * `foo` is a variable
5626 */
5627function quux () {
5628
5629}
5630// Message: Sentence must end with a period.
5631
5632/**
5633 * Foo.
5634 *
5635 * foo.
5636 */
5637function quux () {
5638
5639}
5640// Message: Sentence should start with an uppercase character.
5641
5642/**
5643 * тест.
5644 */
5645function quux () {
5646
5647}
5648// Message: Sentence should start with an uppercase character.
5649
5650/**
5651 * Foo
5652 */
5653function quux () {
5654
5655}
5656// Message: Sentence must end with a period.
5657
5658/**
5659 * Foo
5660 * Bar.
5661 */
5662function quux () {
5663
5664}
5665// Message: A line of text is started with an uppercase character, but preceding line does not end the sentence.
5666
5667/**
5668 * Foo.
5669 *
5670 * @param foo foo.
5671 */
5672function quux (foo) {
5673
5674}
5675// Message: Sentence should start with an uppercase character.
5676
5677/**
5678 * Foo.
5679 *
5680 * @param foo bar
5681 */
5682function quux (foo) {
5683
5684}
5685// Message: Sentence should start with an uppercase character.
5686
5687/**
5688 * {@see Foo.bar} buz
5689 */
5690function quux (foo) {
5691
5692}
5693// Message: Sentence should start with an uppercase character.
5694
5695/**
5696 * Foo.
5697 *
5698 * @returns {number} foo
5699 */
5700function quux (foo) {
5701
5702}
5703// Message: Sentence should start with an uppercase character.
5704
5705/**
5706 * Foo.
5707 *
5708 * @returns foo.
5709 */
5710function quux (foo) {
5711
5712}
5713// Message: Sentence should start with an uppercase character.
5714
5715/**
5716 * lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
5717 * iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
5718 * tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
5719 * vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
5720 * proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
5721 * consequat auctor magna. duis pharetra purus in porttitor mollis.
5722 */
5723function longDescription (foo) {
5724
5725}
5726// Message: Sentence should start with an uppercase character.
5727
5728/**
5729 * @arg {number} foo - Foo
5730 */
5731function quux (foo) {
5732
5733}
5734// Message: Sentence must end with a period.
5735
5736/**
5737 * @argument {number} foo - Foo
5738 */
5739function quux (foo) {
5740
5741}
5742// Message: Sentence must end with a period.
5743
5744/**
5745 * @return {number} foo
5746 */
5747function quux (foo) {
5748
5749}
5750// Message: Sentence should start with an uppercase character.
5751
5752/**
5753 * Returns bar.
5754 *
5755 * @return {number} bar
5756 */
5757function quux (foo) {
5758
5759}
5760// Message: Sentence should start with an uppercase character.
5761
5762/**
5763 * @throws {object} Hello World
5764 * hello world
5765*/
5766// Message: Sentence must end with a period.
5767
5768/**
5769 * @summary Foo
5770 */
5771function quux () {
5772
5773}
5774// Message: Sentence must end with a period.
5775
5776/**
5777 * @throws {SomeType} Foo
5778 */
5779function quux () {
5780
5781}
5782// Message: Sentence must end with a period.
5783
5784/**
5785 * @see Foo
5786 */
5787function quux () {
5788
5789}
5790// Options: [{"tags":["see"]}]
5791// Message: Sentence must end with a period.
5792
5793/**
5794 * @param foo Foo bar
5795 */
5796function quux (foo) {
5797
5798}
5799// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
5800// Options: [{"tags":["param"]}]
5801// Message: Sentence must end with a period.
5802
5803/**
5804 * Sorry, but this isn't a complete sentence, Mr.
5805 */
5806function quux () {
5807
5808}
5809// Options: [{"abbreviations":["Mr"]}]
5810// Message: Sentence must end with a period.
5811
5812/**
5813 * Sorry, but this isn't a complete sentence Mr.
5814 */
5815function quux () {
5816
5817}
5818// Options: [{"abbreviations":["Mr."]}]
5819// Message: Sentence must end with a period.
5820
5821/**
5822 * Sorry, but this isn't a complete sentence Mr.
5823 */
5824function quux () {
5825
5826}
5827// Options: [{"abbreviations":["Mr"]}]
5828// Message: Sentence must end with a period.
5829
5830/**
5831 * Sorry, but this isn't a complete sentence Mr. and Mrs.
5832 */
5833function quux () {
5834
5835}
5836// Options: [{"abbreviations":["Mr","Mrs"]}]
5837// Message: Sentence must end with a period.
5838
5839/**
5840 * This is a complete sentence. But this isn't, Mr.
5841 */
5842function quux () {
5843
5844}
5845// Options: [{"abbreviations":["Mr"]}]
5846// Message: Sentence must end with a period.
5847
5848/**
5849 * This is a complete Mr. sentence. But this isn't, Mr.
5850 */
5851function quux () {
5852
5853}
5854// Options: [{"abbreviations":["Mr"]}]
5855// Message: Sentence must end with a period.
5856
5857/**
5858 * This is a complete Mr. sentence.
5859 */
5860function quux () {
5861
5862}
5863// Message: Sentence should start with an uppercase character.
5864
5865/**
5866 * This is fun, i.e. enjoyable, but not superlatively so, e.g. not
5867 * super, wonderful, etc..
5868 */
5869function quux () {
5870
5871}
5872// Message: Sentence should start with an uppercase character.
5873
5874/**
5875 * Do not have dynamic content; e.g. homepage. Here a simple unique id
5876 * suffices.
5877 */
5878 function quux () {
5879
5880 }
5881// Message: Sentence should start with an uppercase character.
5882````
5883
5884The following patterns are not considered problems:
5885
5886````js
5887/**
5888 * @param foo - Foo.
5889 */
5890function quux () {
5891
5892}
5893
5894/**
5895 * Foo.
5896 */
5897function quux () {
5898
5899}
5900
5901/**
5902 * Foo.
5903 * Bar.
5904 */
5905function quux () {
5906
5907}
5908
5909/**
5910 * Foo.
5911 *
5912 * Bar.
5913 */
5914function quux () {
5915
5916}
5917
5918/**
5919 * Тест.
5920 */
5921function quux () {
5922
5923}
5924
5925/**
5926 * Foo
5927 * bar.
5928 */
5929function quux () {
5930
5931}
5932
5933/**
5934 * @returns Foo bar.
5935 */
5936function quux () {
5937
5938}
5939
5940/**
5941 * Foo. {@see Math.sin}.
5942 */
5943function quux () {
5944
5945}
5946
5947/**
5948 * Foo {@see Math.sin} bar.
5949 */
5950function quux () {
5951
5952}
5953
5954/**
5955 * Foo?
5956 *
5957 * Bar!
5958 *
5959 * Baz:
5960 * 1. Foo.
5961 * 2. Bar.
5962 */
5963function quux () {
5964
5965}
5966
5967/**
5968 * Hello:
5969 * World.
5970 */
5971function quux () {
5972
5973}
5974
5975/**
5976 * Hello: world.
5977 */
5978function quux () {
5979
5980}
5981
5982/**
5983 *
5984 */
5985function quux () {
5986
5987}
5988
5989/**
5990 * @description Foo.
5991 */
5992function quux () {
5993
5994}
5995
5996/**
5997 * `foo` is a variable.
5998 */
5999function quux () {
6000
6001}
6002
6003/**
6004 * Foo.
6005 *
6006 * `foo`.
6007 */
6008function quux () {
6009
6010}
6011
6012/**
6013 * @param foo - `bar`.
6014 */
6015function quux () {
6016
6017}
6018
6019/**
6020 * @returns {number} `foo`.
6021 */
6022function quux () {
6023
6024}
6025
6026/**
6027 * Foo
6028 * `bar`.
6029 */
6030function quux () {
6031
6032}
6033
6034/**
6035 * @example Foo
6036 */
6037function quux () {
6038
6039}
6040
6041/**
6042 * @see Foo
6043 */
6044function quux () {
6045
6046}
6047
6048/**
6049 * Foo.
6050 *
6051 * @param foo Foo.
6052 */
6053function quux (foo) {
6054
6055}
6056
6057/**
6058 * Foo.
6059 *
6060 * @param foo Foo.
6061 */
6062function quux (foo) {
6063
6064}
6065// Options: [{"tags":["param"]}]
6066
6067/**
6068 * @param foo Foo bar.
6069 */
6070function quux (foo) {
6071
6072}
6073// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6074// Options: [{"tags":["param"]}]
6075
6076/**
6077 *
6078 */
6079function quux (foo) {
6080
6081}
6082// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6083
6084/**
6085* We stop loading Items when we have loaded:
6086*
6087* 1) The main Item;
6088* 2) All its variants.
6089*/
6090
6091/**
6092 * This method is working on 2 steps.
6093 *
6094 * | Step | Comment |
6095 * |------|-------------|
6096 * | 1 | do it |
6097 * | 2 | do it again |
6098 */
6099
6100/**
6101 * This is something that
6102 * I want to test.
6103 */
6104function quux () {
6105
6106}
6107
6108/**
6109 * When making HTTP requests, the
6110 * URL is super important.
6111 */
6112function quux () {
6113
6114}
6115
6116/**
6117 * Sorry, but this isn't a complete sentence, Mr.
6118 */
6119function quux () {
6120
6121}
6122
6123/**
6124 * Sorry, but this isn't a complete sentence Mr..
6125 */
6126function quux () {
6127
6128}
6129// Options: [{"abbreviations":["Mr."]}]
6130
6131/**
6132 * Sorry, but this isn't a complete sentence Mr.
6133 */
6134function quux () {
6135
6136}
6137
6138/**
6139 * Sorry, but this isn't a complete sentence Mr. and Mrs..
6140 */
6141function quux () {
6142
6143}
6144// Options: [{"abbreviations":["Mr","Mrs"]}]
6145
6146/**
6147 * This is a complete sentence aMr.
6148 */
6149function quux () {
6150
6151}
6152// Options: [{"abbreviations":["Mr"]}]
6153
6154/**
6155 * This is a complete sentence. But this isn't, Mr.
6156 */
6157function quux () {
6158
6159}
6160
6161/**
6162 * This is a complete Mr. Sentence. But this isn't, Mr.
6163 */
6164function quux () {
6165
6166}
6167
6168/**
6169 * This is a complete Mr. sentence.
6170 */
6171function quux () {
6172
6173}
6174// Options: [{"abbreviations":["Mr"]}]
6175
6176/**
6177 * This is fun, i.e. enjoyable, but not superlatively so, e.g. not
6178 * super, wonderful, etc..
6179 */
6180function quux () {
6181
6182}
6183// Options: [{"abbreviations":["etc","e.g.","i.e."]}]
6184
6185
6186**
6187* Do not have dynamic content; e.g. homepage. Here a simple unique id
6188* suffices.
6189*/
6190function quux () {
6191
6192}
6193// Options: [{"abbreviations":["etc","e.g.","i.e."]}]
6194````
6195
6196
6197<a name="eslint-plugin-jsdoc-rules-require-description"></a>
6198### <code>require-description</code>
6199
6200Requires that all functions have a description.
6201
6202* All functions must have an implicit description or have the option
6203 `descriptionStyle` set to `tag`.
6204* Every jsdoc block description (or description tag if `descriptionStyle` is
6205 `"tag"`) must have a non-empty description that explains the purpose of the
6206 method.
6207
6208<a name="eslint-plugin-jsdoc-rules-require-description-options-15"></a>
6209#### Options
6210
6211An options object may have any of the following properties:
6212
6213- `contexts` - Set to an array of strings representing the AST context
6214 where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6
6215 classes). Overrides the default contexts (see below). Set to `"any"` if
6216 you want the rule to apply to any jsdoc block throughout your files.
6217- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
6218 document block avoids the need for a `@description`. Defaults to an
6219 empty array.
6220- `descriptionStyle` - Whether to accept implicit descriptions (`"body"`) or
6221 `@description` tags (`"tag"`) as satisfying the rule. Set to `"any"` to
6222 accept either style. Defaults to `"body"`.
6223
6224|||
6225|---|---|
6226|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6227|Tags|`description` or jsdoc block|
6228|Aliases|`desc`|
6229|Options|`contexts`, `exemptedBy`, `descriptionStyle`|
6230|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
6231
6232The following patterns are considered problems:
6233
6234````js
6235/**
6236 *
6237 */
6238function quux () {
6239
6240}
6241// Options: [{"descriptionStyle":"tag"}]
6242// Message: Missing JSDoc @description declaration.
6243
6244/**
6245 *
6246 */
6247function quux () {
6248
6249}
6250// Options: [{"descriptionStyle":"any"}]
6251// Message: Missing JSDoc block description or @description declaration.
6252
6253/**
6254 *
6255 */
6256function quux () {
6257
6258}
6259// Options: [{"descriptionStyle":"body"}]
6260// Message: Missing JSDoc block description.
6261
6262/**
6263 *
6264 */
6265class quux {
6266
6267}
6268// Options: [{"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
6269// Message: Missing JSDoc @description declaration.
6270
6271/**
6272 *
6273 */
6274// Options: [{"contexts":["any"],"descriptionStyle":"tag"}]
6275// Message: Missing JSDoc @description declaration.
6276
6277/**
6278 *
6279 */
6280class quux {
6281
6282}
6283// Options: [{"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
6284// Message: Missing JSDoc @description declaration.
6285
6286/**
6287 *
6288 */
6289class quux {
6290
6291}
6292// Options: [{"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
6293// Message: Missing JSDoc @description declaration.
6294
6295/**
6296 * @description
6297 */
6298function quux () {
6299
6300}
6301// Options: [{"descriptionStyle":"tag"}]
6302// Message: Missing JSDoc @description description.
6303
6304/**
6305 *
6306 */
6307interface quux {
6308
6309}
6310// Options: [{"contexts":["TSInterfaceDeclaration"],"descriptionStyle":"tag"}]
6311// Message: Missing JSDoc @description declaration.
6312
6313/**
6314 *
6315 */
6316var quux = class {
6317
6318};
6319// Options: [{"contexts":["ClassExpression"],"descriptionStyle":"tag"}]
6320// Message: Missing JSDoc @description declaration.
6321
6322/**
6323 *
6324 */
6325var quux = {
6326
6327};
6328// Options: [{"contexts":["ObjectExpression"],"descriptionStyle":"tag"}]
6329// Message: Missing JSDoc @description declaration.
6330
6331/**
6332 * @someDesc
6333 */
6334function quux () {
6335
6336}
6337// Settings: {"jsdoc":{"tagNamePreference":{"description":{"message":"Please avoid `{{tagName}}`; use `{{replacement}}` instead","replacement":"someDesc"}}}}
6338// Options: [{"descriptionStyle":"tag"}]
6339// Message: Missing JSDoc @someDesc description.
6340
6341/**
6342 * @description
6343 */
6344function quux () {
6345
6346}
6347// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6348// Options: [{"descriptionStyle":"tag"}]
6349// Message: Unexpected tag `@description`
6350
6351/**
6352 * @description
6353 */
6354function quux () {
6355
6356}
6357// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6358// Options: [{"descriptionStyle":"any"}]
6359// Message: Missing JSDoc block description or @description declaration.
6360
6361/**
6362 *
6363 */
6364function quux () {
6365}
6366// Options: [{"exemptedBy":["notPresent"]}]
6367// Message: Missing JSDoc block description.
6368````
6369
6370The following patterns are not considered problems:
6371
6372````js
6373/**
6374 *
6375 */
6376
6377/**
6378 * @description
6379 * // arbitrary description content
6380 */
6381function quux () {
6382
6383}
6384// Options: [{"descriptionStyle":"tag"}]
6385
6386/**
6387 * @description
6388 * quux(); // does something useful
6389 */
6390function quux () {
6391
6392}
6393// Options: [{"descriptionStyle":"tag"}]
6394
6395/**
6396 * @description <caption>Valid usage</caption>
6397 * quux(); // does something useful
6398 *
6399 * @description <caption>Invalid usage</caption>
6400 * quux('random unwanted arg'); // results in an error
6401 */
6402function quux () {
6403
6404}
6405// Options: [{"descriptionStyle":"tag"}]
6406
6407/**
6408 *
6409 */
6410class quux {
6411
6412}
6413// Options: [{"descriptionStyle":"tag"}]
6414
6415/**
6416 *
6417 */
6418function quux () {
6419
6420}
6421// Options: [{"contexts":["ClassDeclaration"]}]
6422
6423/**
6424 * @type {MyCallback}
6425 */
6426function quux () {
6427
6428}
6429// Options: [{"exemptedBy":["type"]}]
6430
6431/**
6432 *
6433 */
6434interface quux {
6435
6436}
6437// Options: [{"descriptionStyle":"tag"}]
6438
6439/**
6440 *
6441 */
6442var quux = class {
6443
6444};
6445// Options: [{"descriptionStyle":"tag"}]
6446
6447/**
6448 *
6449 */
6450var quux = {
6451
6452};
6453// Options: [{"descriptionStyle":"tag"}]
6454
6455/**
6456 * Has an implicit description
6457 */
6458function quux () {
6459
6460}
6461// Options: [{"descriptionStyle":"body"}]
6462
6463/**
6464 * Has an implicit description
6465 */
6466function quux () {
6467
6468}
6469
6470/**
6471 * Has an implicit description
6472 */
6473function quux () {
6474
6475}
6476// Options: [{"descriptionStyle":"any"}]
6477
6478/**
6479 * @description Has an explicit description
6480 */
6481function quux () {
6482
6483}
6484// Options: [{"descriptionStyle":"any"}]
6485
6486/**
6487 *
6488 */
6489function quux () {
6490
6491}
6492// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6493````
6494
6495
6496<a name="eslint-plugin-jsdoc-rules-require-example"></a>
6497### <code>require-example</code>
6498
6499Requires that all functions have examples.
6500
6501* All functions must have one or more `@example` tags.
6502* Every example tag must have a non-empty description that explains the method's usage.
6503
6504<a name="eslint-plugin-jsdoc-rules-require-example-options-16"></a>
6505#### Options
6506
6507This rule has an object option.
6508
6509<a name="eslint-plugin-jsdoc-rules-require-example-options-16-exemptedby"></a>
6510##### <code>exemptedBy</code>
6511
6512Array of tags (e.g., `['type']`) whose presence on the document
6513block avoids the need for an `@example`. Defaults to an empty array.
6514
6515<a name="eslint-plugin-jsdoc-rules-require-example-options-16-avoidexampleonconstructors"></a>
6516##### <code>avoidExampleOnConstructors</code>
6517
6518Set to `true` to avoid the need for an example on a constructor (whether
6519indicated as such by a jsdoc tag or by being within an ES6 `class`).
6520Defaults to `false`.
6521
6522<a name="eslint-plugin-jsdoc-rules-require-example-options-16-contexts-3"></a>
6523##### <code>contexts</code>
6524
6525Set this to an array of strings representing the AST context
6526where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6 classes).
6527Overrides the default contexts (see below). Set to `"any"` if you want
6528the rule to apply to any jsdoc block throughout your files.
6529
6530<a name="eslint-plugin-jsdoc-rules-require-example-fixer"></a>
6531#### Fixer
6532
6533The fixer for `require-example` will add an empty `@example`, but it will still
6534report a missing example description after this is added.
6535
6536|||
6537|---|---|
6538|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6539|Tags|`example`|
6540|Options|`exemptedBy`, `avoidExampleOnConstructors`, `contexts`|
6541|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
6542
6543The following patterns are considered problems:
6544
6545````js
6546/**
6547 *
6548 */
6549function quux () {
6550
6551}
6552// Message: Missing JSDoc @example declaration.
6553
6554/**
6555 * @example
6556 */
6557function quux () {
6558
6559}
6560// Message: Missing JSDoc @example description.
6561
6562/**
6563 * @constructor
6564 */
6565function f () {
6566
6567}
6568// Settings: {"jsdoc":{"avoidExampleOnConstructors":true}}
6569// Message: `settings.jsdoc.avoidExampleOnConstructors` has been removed, use options in the rule `require-example` instead.
6570
6571/**
6572 * @constructor
6573 */
6574function quux () {
6575
6576}
6577// Message: Missing JSDoc @example declaration.
6578
6579/**
6580 * @constructor
6581 * @example
6582 */
6583function quux () {
6584
6585}
6586// Message: Missing JSDoc @example description.
6587
6588/**
6589 *
6590 */
6591class quux {
6592
6593}
6594// Options: [{"contexts":["ClassDeclaration"]}]
6595// Message: Missing JSDoc @example declaration.
6596
6597/**
6598 *
6599 */
6600// Options: [{"contexts":["any"]}]
6601// Message: Missing JSDoc @example declaration.
6602
6603/**
6604 *
6605 */
6606function quux () {
6607}
6608// Options: [{"exemptedBy":["notPresent"]}]
6609// Message: Missing JSDoc @example declaration.
6610````
6611
6612The following patterns are not considered problems:
6613
6614````js
6615/**
6616 *
6617 */
6618
6619/**
6620 * @example
6621 * // arbitrary example content
6622 */
6623function quux () {
6624
6625}
6626
6627/**
6628 * @example
6629 * quux(); // does something useful
6630 */
6631function quux () {
6632
6633}
6634
6635/**
6636 * @example <caption>Valid usage</caption>
6637 * quux(); // does something useful
6638 *
6639 * @example <caption>Invalid usage</caption>
6640 * quux('random unwanted arg'); // results in an error
6641 */
6642function quux () {
6643
6644}
6645
6646/**
6647 * @constructor
6648 */
6649function quux () {
6650
6651}
6652// Options: [{"avoidExampleOnConstructors":true}]
6653
6654/**
6655 * @constructor
6656 * @example
6657 */
6658function quux () {
6659
6660}
6661// Options: [{"avoidExampleOnConstructors":true}]
6662
6663class Foo {
6664 /**
6665 *
6666 */
6667 constructor () {
6668
6669 }
6670}
6671// Options: [{"avoidExampleOnConstructors":true}]
6672
6673/**
6674 * @inheritdoc
6675 */
6676function quux () {
6677
6678}
6679
6680/**
6681 * @type {MyCallback}
6682 */
6683function quux () {
6684
6685}
6686// Options: [{"exemptedBy":["type"]}]
6687
6688/**
6689 * @example Some example code
6690 */
6691class quux {
6692
6693}
6694// Options: [{"contexts":["ClassDeclaration"]}]
6695
6696/**
6697 *
6698 */
6699function quux () {
6700
6701}
6702// Options: [{"contexts":["ClassDeclaration"]}]
6703````
6704
6705
6706<a name="eslint-plugin-jsdoc-rules-require-file-overview"></a>
6707### <code>require-file-overview</code>
6708
6709Checks that:
6710
67111. All files have a `@file`, `@fileoverview`, or `@overview` tag.
67122. Duplicate file overview tags within a given file will be reported
67133. File overview tags will be reported which are not, as per
6714 [the docs](https://jsdoc.app/tags-file.html), "at the beginning of
6715 the file"–where beginning of the file is interpreted in this rule
6716 as being when the overview tag is not preceded by anything other than
6717 a comment.
6718
6719<a name="eslint-plugin-jsdoc-rules-require-file-overview-options-17"></a>
6720#### Options
6721
6722<a name="eslint-plugin-jsdoc-rules-require-file-overview-options-17-tags-3"></a>
6723##### <code>tags</code>
6724
6725The keys of this object are tag names, and the values are configuration
6726objects indicating what will be checked for these whole-file tags.
6727
6728Each configuration object has the following boolean keys (which default
6729to `false` when this option is supplied): `mustExist`, `preventDuplicates`,
6730`initialCommentsOnly`. These correspond to the three items above.
6731
6732When no `tags` is present, the default is:
6733
6734```json
6735{
6736 "file": {
6737 "initialCommentsOnly": true,
6738 "mustExist": true,
6739 "preventDuplicates": true,
6740 }
6741}
6742```
6743
6744You can add additional tag names and/or override `file` if you supply this
6745option, e.g., in place of or in addition to `file`, giving other potential
6746file global tags like `@license`, `@copyright`, `@author`, `@module` or
6747`@exports`, optionally restricting them to a single use or preventing them
6748from being preceded by anything besides comments.
6749
6750For example:
6751
6752```js
6753{
6754 "license": {
6755 "mustExist": true,
6756 "preventDuplicates": true,
6757 }
6758}
6759```
6760
6761This would require one and only one `@license` in the file, though because
6762`initialCommentsOnly` is absent and defaults to `false`, the `@license`
6763can be anywhere.
6764
6765In the case of `@license`, you can use this rule along with the
6766`check-values` rule (with its `allowedLicenses` or `licensePattern` options),
6767to enforce a license whitelist be present on every JS file.
6768
6769Note that if you choose to use `preventDuplicates` with `license`, you still
6770have a way to allow multiple licenses for the whole page by using the SPDX
6771"AND" expression, e.g., `@license (MIT AND GPL-3.0)`.
6772
6773Note that the tag names are the main jsdoc tag name, so you should use `file`
6774in this configuration object regardless of whether you have configured
6775`fileoverview` instead of `file` on `tagNamePreference` (i.e., `fileoverview`
6776will be checked, but you must use `file` on the configuration object).
6777
6778|||
6779|---|---|
6780|Context|Everywhere|
6781|Tags|`file`; others when `tags` set|
6782|Aliases|`fileoverview`, `overview`|
6783|Options|`tags`|
6784
6785The following patterns are considered problems:
6786
6787````js
6788
6789// Message: Missing @file
6790
6791
6792// Options: [{"tags":{"file":{"initialCommentsOnly":true,"mustExist":true,"preventDuplicates":true}}}]
6793// Message: Missing @file
6794
6795
6796// Options: [{"tags":{"file":{"mustExist":true}}}]
6797// Message: Missing @file
6798
6799
6800// Options: [{"tags":{"author":{"initialCommentsOnly":false,"mustExist":true,"preventDuplicates":false}}}]
6801// Message: Missing @author
6802
6803/**
6804 *
6805 */
6806// Message: Missing @file
6807
6808/**
6809 *
6810 */
6811function quux () {}
6812// Message: Missing @file
6813
6814/**
6815 *
6816 */
6817function quux () {}
6818// Settings: {"jsdoc":{"tagNamePreference":{"file":"fileoverview"}}}
6819// Message: Missing @fileoverview
6820
6821/**
6822 *
6823 */
6824function quux () {}
6825// Settings: {"jsdoc":{"tagNamePreference":{"file":"overview"}}}
6826// Message: Missing @overview
6827
6828/**
6829 *
6830 */
6831function quux () {}
6832// Settings: {"jsdoc":{"tagNamePreference":{"file":false}}}
6833// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
6834
6835/**
6836 *
6837 */
6838function quux () {}
6839// Settings: {"jsdoc":{"tagNamePreference":{"file":false}}}
6840// Options: [{"tags":{"file":{"initialCommentsOnly":false,"mustExist":true,"preventDuplicates":false}}}]
6841// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
6842
6843/**
6844 *
6845 */
6846function quux () {}
6847// Settings: {"jsdoc":{"tagNamePreference":{"file":{"message":"Don't use file"}}}}
6848// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
6849
6850/**
6851 * @param a
6852 */
6853function quux (a) {}
6854// Message: Missing @file
6855
6856/**
6857 * @param a
6858 */
6859function quux (a) {}
6860
6861/**
6862 * @param b
6863 */
6864function bar (b) {}
6865// Message: Missing @file
6866
6867/**
6868 * @file
6869 */
6870
6871 /**
6872 * @file
6873 */
6874// Message: Duplicate @file
6875
6876/**
6877 * @copyright
6878 */
6879
6880 /**
6881 * @copyright
6882 */
6883// Options: [{"tags":{"copyright":{"initialCommentsOnly":false,"mustExist":false,"preventDuplicates":true}}}]
6884// Message: Duplicate @copyright
6885
6886function quux () {
6887}
6888/**
6889 * @file
6890 */
6891// Message: @file should be at the beginning of the file
6892
6893function quux () {
6894}
6895/**
6896 * @license
6897 */
6898// Options: [{"tags":{"license":{"initialCommentsOnly":true,"mustExist":false,"preventDuplicates":false}}}]
6899// Message: @license should be at the beginning of the file
6900
6901function quux () {
6902}
6903/**
6904 * @license
6905 */
6906// Options: [{"tags":{"license":{"initialCommentsOnly":true}}}]
6907// Message: @license should be at the beginning of the file
6908
6909/**
6910 * @file
6911 */
6912
6913/**
6914 * @file
6915 */
6916// Options: [{"tags":{"file":{"initialCommentsOnly":true,"preventDuplicates":true}}}]
6917// Message: Duplicate @file
6918````
6919
6920The following patterns are not considered problems:
6921
6922````js
6923/**
6924 * @file
6925 */
6926
6927/**
6928 * @file
6929 */
6930
6931/**
6932 * @file
6933 */
6934// Options: [{"tags":{"license":{"initialCommentsOnly":true,"preventDuplicates":true}}}]
6935
6936// Ok preceded by comment
6937/**
6938 * @file
6939 */
6940
6941/**
6942 * @fileoverview
6943 */
6944// Settings: {"jsdoc":{"tagNamePreference":{"file":"fileoverview"}}}
6945
6946/**
6947 * @overview
6948 */
6949// Settings: {"jsdoc":{"tagNamePreference":{"file":"overview"}}}
6950
6951/**
6952 * @file Description of file
6953 */
6954
6955/**
6956 * @file Description of file
6957 */
6958function quux () {
6959}
6960
6961/**
6962 *
6963 */
6964
6965function quux () {
6966}
6967/**
6968 *
6969 */
6970// Options: [{"tags":{"license":{"initialCommentsOnly":true,"mustExist":false,"preventDuplicates":false}}}]
6971
6972function quux () {
6973}
6974/**
6975 *
6976 */
6977// Options: [{"tags":{"license":{"initialCommentsOnly":false,"mustExist":false,"preventDuplicates":false}}}]
6978
6979function quux () {
6980}
6981/**
6982 *
6983 */
6984// Options: [{"tags":{"license":{"initialCommentsOnly":false,"mustExist":false,"preventDuplicates":true}}}]
6985
6986/**
6987 * @license MIT
6988 */
6989
6990 var a
6991
6992 /**
6993 * @type {Array}
6994 */
6995// Options: [{"tags":{"license":{"initialCommentsOnly":true,"mustExist":false,"preventDuplicates":false}}}]
6996````
6997
6998
6999<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description"></a>
7000### <code>require-hyphen-before-param-description</code>
7001
7002Requires a hyphen before the `@param` description.
7003
7004<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-18"></a>
7005#### Options
7006
7007This rule takes one optional string argument. If it is `"always"` then a problem is raised when there is no hyphen before the description. If it is `"never"` then a problem is raised when there is a hyphen before the description. The default value is `"always"`.
7008
7009|||
7010|---|---|
7011|Context|everywhere|
7012|Tags|`param`|
7013|Aliases|`arg`, `argument`|
7014|Options|(a string matching `"always"|"never"`)|
7015
7016The following patterns are considered problems:
7017
7018````js
7019/**
7020 * @param foo Foo.
7021 */
7022function quux () {
7023
7024}
7025// Options: ["always"]
7026// Message: There must be a hyphen before @param description.
7027
7028/**
7029 * @param foo Foo.
7030 */
7031function quux () {
7032
7033}
7034// Message: There must be a hyphen before @param description.
7035
7036/**
7037 * @param foo - Foo.
7038 */
7039function quux () {
7040
7041}
7042// Options: ["never"]
7043// Message: There must be no hyphen before @param description.
7044
7045/**
7046 * @param foo - foo
7047 * @param foo foo
7048 */
7049function quux () {
7050
7051}
7052// Options: ["always"]
7053// Message: There must be a hyphen before @param description.
7054
7055/**
7056 * @param foo foo
7057 * bar
7058 * @param bar - bar
7059 */
7060function quux () {
7061
7062}
7063// Options: ["always"]
7064// Message: There must be a hyphen before @param description.
7065
7066/**
7067 * @param foo
7068 */
7069function quux (foo) {
7070
7071}
7072// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
7073// Message: Unexpected tag `@param`
7074````
7075
7076The following patterns are not considered problems:
7077
7078````js
7079/**
7080 * @param foo - Foo.
7081 */
7082function quux () {
7083
7084}
7085// Options: ["always"]
7086
7087/**
7088 * @param foo Foo.
7089 */
7090function quux () {
7091
7092}
7093// Options: ["never"]
7094
7095/**
7096 * @param foo
7097 */
7098function quux () {
7099
7100}
7101````
7102
7103
7104<a name="eslint-plugin-jsdoc-rules-require-jsdoc"></a>
7105### <code>require-jsdoc</code>
7106
7107Checks for presence of jsdoc comments, on class declarations as well as
7108functions.
7109
7110<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-19"></a>
7111#### Options
7112
7113Accepts one optional options object with the following optional keys.
7114
7115- `publicOnly` - This option will insist that missing jsdoc blocks are
7116 only reported for function bodies / class declarations that are exported
7117 from the module. May be a boolean or object. If set to `true`, the defaults
7118 below will be used. If unset, jsdoc block reporting will not be limited to
7119 exports.
7120
7121 This object supports the following optional boolean keys (`false` unless
7122 otherwise noted):
7123
7124 - `ancestorsOnly` - Only check node ancestors to check if node is exported
7125 - `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
7126 - `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
7127 - `window` - Window global exports are checked for JSDoc comments
7128
7129- `require` - An object with the following optional boolean keys which all
7130 default to `false` except as noted, indicating the contexts where the rule
7131 will apply:
7132
7133 - `ArrowFunctionExpression`
7134 - `ClassDeclaration`
7135 - `ClassExpression`
7136 - `FunctionDeclaration` (defaults to `true`)
7137 - `FunctionExpression`
7138 - `MethodDefinition`
7139
7140- `contexts` - Set this to an array of strings representing the additional
7141 AST contexts where you wish the rule to be applied (e.g., `Property` for
7142 properties). Defaults to an empty array.
7143
7144- `exemptEmptyFunctions` (default: false) - When `true`, the rule will not report
7145 missing jsdoc blocks above functions/methods with no parameters or return values
7146 (intended where variable names are sufficient for themselves as documentation).
7147
7148|||
7149|---|---|
7150|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
7151|Tags|N/A|
7152|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyFunctions`|
7153
7154The following patterns are considered problems:
7155
7156````js
7157/**
7158 * @func myFunction
7159 */
7160function myFunction() {
7161
7162}
7163// Settings: {"jsdoc":{"maxLines":3,"minLines":2}}
7164// Message: Missing JSDoc comment.
7165
7166/**
7167 * @func myFunction
7168 */
7169
7170
7171function myFunction() {
7172
7173}
7174// Settings: {"jsdoc":{"maxLines":2}}
7175// Message: Missing JSDoc comment.
7176
7177/** @func myFunction */ function myFunction() {
7178
7179}
7180// Settings: {"jsdoc":{"minLines":1}}
7181// Message: Missing JSDoc comment.
7182
7183export var test = function () {
7184
7185};
7186// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7187// Message: Missing JSDoc comment.
7188
7189function test () {
7190
7191}
7192export var test2 = test;
7193// Options: [{"publicOnly":true,"require":{"FunctionDeclaration":true}}]
7194// Message: Missing JSDoc comment.
7195
7196export const test = () => {
7197
7198};
7199// Options: [{"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
7200// Message: Missing JSDoc comment.
7201
7202export let test = class {
7203
7204};
7205// Options: [{"publicOnly":true,"require":{"ClassExpression":true}}]
7206// Message: Missing JSDoc comment.
7207
7208export default function () {}
7209// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
7210// Message: Missing JSDoc comment.
7211
7212export default () => {}
7213// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"ArrowFunctionExpression":true}}]
7214// Message: Missing JSDoc comment.
7215
7216export default (function () {})
7217// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
7218// Message: Missing JSDoc comment.
7219
7220export default class {}
7221// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"ClassDeclaration":true}}]
7222// Message: Missing JSDoc comment.
7223
7224function quux (foo) {
7225
7226}
7227// Message: Missing JSDoc comment.
7228
7229
7230// Settings: {"jsdoc":{"exemptEmptyFunctions":true}}
7231// Message: `settings.jsdoc.exemptEmptyFunctions` has been removed, use options in the rule `require-jsdoc` instead.
7232
7233function quux (foo) {
7234
7235}
7236// Options: [{"exemptEmptyFunctions":true}]
7237// Message: Missing JSDoc comment.
7238
7239function quux (foo) {
7240
7241}
7242// Settings: {"jsdoc":{"minLines":2}}
7243// Options: [{"exemptEmptyFunctions":true}]
7244// Message: Missing JSDoc comment.
7245
7246function myFunction() {}
7247// Message: Missing JSDoc comment.
7248
7249/**
7250 * Description for A.
7251 */
7252class A {
7253 constructor(xs) {
7254 this.a = xs;
7255 }
7256}
7257// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7258// Message: Missing JSDoc comment.
7259
7260class A {
7261 /**
7262 * Description for constructor.
7263 * @param {object[]} xs - xs
7264 */
7265 constructor(xs) {
7266 this.a = xs;
7267 }
7268}
7269// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7270// Message: Missing JSDoc comment.
7271
7272class A extends B {
7273 /**
7274 * Description for constructor.
7275 * @param {object[]} xs - xs
7276 */
7277 constructor(xs) {
7278 this.a = xs;
7279 }
7280}
7281// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7282// Message: Missing JSDoc comment.
7283
7284export class A extends B {
7285 /**
7286 * Description for constructor.
7287 * @param {object[]} xs - xs
7288 */
7289 constructor(xs) {
7290 this.a = xs;
7291 }
7292}
7293// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7294// Message: Missing JSDoc comment.
7295
7296export default class A extends B {
7297 /**
7298 * Description for constructor.
7299 * @param {object[]} xs - xs
7300 */
7301 constructor(xs) {
7302 this.a = xs;
7303 }
7304}
7305// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7306// Message: Missing JSDoc comment.
7307
7308var myFunction = () => {}
7309// Options: [{"require":{"ArrowFunctionExpression":true}}]
7310// Message: Missing JSDoc comment.
7311
7312var myFunction = () => () => {}
7313// Options: [{"require":{"ArrowFunctionExpression":true}}]
7314// Message: Missing JSDoc comment.
7315
7316var foo = function() {}
7317// Options: [{"require":{"FunctionExpression":true}}]
7318// Message: Missing JSDoc comment.
7319
7320const foo = {bar() {}}
7321// Options: [{"require":{"FunctionExpression":true}}]
7322// Message: Missing JSDoc comment.
7323
7324var foo = {bar: function() {}}
7325// Options: [{"require":{"FunctionExpression":true}}]
7326// Message: Missing JSDoc comment.
7327
7328function foo (abc) {}
7329// Options: [{"exemptEmptyFunctions":false}]
7330// Message: Missing JSDoc comment.
7331
7332function foo () {
7333 return true;
7334}
7335// Options: [{"exemptEmptyFunctions":false}]
7336// Message: Missing JSDoc comment.
7337
7338module.exports = function quux () {
7339
7340}
7341// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7342// Message: Missing JSDoc comment.
7343
7344module.exports = function quux () {
7345
7346}
7347// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7348// Message: Missing JSDoc comment.
7349
7350module.exports = {
7351 method: function() {
7352
7353 }
7354}
7355// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7356// Message: Missing JSDoc comment.
7357
7358module.exports = {
7359 test: {
7360 test2: function() {
7361
7362 }
7363 }
7364}
7365// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7366// Message: Missing JSDoc comment.
7367
7368module.exports = {
7369 test: {
7370 test2: function() {
7371
7372 }
7373 }
7374}
7375// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7376// Message: Missing JSDoc comment.
7377
7378const test = module.exports = function () {
7379
7380}
7381// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7382// Message: Missing JSDoc comment.
7383
7384/**
7385*
7386*/
7387const test = module.exports = function () {
7388
7389}
7390
7391test.prototype.method = function() {}
7392// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7393// Message: Missing JSDoc comment.
7394
7395const test = function () {
7396
7397}
7398module.exports = {
7399 test: test
7400}
7401// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7402// Message: Missing JSDoc comment.
7403
7404const test = () => {
7405
7406}
7407module.exports = {
7408 test: test
7409}
7410// Options: [{"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
7411// Message: Missing JSDoc comment.
7412
7413class Test {
7414 method() {
7415
7416 }
7417}
7418module.exports = Test;
7419// Options: [{"publicOnly":true,"require":{"MethodDefinition":true}}]
7420// Message: Missing JSDoc comment.
7421
7422export default function quux () {
7423
7424}
7425// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7426// Message: Missing JSDoc comment.
7427
7428export default function quux () {
7429
7430}
7431// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7432// Message: Missing JSDoc comment.
7433
7434function quux () {
7435
7436}
7437export default quux;
7438// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7439// Message: Missing JSDoc comment.
7440
7441export function test() {
7442
7443}
7444// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7445// Message: Missing JSDoc comment.
7446
7447export function test() {
7448
7449}
7450// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7451// Message: Missing JSDoc comment.
7452
7453var test = function () {
7454
7455}
7456var test2 = 2;
7457export { test, test2 }
7458// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7459// Message: Missing JSDoc comment.
7460
7461var test = function () {
7462
7463}
7464export { test as test2 }
7465// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7466// Message: Missing JSDoc comment.
7467
7468export default class A {
7469
7470}
7471// Options: [{"publicOnly":true,"require":{"ClassDeclaration":true}}]
7472// Message: Missing JSDoc comment.
7473
7474export default class A {
7475
7476}
7477// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true}}]
7478// Message: Missing JSDoc comment.
7479
7480var test = function () {
7481
7482}
7483// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7484// Message: Missing JSDoc comment.
7485
7486window.test = function () {
7487
7488}
7489// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7490// Message: Missing JSDoc comment.
7491
7492function test () {
7493
7494}
7495// Options: [{"publicOnly":{"window":true}}]
7496// Message: Missing JSDoc comment.
7497
7498module.exports = function() {
7499
7500}
7501// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionExpression":true}}]
7502// Message: Missing JSDoc comment.
7503
7504export function someMethod() {
7505
7506}
7507// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
7508// Message: Missing JSDoc comment.
7509
7510export function someMethod() {
7511
7512}
7513// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
7514// Message: Missing JSDoc comment.
7515
7516const myObject = {
7517 myProp: true
7518};
7519// Options: [{"contexts":["Property"]}]
7520// Message: Missing JSDoc comment.
7521````
7522
7523The following patterns are not considered problems:
7524
7525````js
7526/**
7527 *
7528 */
7529
7530var array = [1,2,3];
7531array.forEach(function() {});
7532
7533/**
7534 * @class MyClass
7535 **/
7536function MyClass() {}
7537
7538/**
7539 Function doing something
7540 */
7541function myFunction() {}
7542/**
7543 Function doing something
7544 */
7545var myFunction = function() {};
7546/**
7547 Function doing something
7548 */
7549Object.myFunction = function () {};
7550var obj = {
7551 /**
7552 * Function doing something
7553 **/
7554 myFunction: function () {} };
7555
7556/**
7557 @func myFunction
7558 */
7559function myFunction() {}
7560/**
7561 @method myFunction
7562 */
7563function myFunction() {}
7564/**
7565 @function myFunction
7566 */
7567function myFunction() {}
7568
7569/**
7570 @func myFunction
7571 */
7572var myFunction = function () {}
7573/**
7574 @method myFunction
7575 */
7576var myFunction = function () {}
7577/**
7578 @function myFunction
7579 */
7580var myFunction = function () {}
7581
7582/**
7583 @func myFunction
7584 */
7585Object.myFunction = function() {}
7586/**
7587 @method myFunction
7588 */
7589Object.myFunction = function() {}
7590/**
7591 @function myFunction
7592 */
7593Object.myFunction = function() {}
7594(function(){})();
7595
7596var object = {
7597 /**
7598 * @func myFunction - Some function
7599 */
7600 myFunction: function() {} }
7601var object = {
7602 /**
7603 * @method myFunction - Some function
7604 */
7605 myFunction: function() {} }
7606var object = {
7607 /**
7608 * @function myFunction - Some function
7609 */
7610 myFunction: function() {} }
7611
7612var array = [1,2,3];
7613array.filter(function() {});
7614Object.keys(this.options.rules || {}).forEach(function(name) {}.bind(this));
7615var object = { name: 'key'};
7616Object.keys(object).forEach(function() {})
7617
7618/**
7619 * @func myFunction
7620 */
7621
7622function myFunction() {
7623
7624}
7625// Settings: {"jsdoc":{"maxLines":2,"minLines":0}}
7626
7627/**
7628 * @func myFunction
7629 */
7630
7631
7632function myFunction() {
7633
7634}
7635// Settings: {"jsdoc":{"maxLines":3,"minLines":0}}
7636
7637/** @func myFunction */ function myFunction() {
7638
7639}
7640// Settings: {"jsdoc":{"maxLines":0,"minLines":0}}
7641
7642/**
7643 * @func myFunction
7644 */
7645
7646function myFunction() {
7647
7648}
7649// Settings: {"jsdoc":{"maxLines":3,"minLines":2}}
7650
7651function myFunction() {}
7652// Options: [{"require":{"ClassDeclaration":true,"FunctionDeclaration":false,"MethodDefinition":true}}]
7653
7654var myFunction = function() {}
7655// Options: [{"require":{"ClassDeclaration":true,"FunctionDeclaration":false,"MethodDefinition":true}}]
7656
7657/**
7658 * Description for A.
7659 */
7660class A {
7661 /**
7662 * Description for constructor.
7663 * @param {object[]} xs - xs
7664 */
7665 constructor(xs) {
7666 this.a = xs;
7667 }
7668}
7669// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7670
7671/**
7672 * Description for A.
7673 */
7674class App extends Component {
7675 /**
7676 * Description for constructor.
7677 * @param {object[]} xs - xs
7678 */
7679 constructor(xs) {
7680 this.a = xs;
7681 }
7682}
7683// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7684
7685/**
7686 * Description for A.
7687 */
7688export default class App extends Component {
7689 /**
7690 * Description for constructor.
7691 * @param {object[]} xs - xs
7692 */
7693 constructor(xs) {
7694 this.a = xs;
7695 }
7696}
7697// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7698
7699/**
7700 * Description for A.
7701 */
7702export class App extends Component {
7703 /**
7704 * Description for constructor.
7705 * @param {object[]} xs - xs
7706 */
7707 constructor(xs) {
7708 this.a = xs;
7709 }
7710}
7711// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7712
7713class A {
7714 constructor(xs) {
7715 this.a = xs;
7716 }
7717}
7718// Options: [{"require":{"ClassDeclaration":false,"MethodDefinition":false}}]
7719
7720/**
7721* Function doing something
7722*/
7723var myFunction = () => {}
7724// Options: [{"require":{"ArrowFunctionExpression":true}}]
7725
7726/**
7727* Function doing something
7728*/
7729var myFunction = function () {}
7730// Options: [{"require":{"ArrowFunctionExpression":true}}]
7731
7732/**
7733* Function doing something
7734*/
7735var myFunction = () => {}
7736// Options: [{"require":{"ArrowFunctionExpression":false}}]
7737
7738/**
7739 Function doing something
7740*/
7741var myFunction = () => () => {}
7742// Options: [{"require":{"ArrowFunctionExpression":true}}]
7743
7744setTimeout(() => {}, 10);
7745// Options: [{"require":{"ArrowFunctionExpression":true}}]
7746
7747/**
7748JSDoc Block
7749*/
7750var foo = function() {}
7751// Options: [{"require":{"FunctionExpression":true}}]
7752
7753const foo = {/**
7754JSDoc Block
7755*/
7756bar() {}}
7757// Options: [{"require":{"FunctionExpression":true}}]
7758
7759var foo = {/**
7760JSDoc Block
7761*/
7762bar: function() {}}
7763// Options: [{"require":{"FunctionExpression":true}}]
7764
7765var foo = { [function() {}]: 1 };
7766// Options: [{"require":{"FunctionExpression":true}}]
7767
7768function foo () {}
7769// Options: [{"exemptEmptyFunctions":true}]
7770
7771function foo () {
7772 return;
7773}
7774// Options: [{"exemptEmptyFunctions":true}]
7775
7776const test = {};
7777/**
7778 * test
7779 */
7780 test.method = function () {
7781
7782}
7783module.exports = {
7784 prop: { prop2: test.method }
7785}
7786// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7787
7788/**
7789 *
7790 */
7791function test() {
7792
7793}
7794
7795module.exports = {
7796 prop: { prop2: test }
7797}
7798// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7799
7800/**
7801 *
7802 */
7803test = function() {
7804
7805}
7806
7807module.exports = {
7808 prop: { prop2: test }
7809}
7810// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionExpression":true}}]
7811
7812/**
7813 *
7814 */
7815test = function() {
7816
7817}
7818
7819exports.someMethod = {
7820 prop: { prop2: test }
7821}
7822// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
7823
7824/**
7825 *
7826 */
7827const test = () => {
7828
7829}
7830
7831module.exports = {
7832prop: { prop2: test }
7833}
7834// Options: [{"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
7835
7836const test = () => {
7837
7838}
7839module.exports = {
7840 prop: { prop2: test }
7841}
7842// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"ArrowFunctionExpression":true}}]
7843
7844/**
7845 *
7846 */
7847window.test = function() {
7848
7849}
7850
7851module.exports = {
7852prop: window
7853}
7854// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7855
7856test = function() {
7857
7858}
7859
7860/**
7861 *
7862 */
7863test = function() {
7864
7865}
7866
7867module.exports = {
7868prop: { prop2: test }
7869}
7870// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7871
7872test = function() {
7873
7874}
7875
7876test = 2;
7877
7878module.exports = {
7879prop: { prop2: test }
7880}
7881// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7882
7883/**
7884 *
7885 */
7886function test() {
7887
7888}
7889
7890/**
7891 *
7892 */
7893test.prototype.method = function() {
7894
7895}
7896
7897module.exports = {
7898prop: { prop2: test }
7899}
7900// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7901
7902class Test {
7903 /**
7904 * Test
7905 */
7906 method() {
7907
7908 }
7909}
7910module.exports = Test;
7911// Options: [{"publicOnly":true,"require":{"MethodDefinition":true}}]
7912
7913/**
7914 *
7915 */
7916export default function quux () {
7917
7918}
7919// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7920
7921/**
7922 *
7923 */
7924export default function quux () {
7925
7926}
7927// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7928
7929/**
7930 *
7931 */
7932function quux () {
7933
7934}
7935export default quux;
7936// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7937
7938function quux () {
7939
7940}
7941export default quux;
7942// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7943
7944/**
7945 *
7946 */
7947export function test() {
7948
7949}
7950// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7951
7952/**
7953 *
7954 */
7955export function test() {
7956
7957}
7958// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7959
7960/**
7961 *
7962 */
7963var test = function () {
7964
7965}
7966var test2 = 2;
7967export { test, test2 }
7968// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7969
7970/**
7971 *
7972 */
7973var test = function () {
7974
7975}
7976export { test as test2 }
7977// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7978
7979/**
7980 *
7981 */
7982export default class A {
7983
7984}
7985// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true}}]
7986
7987/**
7988 *
7989 */
7990var test = function () {
7991
7992}
7993// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7994
7995let test = function () {
7996
7997}
7998// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7999
8000let test = class {
8001
8002}
8003// Options: [{"publicOnly":true,"require":{"ClassExpression":false}}]
8004
8005/**
8006 *
8007 */
8008let test = class {
8009
8010}
8011// Options: [{"publicOnly":true,"require":{"ClassExpression":true}}]
8012
8013export function someMethod() {
8014
8015}
8016// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionDeclaration":true}}]
8017
8018export function someMethod() {
8019
8020}
8021// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionDeclaration":true}}]
8022
8023exports.someMethod = function() {
8024
8025}
8026// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
8027
8028const myObject = {
8029 myProp: true
8030};
8031// Options: [{"contexts":[]}]
8032
8033function bear() {}
8034/**
8035 *
8036 */
8037function quux () {
8038}
8039export default quux;
8040// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
8041
8042/**
8043 * This example interface is great!
8044 */
8045export interface Example {
8046 /**
8047 * My super test string!
8048 */
8049 test: string
8050}
8051// Options: [{"contexts":["TSInterfaceDeclaration"]}]
8052
8053/**
8054 * This example interface is great!
8055 */
8056interface Example {
8057 /**
8058 * My super test string!
8059 */
8060 test: string
8061}
8062// Options: [{"contexts":["TSInterfaceDeclaration"]}]
8063
8064/**
8065 * This example type is great!
8066 */
8067export type Example = {
8068 /**
8069 * My super test string!
8070 */
8071 test: string
8072};
8073// Options: [{"contexts":["TSTypeAliasDeclaration"]}]
8074
8075/**
8076 * This example type is great!
8077 */
8078type Example = {
8079 /**
8080 * My super test string!
8081 */
8082 test: string
8083};
8084// Options: [{"contexts":["TSTypeAliasDeclaration"]}]
8085
8086/**
8087 * This example enum is great!
8088 */
8089export enum Example {
8090 /**
8091 * My super test enum!
8092 */
8093 test = 123
8094}
8095// Options: [{"contexts":["TSEnumDeclaration"]}]
8096
8097/**
8098 * This example enum is great!
8099 */
8100enum Example {
8101 /**
8102 * My super test enum!
8103 */
8104 test = 123
8105}
8106// Options: [{"contexts":["TSEnumDeclaration"]}]
8107
8108const foo = {...{}};
8109function bar() {}
8110// Options: [{"exemptEmptyFunctions":false,"publicOnly":true,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
8111
8112/**
8113 * Class documentation
8114 */
8115 @logged
8116export default class Foo {
8117 // ....
8118}
8119// Options: [{"exemptEmptyFunctions":false,"require":{"ClassDeclaration":true}}]
8120````
8121
8122
8123<a name="eslint-plugin-jsdoc-rules-require-param-description"></a>
8124### <code>require-param-description</code>
8125
8126Requires that each `@param` tag has a `description` value.
8127
8128<a name="eslint-plugin-jsdoc-rules-require-param-description-options-20"></a>
8129#### Options
8130
8131<a name="eslint-plugin-jsdoc-rules-require-param-description-options-20-contexts-4"></a>
8132##### <code>contexts</code>
8133
8134Set this to an array of strings representing the AST context
8135where you wish the rule to be applied.
8136Overrides the default contexts (see below). Set to `"any"` if you want
8137the rule to apply to any jsdoc block throughout your files (as is necessary
8138for finding function blocks not attached to a function declaration or
8139expression, i.e., `@callback` or `@function` (or its aliases `@func` or
8140`@method`) (including those associated with an `@interface`).
8141
8142|||
8143|---|---|
8144|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8145|Tags|`param`|
8146|Aliases|`arg`, `argument`|
8147|Options|`contexts`|
8148
8149The following patterns are considered problems:
8150
8151````js
8152/**
8153 * @param foo
8154 */
8155function quux (foo) {
8156
8157}
8158// Message: Missing JSDoc @param "foo" description.
8159
8160/**
8161 * @param foo
8162 */
8163function quux (foo) {
8164
8165}
8166// Options: [{"contexts":["any"]}]
8167// Message: Missing JSDoc @param "foo" description.
8168
8169/**
8170 * @function
8171 * @param foo
8172 */
8173// Options: [{"contexts":["any"]}]
8174// Message: Missing JSDoc @param "foo" description.
8175
8176/**
8177 * @callback
8178 * @param foo
8179 */
8180// Options: [{"contexts":["any"]}]
8181// Message: Missing JSDoc @param "foo" description.
8182
8183/**
8184 * @arg foo
8185 */
8186function quux (foo) {
8187
8188}
8189// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8190// Message: Missing JSDoc @arg "foo" description.
8191
8192/**
8193 * @param foo
8194 */
8195function quux (foo) {
8196
8197}
8198// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
8199// Message: Unexpected tag `@param`
8200````
8201
8202The following patterns are not considered problems:
8203
8204````js
8205/**
8206 *
8207 */
8208function quux (foo) {
8209
8210}
8211
8212/**
8213 * @param foo Foo.
8214 */
8215function quux (foo) {
8216
8217}
8218
8219/**
8220 * @param foo Foo.
8221 */
8222function quux (foo) {
8223
8224}
8225// Options: [{"contexts":["any"]}]
8226
8227/**
8228 * @function
8229 * @param foo
8230 */
8231
8232/**
8233 * @callback
8234 * @param foo
8235 */
8236````
8237
8238
8239<a name="eslint-plugin-jsdoc-rules-require-param-name"></a>
8240### <code>require-param-name</code>
8241
8242Requires that all function parameters have names.
8243
8244> 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.
8245>
8246> [JSDoc](https://jsdoc.app/tags-param.html#overview)
8247
8248<a name="eslint-plugin-jsdoc-rules-require-param-name-options-21"></a>
8249#### Options
8250
8251<a name="eslint-plugin-jsdoc-rules-require-param-name-options-21-contexts-5"></a>
8252##### <code>contexts</code>
8253
8254Set this to an array of strings representing the AST context
8255where you wish the rule to be applied.
8256Overrides the default contexts (see below). Set to `"any"` if you want
8257the rule to apply to any jsdoc block throughout your files (as is necessary
8258for finding function blocks not attached to a function declaration or
8259expression, i.e., `@callback` or `@function` (or its aliases `@func` or
8260`@method`) (including those associated with an `@interface`).
8261
8262|||
8263|---|---|
8264|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8265|Tags|`param`|
8266|Aliases|`arg`, `argument`|
8267|Options|`contexts`|
8268
8269The following patterns are considered problems:
8270
8271````js
8272/**
8273 * @param
8274 */
8275function quux (foo) {
8276
8277}
8278// Message: There must be an identifier after @param type.
8279
8280/**
8281 * @param {string}
8282 */
8283function quux (foo) {
8284
8285}
8286// Message: There must be an identifier after @param tag.
8287
8288/**
8289 * @param {string}
8290 */
8291function quux (foo) {
8292
8293}
8294// Options: [{"contexts":["any"]}]
8295// Message: There must be an identifier after @param tag.
8296
8297/**
8298 * @function
8299 * @param {string}
8300 */
8301// Options: [{"contexts":["any"]}]
8302// Message: There must be an identifier after @param tag.
8303
8304/**
8305 * @callback
8306 * @param {string}
8307 */
8308// Options: [{"contexts":["any"]}]
8309// Message: There must be an identifier after @param tag.
8310
8311/**
8312 * @param foo
8313 */
8314function quux (foo) {
8315
8316}
8317// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
8318// Message: Unexpected tag `@param`
8319````
8320
8321The following patterns are not considered problems:
8322
8323````js
8324/**
8325 * @param foo
8326 */
8327function quux (foo) {
8328
8329}
8330
8331/**
8332 * @param foo
8333 */
8334function quux (foo) {
8335
8336}
8337// Options: [{"contexts":["any"]}]
8338
8339/**
8340 * @param {string} foo
8341 */
8342function quux (foo) {
8343
8344}
8345
8346/**
8347 * @function
8348 * @param
8349 */
8350
8351/**
8352 * @callback
8353 * @param
8354 */
8355````
8356
8357
8358<a name="eslint-plugin-jsdoc-rules-require-param-type"></a>
8359### <code>require-param-type</code>
8360
8361Requires that each `@param` tag has a `type` value.
8362
8363<a name="eslint-plugin-jsdoc-rules-require-param-type-options-22"></a>
8364#### Options
8365
8366<a name="eslint-plugin-jsdoc-rules-require-param-type-options-22-contexts-6"></a>
8367##### <code>contexts</code>
8368
8369Set this to an array of strings representing the AST context
8370where you wish the rule to be applied.
8371Overrides the default contexts (see below). Set to `"any"` if you want
8372the rule to apply to any jsdoc block throughout your files (as is necessary
8373for finding function blocks not attached to a function declaration or
8374expression, i.e., `@callback` or `@function` (or its aliases `@func` or
8375`@method`) (including those associated with an `@interface`).
8376
8377|||
8378|---|---|
8379|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
8380|Tags|`param`|
8381|Aliases|`arg`, `argument`|
8382|Options|`contexts`|
8383
8384The following patterns are considered problems:
8385
8386````js
8387/**
8388 * @param foo
8389 */
8390function quux (foo) {
8391
8392}
8393// Message: Missing JSDoc @param "foo" type.
8394
8395/**
8396 * @param foo
8397 */
8398function quux (foo) {
8399
8400}
8401// Options: [{"contexts":["any"]}]
8402// Message: Missing JSDoc @param "foo" type.
8403
8404/**
8405 * @function
8406 * @param foo
8407 */
8408// Options: [{"contexts":["any"]}]
8409// Message: Missing JSDoc @param "foo" type.
8410
8411/**
8412 * @callback
8413 * @param foo
8414 */
8415// Options: [{"contexts":["any"]}]
8416// Message: Missing JSDoc @param "foo" type.
8417
8418/**
8419 * @arg foo
8420 */
8421function quux (foo) {
8422
8423}
8424// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8425// Message: Missing JSDoc @arg "foo" type.
8426
8427/**
8428 * @param foo
8429 */
8430function quux (foo) {
8431
8432}
8433// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
8434// Message: Unexpected tag `@param`
8435````
8436
8437The following patterns are not considered problems:
8438
8439````js
8440/**
8441 *
8442 */
8443function quux (foo) {
8444
8445}
8446
8447/**
8448 * @param {number} foo
8449 */
8450function quux (foo) {
8451
8452}
8453
8454/**
8455 * @param {number} foo
8456 */
8457function quux (foo) {
8458
8459}
8460// Options: [{"contexts":["any"]}]
8461
8462/**
8463 * @function
8464 * @param foo
8465 */
8466
8467/**
8468 * @callback
8469 * @param foo
8470 */
8471````
8472
8473
8474<a name="eslint-plugin-jsdoc-rules-require-param"></a>
8475### <code>require-param</code>
8476
8477Requires that all function parameters are documented.
8478
8479<a name="eslint-plugin-jsdoc-rules-require-param-options-23"></a>
8480#### Options
8481
8482An options object accepts one optional property:
8483
8484- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
8485 block avoids the need for a `@param`. Defaults to an empty array.
8486
8487|||
8488|---|---|
8489|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
8490|Tags|`param`|
8491|Aliases|`arg`, `argument`|
8492|Options|`exemptedBy`|
8493|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
8494
8495The following patterns are considered problems:
8496
8497````js
8498/**
8499 *
8500 */
8501function quux (foo) {
8502
8503}
8504// Message: Missing JSDoc @param "foo" declaration.
8505
8506/**
8507 *
8508 */
8509function quux (foo, bar) {
8510
8511}
8512// Message: Missing JSDoc @param "foo" declaration.
8513
8514/**
8515 * @param foo
8516 */
8517function quux (foo, bar) {
8518
8519}
8520// Message: Missing JSDoc @param "bar" declaration.
8521
8522/**
8523 * @param bar
8524 */
8525function quux (foo, bar, baz) {
8526
8527}
8528// Message: Missing JSDoc @param "foo" declaration.
8529
8530/**
8531 * @param foo
8532 * @param bar
8533 */
8534function quux (foo, bar, baz) {
8535
8536}
8537// Message: Missing JSDoc @param "baz" declaration.
8538
8539/**
8540 * @param baz
8541 */
8542function quux (foo, bar, baz) {
8543
8544}
8545// Message: Missing JSDoc @param "foo" declaration.
8546
8547/**
8548 * @param
8549 */
8550function quux (foo) {
8551
8552}
8553// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8554// Message: Missing JSDoc @arg "foo" declaration.
8555
8556/**
8557 * @param foo
8558 */
8559function quux (foo, bar) {
8560
8561}
8562// Message: Missing JSDoc @param "bar" declaration.
8563
8564/**
8565 * @override
8566 */
8567function quux (foo) {
8568
8569}
8570// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
8571// Message: Missing JSDoc @param "foo" declaration.
8572
8573/**
8574 * @implements
8575 */
8576function quux (foo) {
8577
8578}
8579// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
8580// Message: Missing JSDoc @param "foo" declaration.
8581
8582/**
8583 * @augments
8584 */
8585function quux (foo) {
8586
8587}
8588// Message: Missing JSDoc @param "foo" declaration.
8589
8590/**
8591 * @extends
8592 */
8593function quux (foo) {
8594
8595}
8596// Message: Missing JSDoc @param "foo" declaration.
8597
8598/**
8599 * @override
8600 */
8601class A {
8602 /**
8603 *
8604 */
8605 quux (foo) {
8606
8607 }
8608}
8609// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
8610// Message: Missing JSDoc @param "foo" declaration.
8611
8612/**
8613 * @implements
8614 */
8615class A {
8616 /**
8617 *
8618 */
8619 quux (foo) {
8620
8621 }
8622}
8623// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
8624// Message: Missing JSDoc @param "foo" declaration.
8625
8626/**
8627 * @augments
8628 */
8629class A {
8630 /**
8631 *
8632 */
8633 quux (foo) {
8634
8635 }
8636}
8637// Message: Missing JSDoc @param "foo" declaration.
8638
8639/**
8640 * @extends
8641 */
8642class A {
8643 /**
8644 *
8645 */
8646 quux (foo) {
8647
8648 }
8649}
8650// Message: Missing JSDoc @param "foo" declaration.
8651
8652export class SomeClass {
8653 /**
8654 * @param property
8655 */
8656 constructor(private property: string, private foo: number) {}
8657}
8658// Message: Missing JSDoc @param "foo" declaration.
8659
8660/**
8661 * @param
8662 */
8663function quux (foo) {
8664
8665}
8666// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
8667// Message: Unexpected tag `@param`
8668
8669/**
8670 *
8671 */
8672function quux ({bar, baz}, foo) {
8673}
8674// Message: Missing JSDoc @param "foo" declaration.
8675
8676/**
8677 *
8678 */
8679function quux (foo, {bar, baz}) {
8680}
8681// Message: Missing JSDoc @param "foo" declaration.
8682
8683/**
8684 *
8685 */
8686function quux ([bar, baz], foo) {
8687}
8688// Message: Missing JSDoc @param "foo" declaration.
8689
8690/**
8691 *
8692 */
8693function quux (foo) {
8694}
8695// Options: [{"exemptedBy":["notPresent"]}]
8696// Message: Missing JSDoc @param "foo" declaration.
8697````
8698
8699The following patterns are not considered problems:
8700
8701````js
8702/**
8703 * @param foo
8704 */
8705function quux (foo) {
8706
8707}
8708
8709/**
8710 * @inheritdoc
8711 */
8712function quux (foo) {
8713
8714}
8715
8716/**
8717 * @arg foo
8718 */
8719function quux (foo) {
8720
8721}
8722// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8723
8724/**
8725 * @override
8726 * @param foo
8727 */
8728function quux (foo) {
8729
8730}
8731
8732/**
8733 * @override
8734 */
8735function quux (foo) {
8736
8737}
8738
8739/**
8740 * @override
8741 */
8742class A {
8743 /**
8744 *
8745 */
8746 quux (foo) {
8747
8748 }
8749}
8750
8751/**
8752 * @override
8753 */
8754function quux (foo) {
8755
8756}
8757// Settings: {"jsdoc":{"overrideReplacesDocs":true}}
8758
8759/**
8760 * @implements
8761 */
8762class A {
8763 /**
8764 *
8765 */
8766 quux (foo) {
8767
8768 }
8769}
8770
8771/**
8772 * @implements
8773 */
8774function quux (foo) {
8775
8776}
8777
8778/**
8779 * @implements
8780 */
8781function quux (foo) {
8782
8783}
8784// Settings: {"jsdoc":{"implementsReplacesDocs":true}}
8785
8786/**
8787 * @implements
8788 * @param foo
8789 */
8790function quux (foo) {
8791
8792}
8793
8794/**
8795 * @augments
8796 */
8797function quux (foo) {
8798
8799}
8800// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8801
8802/**
8803 * @augments
8804 * @param foo
8805 */
8806function quux (foo) {
8807
8808}
8809
8810/**
8811 * @extends
8812 */
8813function quux (foo) {
8814
8815}
8816// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8817
8818/**
8819 * @extends
8820 * @param foo
8821 */
8822function quux (foo) {
8823
8824}
8825
8826/**
8827 * @augments
8828 */
8829function quux (foo) {
8830
8831}
8832// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8833
8834/**
8835 * @extends
8836 */
8837function quux (foo) {
8838
8839}
8840// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8841
8842/**
8843 * @override
8844 */
8845class A {
8846 /**
8847 * @param foo
8848 */
8849 quux (foo) {
8850
8851 }
8852}
8853
8854/**
8855 * @override
8856 */
8857class A {
8858 /**
8859 *
8860 */
8861 quux (foo) {
8862
8863 }
8864}
8865// Settings: {"jsdoc":{"overrideReplacesDocs":true}}
8866
8867/**
8868 * @implements
8869 */
8870class A {
8871 /**
8872 *
8873 */
8874 quux (foo) {
8875
8876 }
8877}
8878// Settings: {"jsdoc":{"implementsReplacesDocs":true}}
8879
8880/**
8881 * @implements
8882 */
8883class A {
8884 /**
8885 * @param foo
8886 */
8887 quux (foo) {
8888
8889 }
8890}
8891
8892/**
8893 * @augments
8894 */
8895class A {
8896 /**
8897 *
8898 */
8899 quux (foo) {
8900
8901 }
8902}
8903// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8904
8905/**
8906 * @augments
8907 */
8908class A {
8909 /**
8910 * @param foo
8911 */
8912 quux (foo) {
8913
8914 }
8915}
8916
8917/**
8918 * @extends
8919 */
8920class A {
8921 /**
8922 *
8923 */
8924 quux (foo) {
8925
8926 }
8927}
8928// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8929
8930/**
8931 * @extends
8932 */
8933class A {
8934 /**
8935 * @param foo
8936 */
8937 quux (foo) {
8938
8939 }
8940}
8941
8942/**
8943 * @augments
8944 */
8945class A {
8946 /**
8947 *
8948 */
8949 quux (foo) {
8950
8951 }
8952}
8953// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8954
8955/**
8956 * @extends
8957 */
8958class A {
8959 /**
8960 *
8961 */
8962 quux (foo) {
8963
8964 }
8965}
8966// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8967
8968/**
8969 * @private
8970 */
8971function quux (foo) {
8972
8973}
8974// Settings: {"jsdoc":{"ignorePrivate":true}}
8975
8976/**
8977 * @access private
8978 */
8979function quux (foo) {
8980
8981}
8982// Settings: {"jsdoc":{"ignorePrivate":true}}
8983
8984// issue 182: optional chaining
8985/** @const {boolean} test */
8986const test = something?.find(_ => _)
8987
8988/** @type {RequestHandler} */
8989function foo(req, res, next) {}
8990
8991/**
8992 * @type {MyCallback}
8993 */
8994function quux () {
8995
8996}
8997// Options: [{"exemptedBy":["type"]}]
8998
8999/**
9000 * @override
9001 */
9002var A = class {
9003 /**
9004 *
9005 */
9006 quux (foo) {
9007
9008 }
9009}
9010
9011export class SomeClass {
9012 /**
9013 * @param property
9014 */
9015 constructor(private property: string) {}
9016}
9017
9018/**
9019 * Assign the project to an employee.
9020 *
9021 * @param {object} employee - The employee who is responsible for the project.
9022 * @param {string} employee.name - The name of the employee.
9023 * @param {string} employee.department - The employee's department.
9024 */
9025function assign({name, department}) {
9026 // ...
9027}
9028
9029export abstract class StephanPlugin<O, D> {
9030
9031 /**
9032 * Called right after Stephan loads the plugin file.
9033 *
9034 * @example
9035 *```typescript
9036 * type Options = {
9037 * verbose?: boolean;
9038 * token?: string;
9039 * }
9040 * ```
9041 *
9042 * Note that your Options type should only have optional properties...
9043 *
9044 * @param args Arguments compiled and provided by StephanClient.
9045 * @param args.options The options as provided by the user, or an empty object if not provided.
9046 * @param defaultOptions The default options as provided by the plugin, or an empty object.
9047 */
9048 public constructor({options, client}: {
9049 options: O;
9050 client: unknown;
9051 }, defaultOptions: D) {
9052
9053 }
9054}
9055````
9056
9057
9058<a name="eslint-plugin-jsdoc-rules-require-property"></a>
9059### <code>require-property</code>
9060
9061Requires that all `@typedef` and `@namespace` tags have `@property`
9062when their type is a plain `object`, `Object`, or `PlainObject`.
9063
9064Note that if any other type, including a subtype of object such as
9065`object<string, string>`, will not be reported.
9066
9067<a name="eslint-plugin-jsdoc-rules-require-property-fixer-1"></a>
9068#### Fixer
9069
9070The fixer for `require-example` will add an empty `@property`.
9071
9072|||
9073|---|---|
9074|Context|Everywhere|
9075|Tags|`typedef`, `namespace`|
9076
9077The following patterns are considered problems:
9078
9079````js
9080/**
9081 * @typedef {object} SomeTypedef
9082 */
9083// Message: Missing JSDoc @property.
9084
9085/**
9086 * @typedef {PlainObject} SomeTypedef
9087 */
9088// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
9089// Message: Missing JSDoc @prop.
9090
9091/**
9092 * @namespace {Object} SomeName
9093 */
9094// Message: Missing JSDoc @property.
9095````
9096
9097The following patterns are not considered problems:
9098
9099````js
9100/**
9101 *
9102 */
9103
9104/**
9105 * @property
9106 */
9107
9108/**
9109 * @typedef {Object} SomeTypedef
9110 * @property {SomeType} propName Prop description
9111 */
9112
9113/**
9114 * @typedef {object} SomeTypedef
9115 * @prop {SomeType} propName Prop description
9116 */
9117// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
9118
9119/**
9120 * @typedef {object} SomeTypedef
9121 * @property
9122 * // arbitrary property content
9123 */
9124
9125/**
9126 * @typedef {object<string, string>} SomeTypedef
9127 */
9128
9129/**
9130 * @typedef {string} SomeTypedef
9131 */
9132
9133/**
9134 * @namespace {object} SomeName
9135 * @property {SomeType} propName Prop description
9136 */
9137
9138/**
9139 * @namespace {object} SomeName
9140 * @property
9141 * // arbitrary property content
9142 */
9143
9144/**
9145 * @typedef {object} SomeTypedef
9146 * @property someProp
9147 * @property anotherProp This with a description
9148 * @property {anotherType} yetAnotherProp This with a type and desc.
9149 */
9150function quux () {
9151
9152}
9153````
9154
9155
9156<a name="eslint-plugin-jsdoc-rules-require-property-description"></a>
9157### <code>require-property-description</code>
9158
9159Requires that each `@property` tag has a `description` value.
9160
9161|||
9162|---|---|
9163|Context|everywhere|
9164|Tags|N/A|
9165
9166The following patterns are considered problems:
9167
9168````js
9169/**
9170 * @typedef {SomeType} SomeTypedef
9171 * @property foo
9172 */
9173// Message: Missing JSDoc @property "foo" description.
9174
9175/**
9176 * @typedef {SomeType} SomeTypedef
9177 * @prop foo
9178 */
9179// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
9180// Message: Missing JSDoc @prop "foo" description.
9181
9182/**
9183 * @typedef {SomeType} SomeTypedef
9184 * @property foo
9185 */
9186// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
9187// Message: Unexpected tag `@property`
9188````
9189
9190The following patterns are not considered problems:
9191
9192````js
9193/**
9194 * @typedef {SomeType} SomeTypedef
9195 */
9196
9197/**
9198 * @typedef {SomeType} SomeTypedef
9199 * @property foo Foo.
9200 */
9201
9202/**
9203 * @namespace {SomeType} SomeName
9204 * @property foo Foo.
9205 */
9206
9207/**
9208 * @class
9209 * @property foo Foo.
9210 */
9211````
9212
9213
9214<a name="eslint-plugin-jsdoc-rules-require-property-name"></a>
9215### <code>require-property-name</code>
9216
9217Requires that all function `@property` tags have names.
9218
9219|||
9220|---|---|
9221|Context|everywhere|
9222|Tags|N/A|
9223
9224The following patterns are considered problems:
9225
9226````js
9227/**
9228 * @typedef {SomeType} SomeTypedef
9229 * @property
9230 */
9231// Message: There must be an identifier after @property type.
9232
9233/**
9234 * @typedef {SomeType} SomeTypedef
9235 * @property {string}
9236 */
9237// Message: There must be an identifier after @property tag.
9238
9239/**
9240 * @typedef {SomeType} SomeTypedef
9241 * @property foo
9242 */
9243// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
9244// Message: Unexpected tag `@property`
9245````
9246
9247The following patterns are not considered problems:
9248
9249````js
9250/**
9251 * @typedef {SomeType} SomeTypedef
9252 * @property foo
9253 */
9254
9255/**
9256 * @typedef {SomeType} SomeTypedef
9257 * @property {string} foo
9258 */
9259
9260/**
9261 * @namespace {SomeType} SomeName
9262 * @property {string} foo
9263 */
9264
9265/**
9266 * @class
9267 * @property {string} foo
9268 */
9269````
9270
9271
9272<a name="eslint-plugin-jsdoc-rules-require-property-type"></a>
9273### <code>require-property-type</code>
9274
9275Requires that each `@property` tag has a `type` value.
9276
9277|||
9278|---|---|
9279|Context|everywhere|
9280|Tags|N/A|
9281
9282The following patterns are considered problems:
9283
9284````js
9285/**
9286 * @typedef {SomeType} SomeTypedef
9287 * @property foo
9288 */
9289// Message: Missing JSDoc @property "foo" type.
9290
9291/**
9292 * @typedef {SomeType} SomeTypedef
9293 * @prop foo
9294 */
9295// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
9296// Message: Missing JSDoc @prop "foo" type.
9297
9298/**
9299 * @typedef {SomeType} SomeTypedef
9300 * @property foo
9301 */
9302// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
9303// Message: Unexpected tag `@property`
9304````
9305
9306The following patterns are not considered problems:
9307
9308````js
9309/**
9310 * @typedef {SomeType} SomeTypedef
9311 */
9312
9313/**
9314 * @typedef {SomeType} SomeTypedef
9315 * @property {number} foo
9316 */
9317
9318/**
9319 * @namespace {SomeType} SomeName
9320 * @property {number} foo
9321 */
9322
9323/**
9324 * @class
9325 * @property {number} foo
9326 */
9327````
9328
9329
9330<a name="eslint-plugin-jsdoc-rules-require-returns-check"></a>
9331### <code>require-returns-check</code>
9332
9333Requires a return statement in function body if a `@returns` tag is specified in jsdoc comment.
9334
9335Will also report if multiple `@returns` tags are present.
9336
9337|||
9338|---|---|
9339|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
9340|Tags|`returns`|
9341|Aliases|`return`|
9342
9343The following patterns are considered problems:
9344
9345````js
9346/**
9347 * @returns
9348 */
9349function quux (foo) {
9350
9351}
9352// Message: JSDoc @returns declaration present but return expression not available in function.
9353
9354/**
9355 * @return
9356 */
9357function quux (foo) {
9358
9359}
9360// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
9361// Message: JSDoc @return declaration present but return expression not available in function.
9362
9363/**
9364 * @returns
9365 */
9366const quux = () => {}
9367// Message: JSDoc @returns declaration present but return expression not available in function.
9368
9369/**
9370 * @returns {undefined} Foo.
9371 * @returns {String} Foo.
9372 */
9373function quux () {
9374
9375 return foo;
9376}
9377// Message: Found more than one @returns declaration.
9378
9379const language = {
9380 /**
9381 * @param {string} name
9382 * @returns {string}
9383 */
9384 get name() {
9385 this._name = name;
9386 }
9387}
9388// Message: JSDoc @returns declaration present but return expression not available in function.
9389
9390class Foo {
9391 /**
9392 * @returns {string}
9393 */
9394 bar () {
9395 }
9396}
9397// Message: JSDoc @returns declaration present but return expression not available in function.
9398
9399/**
9400 * @returns
9401 */
9402function quux () {
9403
9404}
9405// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
9406// Message: Unexpected tag `@returns`
9407
9408/**
9409 * @returns {string}
9410 */
9411function f () {
9412 function g() {
9413 return 'foo'
9414 }
9415
9416 () => {
9417 return 5
9418 }
9419}
9420// Message: JSDoc @returns declaration present but return expression not available in function.
9421````
9422
9423The following patterns are not considered problems:
9424
9425````js
9426/**
9427 * @returns Foo.
9428 */
9429function quux () {
9430
9431 return foo;
9432}
9433
9434/**
9435 * @returns {string} Foo.
9436 */
9437function quux () {
9438
9439 return foo;
9440}
9441
9442/**
9443 * @returns {string} Foo.
9444 */
9445function quux () {
9446
9447 return foo;
9448}
9449
9450/**
9451 *
9452 */
9453function quux () {
9454}
9455
9456/**
9457 * @returns {*} Foo.
9458 */
9459const quux = () => foo;
9460
9461/**
9462 * @returns {undefined} Foo.
9463 */
9464function quux () {}
9465
9466/**
9467 * @returns { void } Foo.
9468 */
9469function quux () {}
9470
9471/**
9472 * @returns {Promise<void>}
9473 */
9474async function quux() {}
9475
9476/**
9477 * @returns {Promise<void>}
9478 */
9479const quux = async function () {}
9480
9481/**
9482 * @returns {Promise<void>}
9483 */
9484const quux = async () => {}
9485
9486/**
9487 * @returns Foo.
9488 * @abstract
9489 */
9490function quux () {
9491 throw new Error('must be implemented by subclass!');
9492}
9493
9494/**
9495 * @returns Foo.
9496 * @virtual
9497 */
9498function quux () {
9499 throw new Error('must be implemented by subclass!');
9500}
9501
9502/**
9503 * @returns Foo.
9504 * @constructor
9505 */
9506function quux () {
9507}
9508
9509/**
9510 * @interface
9511 */
9512class Foo {
9513 /**
9514 * @returns {string}
9515 */
9516 bar () {
9517 }
9518}
9519
9520/**
9521 * @returns {undefined} Foo.
9522 */
9523function quux () {
9524}
9525
9526/**
9527 * @returns {void} Foo.
9528 */
9529function quux () {
9530}
9531
9532/**
9533 * @returns {void} Foo.
9534 */
9535function quux () {
9536 return undefined;
9537}
9538
9539/**
9540 * @returns {void} Foo.
9541 */
9542function quux () {
9543 return;
9544}
9545
9546/**
9547 *
9548 */
9549function quux () {
9550 return undefined;
9551}
9552
9553/**
9554 *
9555 */
9556function quux () {
9557 return;
9558}
9559
9560/**
9561 * @returns {true}
9562 */
9563function quux () {
9564 try {
9565 return true;
9566 } catch (err) {
9567 }
9568 return;
9569}
9570
9571/**
9572 * @returns {true}
9573 */
9574function quux () {
9575 try {
9576 } finally {
9577 return true;
9578 }
9579 return;
9580}
9581
9582/**
9583 * @returns {true}
9584 */
9585function quux () {
9586 try {
9587 return;
9588 } catch (err) {
9589 }
9590 return true;
9591}
9592
9593/**
9594 * @returns {true}
9595 */
9596function quux () {
9597 try {
9598 something();
9599 } catch (err) {
9600 return true;
9601 }
9602 return;
9603}
9604
9605/**
9606 * @returns {true}
9607 */
9608function quux () {
9609 switch (true) {
9610 case 'abc':
9611 return true;
9612 }
9613 return;
9614}
9615
9616/**
9617 * @returns {true}
9618 */
9619function quux () {
9620 switch (true) {
9621 case 'abc':
9622 return;
9623 }
9624 return true;
9625}
9626
9627/**
9628 * @returns {true}
9629 */
9630function quux () {
9631 for (const i of abc) {
9632 return true;
9633 }
9634 return;
9635}
9636
9637/**
9638 * @returns {true}
9639 */
9640function quux () {
9641 for (const a in b) {
9642 return true;
9643 }
9644}
9645
9646/**
9647 * @returns {true}
9648 */
9649function quux () {
9650 for (let i=0; i<n; i+=1) {
9651 return true;
9652 }
9653}
9654
9655/**
9656 * @returns {true}
9657 */
9658function quux () {
9659 while(true) {
9660 return true
9661 }
9662}
9663
9664/**
9665 * @returns {true}
9666 */
9667function quux () {
9668 do {
9669 return true
9670 }
9671 while(true)
9672}
9673
9674/**
9675 * @returns {true}
9676 */
9677function quux () {
9678 if (true) {
9679 return;
9680 }
9681 return true;
9682}
9683
9684/**
9685 * @returns {true}
9686 */
9687function quux () {
9688 if (true) {
9689 return true;
9690 }
9691}
9692
9693/**
9694 * @returns {true}
9695 */
9696function quux () {
9697 var a = {};
9698 with (a) {
9699 return true;
9700 }
9701}
9702
9703/**
9704 * @returns {true}
9705 */
9706function quux () {
9707 if (true) {
9708 return;
9709 } else {
9710 return true;
9711 }
9712 return;
9713}
9714````
9715
9716
9717<a name="eslint-plugin-jsdoc-rules-require-returns-description"></a>
9718### <code>require-returns-description</code>
9719
9720Requires that the `@returns` tag has a `description` value. The error
9721will not be reported if the return value is `void` or `undefined`.
9722
9723<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-24"></a>
9724#### Options
9725
9726<a name="eslint-plugin-jsdoc-rules-require-returns-description-options-24-contexts-7"></a>
9727##### <code>contexts</code>
9728
9729Set this to an array of strings representing the AST context
9730where you wish the rule to be applied.
9731Overrides the default contexts (see below). Set to `"any"` if you want
9732the rule to apply to any jsdoc block throughout your files (as is necessary
9733for finding function blocks not attached to a function declaration or
9734expression, i.e., `@callback` or `@function` (or its aliases `@func` or
9735`@method`) (including those associated with an `@interface`).
9736
9737|||
9738|---|---|
9739|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
9740|Tags|`returns`|
9741|Aliases|`return`|
9742|Options|`contexts`|
9743
9744The following patterns are considered problems:
9745
9746````js
9747/**
9748 * @returns
9749 */
9750function quux (foo) {
9751
9752}
9753// Message: Missing JSDoc @returns description.
9754
9755/**
9756 * @returns {string}
9757 */
9758function quux (foo) {
9759
9760}
9761// Message: Missing JSDoc @returns description.
9762
9763/**
9764 * @returns {string}
9765 */
9766function quux (foo) {
9767
9768}
9769// Options: [{"contexts":["any"]}]
9770// Message: Missing JSDoc @returns description.
9771
9772/**
9773 * @function
9774 * @returns {string}
9775 */
9776// Options: [{"contexts":["any"]}]
9777// Message: Missing JSDoc @returns description.
9778
9779/**
9780 * @callback
9781 * @returns {string}
9782 */
9783// Options: [{"contexts":["any"]}]
9784// Message: Missing JSDoc @returns description.
9785
9786/**
9787 * @return
9788 */
9789function quux (foo) {
9790
9791}
9792// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
9793// Message: Missing JSDoc @return description.
9794
9795/**
9796 * @returns
9797 */
9798function quux () {
9799
9800}
9801// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
9802// Message: Unexpected tag `@returns`
9803````
9804
9805The following patterns are not considered problems:
9806
9807````js
9808/**
9809 *
9810 */
9811function quux () {
9812
9813}
9814
9815/**
9816 * @returns Foo.
9817 */
9818function quux () {
9819
9820}
9821
9822/**
9823 * @returns Foo.
9824 */
9825function quux () {
9826
9827}
9828// Options: [{"contexts":["any"]}]
9829
9830/**
9831 * @returns {undefined}
9832 */
9833function quux () {
9834
9835}
9836
9837/**
9838 * @returns {void}
9839 */
9840function quux () {
9841
9842}
9843
9844/**
9845 * @function
9846 * @returns
9847 */
9848
9849/**
9850 * @callback
9851 * @returns
9852 */
9853````
9854
9855
9856<a name="eslint-plugin-jsdoc-rules-require-returns-type"></a>
9857### <code>require-returns-type</code>
9858
9859Requires that `@returns` tag has `type` value.
9860
9861<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-25"></a>
9862#### Options
9863
9864<a name="eslint-plugin-jsdoc-rules-require-returns-type-options-25-contexts-8"></a>
9865##### <code>contexts</code>
9866
9867Set this to an array of strings representing the AST context
9868where you wish the rule to be applied.
9869Overrides the default contexts (see below). Set to `"any"` if you want
9870the rule to apply to any jsdoc block throughout your files (as is necessary
9871for finding function blocks not attached to a function declaration or
9872expression, i.e., `@callback` or `@function` (or its aliases `@func` or
9873`@method`) (including those associated with an `@interface`).
9874
9875|||
9876|---|---|
9877|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
9878|Tags|`returns`|
9879|Aliases|`return`|
9880|Options|`contexts`|
9881|Options|`contexts`|
9882
9883The following patterns are considered problems:
9884
9885````js
9886/**
9887 * @returns
9888 */
9889function quux () {
9890
9891}
9892// Message: Missing JSDoc @returns type.
9893
9894/**
9895 * @returns Foo.
9896 */
9897function quux () {
9898
9899}
9900// Message: Missing JSDoc @returns type.
9901
9902/**
9903 * @returns Foo.
9904 */
9905function quux () {
9906
9907}
9908// Options: [{"contexts":["any"]}]
9909// Message: Missing JSDoc @returns type.
9910
9911/**
9912 * @function
9913 * @returns Foo.
9914 */
9915// Options: [{"contexts":["any"]}]
9916// Message: Missing JSDoc @returns type.
9917
9918/**
9919 * @callback
9920 * @returns Foo.
9921 */
9922// Options: [{"contexts":["any"]}]
9923// Message: Missing JSDoc @returns type.
9924
9925/**
9926 * @return Foo.
9927 */
9928function quux () {
9929
9930}
9931// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
9932// Message: Missing JSDoc @return type.
9933
9934/**
9935 * @returns
9936 */
9937function quux () {
9938
9939}
9940// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
9941// Message: Unexpected tag `@returns`
9942````
9943
9944The following patterns are not considered problems:
9945
9946````js
9947/**
9948 * @returns {number}
9949 */
9950function quux () {
9951
9952}
9953
9954/**
9955 * @returns {number}
9956 */
9957function quux () {
9958
9959}
9960// Options: [{"contexts":["any"]}]
9961
9962/**
9963 * @function
9964 * @returns Foo.
9965 */
9966
9967/**
9968 * @callback
9969 * @returns Foo.
9970 */
9971````
9972
9973
9974<a name="eslint-plugin-jsdoc-rules-require-returns"></a>
9975### <code>require-returns</code>
9976
9977Requires returns are documented.
9978
9979Will also report if multiple `@returns` tags are present.
9980
9981<a name="eslint-plugin-jsdoc-rules-require-returns-options-26"></a>
9982#### Options
9983
9984- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
9985 block avoids the need for a `@returns`. Defaults to an empty array.
9986- `forceRequireReturn` - Set to `true` to always insist on
9987 `@returns` documentation regardless of implicit or explicit `return`'s
9988 in the function. May be desired to flag that a project is aware of an
9989 `undefined`/`void` return. Defaults to `false`.
9990- `forceReturnsWithAsync` - By default `async` functions that do not explicitly
9991 return a value pass this rule as an `async` function will always return a
9992 `Promise`, even if the `Promise` resolves to void. You can force all `async`
9993 functions to require return statements by setting `forceReturnsWithAsync`
9994 to `true` on the options object. This may be useful for flagging that there
9995 has been consideration of return type. Defaults to `false`.
9996- `contexts` - Set this to an array of strings representing the AST context
9997 where you wish the rule to be applied.
9998 Overrides the default contexts (see below). Set to `"any"` if you want
9999 the rule to apply to any jsdoc block throughout your files (as is necessary
10000 for finding function blocks not attached to a function declaration or
10001 expression, i.e., `@callback` or `@function` (or its aliases `@func` or
10002 `@method`) (including those associated with an `@interface`). This
10003 rule will only apply on non-default contexts when there is such a tag
10004 present and the `forceRequireReturn` option is set or if the
10005 `forceReturnsWithAsync` option is set with a present `@async` tag
10006 (since we are not checking against the actual `return` values in these
10007 cases).
10008
10009```js
10010'jsdoc/require-returns': ['error', {forceReturnsWithAsync: true}]
10011```
10012
10013|||
10014|---|---|
10015|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
10016|Tags|`returns`|
10017|Aliases|`return`|
10018|Options|`contexts`, `exemptedBy`, `forceRequireReturn`, `forceReturnsWithAsync`|
10019|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
10020
10021The following patterns are considered problems:
10022
10023````js
10024/**
10025 *
10026 */
10027function quux (foo) {
10028
10029 return foo;
10030}
10031// Message: Missing JSDoc @returns declaration.
10032
10033/**
10034 *
10035 */
10036const foo = () => ({
10037 bar: 'baz'
10038})
10039// Message: Missing JSDoc @returns declaration.
10040
10041/**
10042 *
10043 */
10044const foo = bar=>({ bar })
10045// Message: Missing JSDoc @returns declaration.
10046
10047/**
10048 *
10049 */
10050const foo = bar => bar.baz()
10051// Message: Missing JSDoc @returns declaration.
10052
10053/**
10054 *
10055 */
10056function quux (foo) {
10057
10058 return foo;
10059}
10060// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
10061// Message: Missing JSDoc @return declaration.
10062
10063/**
10064 *
10065 */
10066function foo() {}
10067
10068/**
10069 *
10070 */
10071function bar() {}
10072// Settings: {"jsdoc":{"forceRequireReturn":true}}
10073// Message: `settings.jsdoc.forceRequireReturn` has been removed, use options in the rule `require-returns` instead.
10074
10075/**
10076 *
10077 */
10078async function quux() {
10079}
10080// Options: [{"forceRequireReturn":true}]
10081// Message: Missing JSDoc @returns declaration.
10082
10083/**
10084 *
10085 */
10086const quux = async function () {}
10087// Options: [{"forceRequireReturn":true}]
10088// Message: Missing JSDoc @returns declaration.
10089
10090/**
10091 *
10092 */
10093const quux = async () => {}
10094// Options: [{"forceRequireReturn":true}]
10095// Message: Missing JSDoc @returns declaration.
10096
10097/**
10098 *
10099 */
10100async function quux () {}
10101// Options: [{"forceRequireReturn":true}]
10102// Message: Missing JSDoc @returns declaration.
10103
10104/**
10105 *
10106 */
10107function quux () {
10108}
10109// Options: [{"forceRequireReturn":true}]
10110// Message: Missing JSDoc @returns declaration.
10111
10112/**
10113 *
10114 */
10115function quux () {
10116}
10117// Options: [{"contexts":["any"],"forceRequireReturn":true}]
10118// Message: Missing JSDoc @returns declaration.
10119
10120/**
10121 * @function
10122 */
10123// Options: [{"contexts":["any"],"forceRequireReturn":true}]
10124// Message: Missing JSDoc @returns declaration.
10125
10126/**
10127 * @callback
10128 */
10129// Options: [{"contexts":["any"],"forceRequireReturn":true}]
10130// Message: Missing JSDoc @returns declaration.
10131
10132const language = {
10133 /**
10134 * @param {string} name
10135 */
10136 get name() {
10137 return this._name;
10138 }
10139}
10140// Message: Missing JSDoc @returns declaration.
10141
10142/**
10143 *
10144 */
10145async function quux () {
10146}
10147// Options: [{"forceReturnsWithAsync":true}]
10148// Message: Missing JSDoc @returns declaration.
10149
10150/**
10151 * @function
10152 * @async
10153 */
10154// Options: [{"contexts":["any"],"forceReturnsWithAsync":true}]
10155// Message: Missing JSDoc @returns declaration.
10156
10157/**
10158 * @callback
10159 * @async
10160 */
10161// Options: [{"contexts":["any"],"forceReturnsWithAsync":true}]
10162// Message: Missing JSDoc @returns declaration.
10163
10164/**
10165 * @returns {undefined}
10166 * @returns {void}
10167 */
10168function quux (foo) {
10169
10170 return foo;
10171}
10172// Message: Found more than one @returns declaration.
10173
10174/**
10175 * @returns
10176 */
10177function quux () {
10178
10179}
10180// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
10181// Message: Unexpected tag `@returns`
10182
10183/**
10184 * @param foo
10185 */
10186function quux (foo) {
10187 return 'bar';
10188}
10189// Options: [{"exemptedBy":["notPresent"]}]
10190// Message: Missing JSDoc @returns declaration.
10191
10192/**
10193 * @param {array} a
10194 */
10195async function foo(a) {
10196 return;
10197}
10198// Options: [{"forceReturnsWithAsync":true}]
10199// Message: Missing JSDoc @returns declaration.
10200
10201/**
10202 * @param {array} a
10203 */
10204async function foo(a) {
10205 return Promise.all(a);
10206}
10207// Options: [{"forceReturnsWithAsync":true}]
10208// Message: Missing JSDoc @returns declaration.
10209````
10210
10211The following patterns are not considered problems:
10212
10213````js
10214/**
10215 * @returns Foo.
10216 */
10217function quux () {
10218
10219 return foo;
10220}
10221
10222/**
10223 * @returns Foo.
10224 */
10225function quux () {
10226
10227 return foo;
10228}
10229// Options: [{"contexts":["any"]}]
10230
10231/**
10232 *
10233 */
10234function quux () {
10235}
10236
10237/**
10238 *
10239 */
10240function quux (bar) {
10241 bar.filter(baz => {
10242 return baz.corge();
10243 })
10244}
10245
10246/**
10247 * @returns Array
10248 */
10249function quux (bar) {
10250 return bar.filter(baz => {
10251 return baz.corge();
10252 })
10253}
10254
10255/**
10256 * @returns Array
10257 */
10258const quux = (bar) => bar.filter(({ corge }) => corge())
10259
10260/**
10261 * @inheritdoc
10262 */
10263function quux (foo) {
10264}
10265
10266/**
10267 * @override
10268 */
10269function quux (foo) {
10270}
10271
10272/**
10273 * @constructor
10274 */
10275function quux (foo) {
10276}
10277
10278/**
10279 * @implements
10280 */
10281function quux (foo) {
10282}
10283
10284/**
10285 * @override
10286 */
10287function quux (foo) {
10288
10289 return foo;
10290}
10291
10292/**
10293 * @class
10294 */
10295function quux (foo) {
10296
10297}
10298
10299/**
10300 * @constructor
10301 */
10302function quux (foo) {
10303
10304}
10305
10306/**
10307 * @returns {object}
10308 */
10309function quux () {
10310
10311 return {a: foo};
10312}
10313
10314/**
10315 * @returns {object}
10316 */
10317const quux = () => ({a: foo});
10318
10319/**
10320 * @returns {object}
10321 */
10322const quux = () => {
10323 return {a: foo}
10324};
10325
10326/**
10327 * @returns {void}
10328 */
10329function quux () {
10330}
10331
10332/**
10333 * @returns {void}
10334 */
10335const quux = () => {
10336
10337}
10338
10339/**
10340 * @returns {undefined}
10341 */
10342function quux () {
10343}
10344
10345/**
10346 * @returns {undefined}
10347 */
10348const quux = () => {
10349
10350}
10351
10352/**
10353 *
10354 */
10355function quux () {
10356}
10357
10358/**
10359 *
10360 */
10361const quux = () => {
10362
10363}
10364
10365class Foo {
10366 /**
10367 *
10368 */
10369 constructor () {
10370 }
10371}
10372// Options: [{"forceRequireReturn":true}]
10373
10374const language = {
10375 /**
10376 * @param {string} name
10377 */
10378 set name(name) {
10379 this._name = name;
10380 }
10381}
10382
10383/**
10384 * @returns {void}
10385 */
10386function quux () {
10387}
10388// Options: [{"forceRequireReturn":true}]
10389
10390/**
10391 * @returns {void}
10392 */
10393function quux () {
10394 return undefined;
10395}
10396
10397/**
10398 * @returns {void}
10399 */
10400function quux () {
10401 return undefined;
10402}
10403// Options: [{"forceRequireReturn":true}]
10404
10405/**
10406 * @returns {void}
10407 */
10408function quux () {
10409 return;
10410}
10411
10412/**
10413 * @returns {void}
10414 */
10415function quux () {
10416}
10417// Options: [{"forceRequireReturn":true}]
10418
10419/**
10420 * @returns {void}
10421 */
10422function quux () {
10423 return;
10424}
10425// Options: [{"forceRequireReturn":true}]
10426
10427/** @type {RequestHandler} */
10428function quux (req, res , next) {
10429 return;
10430}
10431
10432/**
10433 * @returns {Promise}
10434 */
10435async function quux () {
10436}
10437// Options: [{"forceRequireReturn":true}]
10438
10439/**
10440 * @returns {Promise}
10441 */
10442async function quux () {
10443}
10444// Options: [{"forceReturnsWithAsync":true}]
10445
10446/**
10447 *
10448 */
10449async function quux () {}
10450
10451/**
10452 *
10453 */
10454const quux = async function () {}
10455
10456/**
10457 *
10458 */
10459const quux = async () => {}
10460
10461/** foo class */
10462class foo {
10463 /** foo constructor */
10464 constructor () {
10465 // =>
10466 this.bar = true;
10467 }
10468}
10469
10470export default foo;
10471
10472/**
10473 *
10474 */
10475function quux () {
10476}
10477// Options: [{"forceReturnsWithAsync":true}]
10478
10479/**
10480 * @type {MyCallback}
10481 */
10482function quux () {
10483
10484}
10485// Options: [{"exemptedBy":["type"]}]
10486
10487/**
10488 * @param {array} a
10489 */
10490async function foo(a) {
10491 return Promise.all(a);
10492}
10493
10494/**
10495 * @param {array} a
10496 */
10497async function foo(a) {
10498 return;
10499}
10500
10501/**
10502 *
10503 */
10504// Options: [{"contexts":["any"]}]
10505
10506/**
10507 * @async
10508 */
10509// Options: [{"contexts":["any"]}]
10510
10511/**
10512 * @function
10513 */
10514// Options: [{"forceRequireReturn":true}]
10515
10516/**
10517 * @callback
10518 */
10519// Options: [{"forceRequireReturn":true}]
10520
10521/**
10522 * @function
10523 * @async
10524 */
10525// Options: [{"forceReturnsWithAsync":true}]
10526
10527/**
10528 * @callback
10529 * @async
10530 */
10531// Options: [{"forceReturnsWithAsync":true}]
10532
10533/**
10534 * @function
10535 */
10536// Options: [{"contexts":["any"],"forceReturnsWithAsync":true}]
10537
10538/**
10539 * @callback
10540 */
10541// Options: [{"contexts":["any"],"forceReturnsWithAsync":true}]
10542````
10543
10544
10545<a name="eslint-plugin-jsdoc-rules-valid-types"></a>
10546### <code>valid-types</code>
10547
10548Requires all types to be valid JSDoc or Closure compiler types without syntax errors.
10549
10550Also impacts behaviors on namepath (or event)-defining and pointing tags:
10551
105521. Name(path)-defining tags requiring namepath: `@external`, `@host`, `@name`, `@typedef`
105531. Name(path)-defining tags (which may have value without namepath or their
10554 namepath can be expressed elsewhere on the block): `@event`, `@callback`,
10555 `@class`, `@constructor`, `@constant`, `@const`,
10556 `@function`, `@func`, `@method`, `@interface`, `@member`, `@var`,
10557 `@mixin`, `@namespace`
105581. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`, `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
105591. Name(path)-pointing tags (which may have value without namepath or their
10560 namepath can be expressed elsewhere on the block): `@listens`, `@fires`,
10561 `@emits`, and `@modifies`
105621. Name(path)-pointing tags (multiple names in one): `@borrows`
10563
10564...with the following applying to the above sets:
10565
10566- Expect tags in set 1-4 to have a valid namepath if present
10567- Prevent sets 2 and 4 from being empty by setting `allowEmptyNamepaths` to
10568 `false` as these tags might have some indicative value without a path
10569 or may allow a name expressed elsewhere on the block (but sets 1 and 3 will
10570 always fail if empty)
10571- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`,
10572 check that both namepaths are present and valid and ensure there is an `as `
10573 between them. In the case of `<this namepath>`, it can be preceded by
10574 one of the name path operators, `#`, `.`, or `~`.
10575- For the special case of `@memberof` and `@memberof!` (part of set 3), as
10576 per the [specification](https://jsdoc.app/tags-memberof.html), they also
10577 allow `#`, `.`, or `~` at the end (which is not allowed at the end of
10578 normal paths).
10579
10580<a name="eslint-plugin-jsdoc-rules-valid-types-options-27"></a>
10581#### Options
10582
10583- `allowEmptyNamepaths` (default: true) - Set to `false` to disallow
10584 empty name paths with `@callback`, `@event`, `@class`, `@constructor`,
10585 `@constant`, `@const`, `@function`, `@func`, `@method`, `@interface`,
10586 `@member`, `@var`, `@mixin`, `@namespace`, `@listens`, `@fires`,
10587 `@modifies`, or `@emits` (these might often be expected to have an
10588 accompanying name path, though they have some indicative value without
10589 one; these may also allow names to be defined in another manner elsewhere
10590 in the block)
10591- `checkSeesForNamepaths` (default: false) - Set this to `true` to insist
10592 that `@see` only use name paths (the tag is normally permitted to
10593 allow other text)
10594
10595
10596|||
10597|---|---|
10598|Context|everywhere|
10599|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), `this`, `throws` (for type), `type` (for type), `typedef` (for name and type), `yields` (for type)|
10600|Aliases|`extends`, `constructor`, `const`, `host`, `emits`, `func`, `method`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
10601|Closure-only|For type only: `package`, `private`, `protected`, `public`, `static`|
10602|Options|`allowEmptyNamepaths`, `checkSeesForNamepaths`|
10603|Settings|`mode`|
10604
10605The following patterns are considered problems:
10606
10607````js
10608/**
10609 * @param {Array<string} foo
10610 */
10611function quux() {
10612
10613}
10614// Message: Syntax error in type: Array<string
10615
10616/**
10617 * @memberof module:namespace.SomeClass<~
10618 */
10619function quux() {
10620
10621}
10622// Message: Syntax error in namepath: module:namespace.SomeClass<~
10623
10624/**
10625 * @memberof module:namespace.SomeClass~<
10626 */
10627function quux() {
10628
10629}
10630// Message: Syntax error in namepath: module:namespace.SomeClass~<
10631
10632/**
10633 * @borrows foo% as bar
10634 */
10635function quux() {
10636
10637}
10638// Message: Syntax error in namepath: foo%
10639
10640/**
10641 * @borrows #foo as bar
10642 */
10643function quux() {
10644
10645}
10646// Message: Syntax error in namepath: #foo
10647
10648/**
10649 * @borrows foo as bar%
10650 */
10651function quux() {
10652
10653}
10654// Message: Syntax error in namepath: bar%
10655
10656/**
10657 * @borrows foo
10658 */
10659function quux() {
10660
10661}
10662// Message: @borrows must have an "as" expression. Found ""
10663
10664/**
10665 * @see foo%
10666 */
10667function quux() {
10668
10669}
10670// Options: [{"checkSeesForNamepaths":true}]
10671// Message: Syntax error in namepath: foo%
10672
10673/** */
10674function foo() {}
10675// Settings: {"jsdoc":{"allowEmptyNamepaths":true,"checkSeesForNamepaths":true}}
10676// Message: `settings.jsdoc.allowEmptyNamepaths` has been removed, use options in the rule `valid-types` instead.
10677
10678/**
10679 * @alias module:abc#event:foo-bar
10680 */
10681function quux() {
10682
10683}
10684// Message: Syntax error in namepath: module:abc#event:foo-bar
10685
10686/**
10687 * @mixes module:namespace.SomeClass~
10688 */
10689function quux() {
10690
10691}
10692// Message: Syntax error in namepath: module:namespace.SomeClass~
10693
10694/**
10695 * @callback
10696 */
10697function quux() {
10698
10699}
10700// Options: [{"allowEmptyNamepaths":false}]
10701// Message: Tag @callback must have a name/namepath
10702
10703/**
10704 * @constant {str%ng}
10705 */
10706 const FOO = 'foo';
10707// Message: Syntax error in type: str%ng
10708
10709/**
10710 * @typedef {str%ng} UserString
10711 */
10712// Message: Syntax error in type: str%ng
10713
10714/**
10715 * @typedef {string} UserStr%ng
10716 */
10717// Message: Syntax error in namepath: UserStr%ng
10718
10719/**
10720 * @extends
10721 */
10722 class Bar {};
10723// Message: Tag @extends must have either a type or namepath
10724
10725/**
10726 * @type
10727 */
10728 let foo;
10729// Message: Tag @type must have a type
10730
10731/**
10732 * @modifies {bar|foo<}
10733 */
10734function quux (foo, bar, baz) {}
10735// Message: Syntax error in type: bar|foo<
10736
10737/**
10738 * @private {BadTypeChecked<}
10739 */
10740function quux () {}
10741// Settings: {"jsdoc":{"mode":"closure"}}
10742// Message: Syntax error in type: BadTypeChecked<
10743
10744/**
10745 * @this {BadTypeChecked<}
10746 */
10747function quux () {}
10748// Settings: {"jsdoc":{"mode":"closure"}}
10749// Message: Syntax error in type: BadTypeChecked<
10750
10751/**
10752 * @define
10753 */
10754 function quux () {}
10755// Settings: {"jsdoc":{"mode":"closure"}}
10756// Message: Tag @define must have a type
10757
10758/**
10759 * @this
10760 */
10761 let foo;
10762// Settings: {"jsdoc":{"mode":"closure"}}
10763// Message: Tag @this must have a type
10764````
10765
10766The following patterns are not considered problems:
10767
10768````js
10769/**
10770 * @param {Array<string>} foo
10771 */
10772function quux() {
10773
10774}
10775
10776/**
10777 * @param {string} foo
10778 */
10779function quux() {
10780
10781}
10782
10783/**
10784 * @param foo
10785 */
10786function quux() {
10787
10788}
10789
10790/**
10791 * @borrows foo as bar
10792 */
10793function quux() {
10794
10795}
10796
10797/**
10798 * @borrows foo as #bar
10799 */
10800function quux() {
10801
10802}
10803
10804/**
10805 * @see foo%
10806 */
10807function quux() {
10808
10809}
10810
10811/**
10812 * @alias module:namespace.SomeClass#event:ext_anevent
10813 */
10814function quux() {
10815
10816}
10817
10818/**
10819 * @callback foo
10820 */
10821function quux() {
10822
10823}
10824
10825/**
10826 * @callback
10827 */
10828function quux() {
10829
10830}
10831// Options: [{"allowEmptyNamepaths":true}]
10832
10833/**
10834 * @class
10835 */
10836function quux() {
10837
10838}
10839
10840/**
10841 * @see {@link foo}
10842 */
10843function quux() {
10844
10845}
10846// Options: [{"checkSeesForNamepaths":true}]
10847
10848/**
10849 *
10850 * @fires {module:namespace.SomeClass#event:ext_anevent}
10851 */
10852function quux() {
10853
10854}
10855
10856/**
10857 * @memberof module:namespace.SomeClass~
10858 */
10859function quux() {
10860
10861}
10862
10863/**
10864 * @memberof! module:namespace.SomeClass.
10865 */
10866function quux() {
10867
10868}
10869
10870/**
10871 *
10872 */
10873function quux() {
10874
10875}
10876
10877/**
10878 * @constant {string}
10879 */
10880 const FOO = 'foo';
10881
10882/**
10883 * @constant {string} FOO
10884 */
10885 const FOO = 'foo';
10886
10887/**
10888 * @extends Foo
10889 */
10890 class Bar {};
10891
10892/**
10893 * @extends {Foo<String>}
10894 */
10895 class Bar {};
10896
10897/**
10898 * @typedef {number|string} UserDefinedType
10899 */
10900
10901/**
10902 * @typedef {number|string}
10903 */
10904let UserDefinedGCCType;
10905
10906/**
10907 * @modifies {foo|bar}
10908 */
10909function quux (foo, bar, baz) {}
10910
10911/**
10912 * @private {BadTypeNotCheckedInJsdoc<}
10913 */
10914function quux () {}
10915
10916/**
10917 * @this {Navigator}
10918 */
10919function quux () {}
10920// Settings: {"jsdoc":{"mode":"closure"}}
10921
10922/**
10923 * @export {SomeType}
10924 */
10925function quux () {}
10926// Settings: {"jsdoc":{"mode":"closure"}}
10927
10928/**
10929 * @define {boolean}
10930 */
10931function quux () {}
10932// Settings: {"jsdoc":{"mode":"closure"}}
10933
10934/**
10935 * @define
10936 */
10937 function quux () {}
10938````
10939
10940
10941
\No newline at end of file