UNPKG

197 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|||
3915|---|---|
3916|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
3917|Tags|`implements` (prevented)|
3918
3919The following patterns are considered problems:
3920
3921````js
3922/**
3923 * @implements {SomeClass}
3924 */
3925function quux () {
3926
3927}
3928// Message: @implements used on a non-constructor function
3929
3930/**
3931 * @implements {SomeClass}
3932 */
3933function quux () {
3934
3935}
3936// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
3937// Message: Unexpected tag `@implements`
3938````
3939
3940The following patterns are not considered problems:
3941
3942````js
3943/**
3944 * @implements {SomeClass}
3945 * @class
3946 */
3947function quux () {
3948
3949}
3950
3951/**
3952 * @implements {SomeClass}
3953 * @constructor
3954 */
3955function quux () {
3956
3957}
3958
3959/**
3960 *
3961 */
3962class quux {
3963 /**
3964 * @implements {SomeClass}
3965 */
3966 constructor () {
3967
3968 }
3969}
3970
3971/**
3972 *
3973 */
3974const quux = class {
3975 /**
3976 * @implements {SomeClass}
3977 */
3978 constructor () {
3979
3980 }
3981}
3982
3983/**
3984 *
3985 */
3986function quux () {
3987
3988}
3989
3990/**
3991 *
3992 */
3993function quux () {
3994
3995}
3996// Settings: {"jsdoc":{"tagNamePreference":{"implements":false}}}
3997````
3998
3999
4000<a name="eslint-plugin-jsdoc-rules-match-description"></a>
4001### <code>match-description</code>
4002
4003Enforces a regular expression pattern on descriptions.
4004
4005The default is this basic expression to match English sentences (Support
4006for Unicode upper case may be added in a future version when it can be handled
4007by our supported Node versions):
4008
4009``^([A-Z]|[`\\d_])[\\s\\S]*[.?!`]$``
4010
4011Applies to the jsdoc block description and `@description` (or `@desc`)
4012by default but the `tags` option (see below) may be used to match other tags.
4013
4014<a name="eslint-plugin-jsdoc-rules-match-description-options-9"></a>
4015#### Options
4016
4017<a name="eslint-plugin-jsdoc-rules-match-description-options-9-matchdescription"></a>
4018##### <code>matchDescription</code>
4019
4020You can supply your own expression to override the default, passing a
4021`matchDescription` string on the options object.
4022
4023```js
4024{
4025 'jsdoc/match-description': ['error', {matchDescription: '[A-Z].*\\.'}]
4026}
4027```
4028
4029As with the default, the supplied regular expression will be applied with the
4030Unicode (`"u"`) flag and is *not* case-insensitive.
4031
4032<a name="eslint-plugin-jsdoc-rules-match-description-options-9-tags-1"></a>
4033##### <code>tags</code>
4034
4035If you want different regular expressions to apply to tags, you may use
4036the `tags` option object:
4037
4038```js
4039{
4040 'jsdoc/match-description': ['error', {tags: {
4041 param: '\\- [A-Z].*\\.',
4042 returns: '[A-Z].*\\.'
4043 }}]
4044}
4045```
4046
4047In place of a string, you can also add `true` to indicate that a particular
4048tag should be linted with the `matchDescription` value (or the default).
4049
4050```js
4051{
4052 'jsdoc/match-description': ['error', {tags: {
4053 param: true,
4054 returns: true
4055 }}]
4056}
4057```
4058
4059The tags `@param`/`@arg`/`@argument` and `@property`/`@prop` will be properly
4060parsed to ensure that the matched "description" text includes only the text
4061after the name.
4062
4063All other tags will treat the text following the tag name, a space, and
4064an optional curly-bracketed type expression (and another space) as part of
4065its "description" (e.g., for `@returns {someType} some description`, the
4066description is `some description` while for `@some-tag xyz`, the description
4067is `xyz`).
4068
4069<a name="eslint-plugin-jsdoc-rules-match-description-options-9-maindescription"></a>
4070##### <code>mainDescription</code>
4071
4072If you wish to override the main function description without changing the
4073default `match-description`, you may use `mainDescription`:
4074
4075```js
4076{
4077 'jsdoc/match-description': ['error', {
4078 mainDescription: '[A-Z].*\\.',
4079 tags: {
4080 param: true,
4081 returns: true
4082 }
4083 }]
4084}
4085```
4086
4087There is no need to add `mainDescription: true`, as by default, the main
4088function (and only the main function) is linted, though you may disable checking
4089it by setting it to `false`.
4090
4091<a name="eslint-plugin-jsdoc-rules-match-description-options-9-contexts"></a>
4092##### <code>contexts</code>
4093
4094Set this to an array of strings representing the AST context
4095where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6 classes).
4096Overrides the default contexts (see below). Set to `"any"` if you want
4097the rule to apply to any jsdoc block throughout your files.
4098
4099|||
4100|---|---|
4101|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
4102|Tags|docblock and `@description` by default but more with `tags`|
4103|Aliases|`@desc`|
4104|Settings||
4105|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`|
4106
4107The following patterns are considered problems:
4108
4109````js
4110/**
4111 * foo.
4112 */
4113const q = class {
4114
4115}
4116// Options: [{"contexts":["ClassExpression"]}]
4117// Message: JSDoc description does not satisfy the regex pattern.
4118
4119/**
4120 * foo.
4121 */
4122// Options: [{"contexts":["any"]}]
4123// Message: JSDoc description does not satisfy the regex pattern.
4124
4125/**
4126 * foo.
4127 */
4128// Options: [{"contexts":["any"]}]
4129// Message: JSDoc description does not satisfy the regex pattern.
4130
4131/**
4132 * foo.
4133 */
4134const q = {
4135
4136};
4137// Options: [{"contexts":["ObjectExpression"]}]
4138// Message: JSDoc description does not satisfy the regex pattern.
4139
4140/**
4141 * foo.
4142 */
4143function quux () {
4144
4145}
4146// Message: JSDoc description does not satisfy the regex pattern.
4147
4148/**
4149 * Foo)
4150 */
4151function quux () {
4152
4153}
4154// Message: JSDoc description does not satisfy the regex pattern.
4155
4156/**
4157 * тест.
4158 */
4159function quux () {
4160
4161}
4162// Options: [{"matchDescription":"[А-Я][А-я]+\\."}]
4163// Message: JSDoc description does not satisfy the regex pattern.
4164
4165/**
4166 * Abc.
4167 */
4168function quux () {
4169
4170}
4171// Options: [{"mainDescription":"[А-Я][А-я]+\\.","tags":{"param":true}}]
4172// Message: JSDoc description does not satisfy the regex pattern.
4173
4174/**
4175 * Foo
4176 */
4177function quux () {
4178
4179}
4180// Message: JSDoc description does not satisfy the regex pattern.
4181
4182/**
4183 * Foo.
4184 *
4185 * @param foo foo.
4186 */
4187function quux (foo) {
4188
4189}
4190// Options: [{"tags":{"param":true}}]
4191// Message: JSDoc description does not satisfy the regex pattern.
4192
4193/**
4194 * Foo.
4195 *
4196 * @prop foo foo.
4197 */
4198function quux (foo) {
4199
4200}
4201// Options: [{"tags":{"prop":true}}]
4202// Message: JSDoc description does not satisfy the regex pattern.
4203
4204/**
4205 * Foo.
4206 *
4207 * @summary foo.
4208 */
4209function quux () {
4210
4211}
4212// Options: [{"tags":{"summary":true}}]
4213// Message: JSDoc description does not satisfy the regex pattern.
4214
4215/**
4216 * Foo.
4217 *
4218 * @author
4219 */
4220function quux () {
4221
4222}
4223// Options: [{"tags":{"author":".+"}}]
4224// Message: JSDoc description does not satisfy the regex pattern.
4225
4226/**
4227 * Foo.
4228 *
4229 * @x-tag
4230 */
4231function quux () {
4232
4233}
4234// Options: [{"tags":{"x-tag":".+"}}]
4235// Message: JSDoc description does not satisfy the regex pattern.
4236
4237/**
4238 * Foo.
4239 *
4240 * @description foo foo.
4241 */
4242function quux (foo) {
4243
4244}
4245// Options: [{"tags":{"description":true}}]
4246// Message: JSDoc description does not satisfy the regex pattern.
4247
4248/**
4249 * Foo
4250 *
4251 * @param foo foo.
4252 */
4253function quux (foo) {
4254
4255}
4256// Options: [{"mainDescription":"^[a-zA-Z]*$","tags":{"param":true}}]
4257// Message: JSDoc description does not satisfy the regex pattern.
4258
4259/**
4260 * Foo
4261 *
4262 * @param foo foo.
4263 */
4264function quux (foo) {
4265
4266}
4267// Options: [{"mainDescription":false,"tags":{"param":true}}]
4268// Message: JSDoc description does not satisfy the regex pattern.
4269
4270/**
4271 * Foo.
4272 *
4273 * @param foo bar
4274 */
4275function quux (foo) {
4276
4277}
4278// Options: [{"tags":{"param":true}}]
4279// Message: JSDoc description does not satisfy the regex pattern.
4280
4281/**
4282 * {@see Foo.bar} buz
4283 */
4284function quux (foo) {
4285
4286}
4287// Message: JSDoc description does not satisfy the regex pattern.
4288
4289/**
4290 * Foo.
4291 *
4292 * @returns {number} foo
4293 */
4294function quux (foo) {
4295
4296}
4297// Options: [{"tags":{"returns":true}}]
4298// Message: JSDoc description does not satisfy the regex pattern.
4299
4300/**
4301 * Foo.
4302 *
4303 * @returns foo.
4304 */
4305function quux (foo) {
4306
4307}
4308// Options: [{"tags":{"returns":true}}]
4309// Message: JSDoc description does not satisfy the regex pattern.
4310
4311/**
4312 * lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
4313 * iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
4314 * tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
4315 * vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
4316 * proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
4317 * consequat auctor magna. duis pharetra purus in porttitor mollis.
4318 */
4319function longDescription (foo) {
4320
4321}
4322// Message: JSDoc description does not satisfy the regex pattern.
4323
4324/**
4325 * @arg {number} foo - Foo
4326 */
4327function quux (foo) {
4328
4329}
4330// Options: [{"tags":{"arg":true}}]
4331// Message: JSDoc description does not satisfy the regex pattern.
4332
4333/**
4334 * @argument {number} foo - Foo
4335 */
4336function quux (foo) {
4337
4338}
4339// Options: [{"tags":{"argument":true}}]
4340// Message: JSDoc description does not satisfy the regex pattern.
4341
4342/**
4343 * @return {number} foo
4344 */
4345function quux (foo) {
4346
4347}
4348// Options: [{"tags":{"return":true}}]
4349// Message: JSDoc description does not satisfy the regex pattern.
4350
4351/**
4352 * Returns bar.
4353 *
4354 * @return {number} bar
4355 */
4356function quux (foo) {
4357
4358}
4359// Options: [{"tags":{"return":true}}]
4360// Message: JSDoc description does not satisfy the regex pattern.
4361
4362/**
4363 * @param notRet
4364 * @returns Тест.
4365 */
4366function quux () {
4367
4368}
4369// Options: [{"tags":{"param":"[А-Я][А-я]+\\."}}]
4370// Message: JSDoc description does not satisfy the regex pattern.
4371
4372/**
4373 * @description notRet
4374 * @returns Тест.
4375 */
4376function quux () {
4377
4378}
4379// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
4380// Message: JSDoc description does not satisfy the regex pattern.
4381
4382/**
4383 * foo.
4384 */
4385class quux {
4386
4387}
4388// Options: [{"contexts":["ClassDeclaration"]}]
4389// Message: JSDoc description does not satisfy the regex pattern.
4390
4391class MyClass {
4392 /**
4393 * Abc
4394 */
4395 myClassField = 1
4396}
4397// Options: [{"contexts":["ClassProperty"]}]
4398// Message: JSDoc description does not satisfy the regex pattern.
4399
4400/**
4401 * foo.
4402 */
4403interface quux {
4404
4405}
4406// Options: [{"contexts":["TSInterfaceDeclaration"]}]
4407// Message: JSDoc description does not satisfy the regex pattern.
4408
4409const myObject = {
4410 /**
4411 * Bad description
4412 */
4413 myProp: true
4414};
4415// Options: [{"contexts":["Property"]}]
4416// Message: JSDoc description does not satisfy the regex pattern.
4417
4418/**
4419 * @param foo Foo bar
4420 */
4421function quux (foo) {
4422
4423}
4424// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4425// Options: [{"tags":{"param":true}}]
4426// Message: JSDoc description does not satisfy the regex pattern.
4427
4428/**
4429 * Foo bar
4430 */
4431function quux (foo) {
4432
4433}
4434// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4435// Message: JSDoc description does not satisfy the regex pattern.
4436````
4437
4438The following patterns are not considered problems:
4439
4440````js
4441/**
4442 *
4443 */
4444
4445/**
4446 *
4447 */
4448 function quux () {
4449
4450 }
4451
4452/**
4453 * @param foo - Foo.
4454 */
4455function quux () {
4456
4457}
4458// Options: [{"tags":{"param":true}}]
4459
4460/**
4461 * Foo.
4462 */
4463function quux () {
4464
4465}
4466
4467/**
4468 * Foo.
4469 * Bar.
4470 */
4471function quux () {
4472
4473}
4474
4475/**
4476 * Foo.
4477 *
4478 * Bar.
4479 */
4480function quux () {
4481
4482}
4483
4484/**
4485 * Тест.
4486 */
4487function quux () {
4488
4489}
4490// Options: [{"matchDescription":"[А-Я][А-я]+\\."}]
4491
4492/**
4493 * @param notRet
4494 * @returns Тест.
4495 */
4496function quux () {
4497
4498}
4499// Options: [{"tags":{"returns":"[А-Я][А-я]+\\."}}]
4500
4501/**
4502 * @param notRet
4503 * @description Тест.
4504 */
4505function quux () {
4506
4507}
4508// Options: [{"tags":{"description":"[А-Я][А-я]+\\."}}]
4509
4510/**
4511 * Foo
4512 * bar.
4513 */
4514function quux () {
4515
4516}
4517
4518/**
4519 * @returns Foo bar.
4520 */
4521function quux () {
4522
4523}
4524// Options: [{"tags":{"returns":true}}]
4525
4526/**
4527 * @returns {type1} Foo bar.
4528 */
4529function quux () {
4530
4531}
4532// Options: [{"tags":{"returns":true}}]
4533
4534/**
4535 * @description Foo bar.
4536 */
4537function quux () {
4538
4539}
4540// Options: [{"tags":{"description":true}}]
4541
4542/**
4543 * Foo. {@see Math.sin}.
4544 */
4545function quux () {
4546
4547}
4548
4549/**
4550 * Foo {@see Math.sin} bar.
4551 */
4552function quux () {
4553
4554}
4555
4556/**
4557 * Foo?
4558 *
4559 * Bar!
4560 *
4561 * Baz:
4562 * 1. Foo.
4563 * 2. Bar.
4564 */
4565function quux () {
4566
4567}
4568
4569/**
4570 * Hello:
4571 * World.
4572 */
4573function quux () {
4574
4575}
4576
4577/**
4578 * Hello: world.
4579 */
4580function quux () {
4581
4582}
4583
4584/**
4585 * Foo
4586 * Bar.
4587 */
4588function quux () {
4589
4590}
4591
4592/**
4593 * Foo.
4594 *
4595 * foo.
4596 */
4597function quux () {
4598
4599}
4600
4601/**
4602 * foo.
4603 */
4604function quux () {
4605
4606}
4607// Options: [{"mainDescription":false}]
4608
4609/**
4610 * foo.
4611 */
4612class quux {
4613
4614}
4615
4616/**
4617 * foo.
4618 */
4619class quux {
4620
4621}
4622// Options: [{"mainDescription":true}]
4623
4624class MyClass {
4625 /**
4626 * Abc.
4627 */
4628 myClassField = 1
4629}
4630// Options: [{"contexts":["ClassProperty"]}]
4631
4632/**
4633 * Foo.
4634 */
4635interface quux {
4636
4637}
4638// Options: [{"contexts":["TSInterfaceDeclaration"]}]
4639
4640const myObject = {
4641 /**
4642 * Bad description
4643 */
4644 myProp: true
4645};
4646// Options: [{"contexts":[]}]
4647
4648/**
4649 * foo.
4650 */
4651const q = class {
4652
4653}
4654// Options: [{"contexts":[]}]
4655
4656/**
4657 * foo.
4658 */
4659const q = {
4660
4661};
4662// Options: [{"contexts":[]}]
4663
4664/**
4665 * @description foo.
4666 */
4667function quux () {
4668
4669}
4670// Options: [{"tags":{"param":true}}]
4671
4672/**
4673 * Foo.
4674 *
4675 * @summary Foo.
4676 */
4677function quux () {
4678
4679}
4680// Options: [{"tags":{"summary":true}}]
4681
4682/**
4683 * Foo.
4684 *
4685 * @author Somebody
4686 */
4687function quux () {
4688
4689}
4690// Options: [{"tags":{"author":".+"}}]
4691
4692/**
4693 * Foo.
4694 *
4695 * @x-tag something
4696 */
4697function quux () {
4698
4699}
4700// Options: [{"tags":{"x-tag":".+"}}]
4701
4702/**
4703 * Foo.
4704 *
4705 * @prop foo Foo.
4706 */
4707function quux (foo) {
4708
4709}
4710// Options: [{"tags":{"prop":true}}]
4711
4712/**
4713 * @param foo Foo bar.
4714 */
4715function quux (foo) {
4716
4717}
4718// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4719
4720/**
4721 *
4722 */
4723function quux () {
4724
4725}
4726// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
4727````
4728
4729
4730<a name="eslint-plugin-jsdoc-rules-newline-after-description"></a>
4731### <code>newline-after-description</code>
4732
4733Enforces a consistent padding of the block description.
4734
4735<a name="eslint-plugin-jsdoc-rules-newline-after-description-options-10"></a>
4736#### Options
4737
4738This 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"`.
4739
4740|||
4741|---|---|
4742|Context|everywhere|
4743|Options|(a string matching `"always"|"never"`)|
4744|Tags|N/A (doc block)|
4745
4746The following patterns are considered problems:
4747
4748````js
4749/**
4750 * Foo.
4751 *
4752 * Foo.
4753 * @foo
4754 */
4755function quux () {
4756
4757}
4758// Options: ["always"]
4759// Message: There must be a newline after the description of the JSDoc block.
4760
4761/**
4762 * Foo.
4763 * @foo
4764 *
4765 * Foo.
4766 */
4767function quux () {
4768
4769}
4770// Options: ["always"]
4771// Message: There must be a newline after the description of the JSDoc block.
4772
4773/**
4774 * Foo.
4775 *
4776 * Foo.
4777 * @foo
4778 */
4779function quux () {
4780
4781}
4782// Message: There must be a newline after the description of the JSDoc block.
4783
4784/**
4785 * Bar.
4786 *
4787 * Bar.
4788 *
4789 * @bar
4790 */
4791function quux () {
4792
4793}
4794// Options: ["never"]
4795// Message: There must be no newline after the description of the JSDoc block.
4796
4797/**
4798 * Bar.
4799 *
4800 * @bar
4801 *
4802 * Bar.
4803 */
4804function quux () {
4805
4806}
4807// Options: ["never"]
4808// Message: There must be no newline after the description of the JSDoc block.
4809
4810
4811 /**
4812 * Bar.
4813 *
4814 * Bar.
4815 *
4816 * @bar
4817 */
4818 function quux () {
4819
4820 }
4821// Options: ["never"]
4822// Message: There must be no newline after the description of the JSDoc block.
4823
4824/**
4825 * A.
4826 *
4827 * @typedef {object} A
4828 * @prop {boolean} a A.
4829 */
4830// Options: ["never"]
4831// Message: There must be no newline after the description of the JSDoc block.
4832
4833/**
4834 * A.
4835 * @typedef {object} A
4836 * @prop {boolean} a A.
4837 */
4838// Options: ["always"]
4839// Message: There must be a newline after the description of the JSDoc block.
4840
4841
4842 /**
4843 * Service for fetching symbols.
4844 * @param {object} $http - Injected http helper.
4845 * @param {object} $q - Injected Promise api helper.
4846 * @param {object} $location - Injected window location object.
4847 * @param {object} REPORT_DIALOG_CONSTANTS - Injected handle.
4848 */
4849// Message: There must be a newline after the description of the JSDoc block.
4850````
4851
4852The following patterns are not considered problems:
4853
4854````js
4855/**
4856 * Foo.
4857 */
4858function quux () {
4859
4860}
4861// Options: ["always"]
4862
4863/**
4864 * Bar.
4865 */
4866function quux () {
4867
4868}
4869// Options: ["never"]
4870
4871/**
4872 * Foo.
4873 *
4874 * @foo
4875 */
4876function quux () {
4877
4878}
4879// Options: ["always"]
4880
4881/**
4882 * Bar.
4883 * @bar
4884 */
4885function quux () {
4886
4887}
4888// Options: ["never"]
4889
4890
4891 /**
4892 * @foo
4893 * Test 
4894 * abc 
4895 * @bar 
4896 */
4897
4898
4899 /**
4900 *
4901 * @foo
4902 * Test 
4903 * abc 
4904 * @bar 
4905 */
4906
4907/***
4908 *
4909 */
4910function quux () {
4911
4912}
4913// Options: ["always"]
4914
4915/**
4916 * Parses query string to object containing URL parameters
4917 *
4918 * @param queryString
4919 * Input string
4920 *
4921 * @returns
4922 * Object containing URL parameters
4923 */
4924export function parseQueryString(queryString: string): { [key: string]: string } { // <-- Line 10 that fails
4925
4926}
4927````
4928
4929
4930<a name="eslint-plugin-jsdoc-rules-no-types"></a>
4931### <code>no-types</code>
4932
4933This rule reports types being used on `@param` or `@returns`.
4934
4935The rule is intended to prevent the indication of types on tags where
4936the type information would be redundant with TypeScript.
4937
4938|||
4939|---|---|
4940|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
4941|Tags|`param`, `returns`|
4942|Aliases|`arg`, `argument`, `return`|
4943
4944The following patterns are considered problems:
4945
4946````js
4947/**
4948 * @param {number} foo
4949 */
4950function quux (foo) {
4951
4952}
4953// Message: Types are not permitted on @param.
4954
4955/**
4956 * @returns {number}
4957 */
4958function quux () {
4959
4960}
4961// Message: Types are not permitted on @returns.
4962````
4963
4964The following patterns are not considered problems:
4965
4966````js
4967/**
4968 * @param foo
4969 */
4970function quux (foo) {
4971
4972}
4973````
4974
4975
4976<a name="eslint-plugin-jsdoc-rules-no-undefined-types"></a>
4977### <code>no-undefined-types</code>
4978
4979Checks that types in jsdoc comments are defined. This can be used to check
4980unimported types.
4981
4982When enabling this rule, types in jsdoc comments will resolve as used
4983variables, i.e. will not be marked as unused by `no-unused-vars`.
4984
4985In addition to considering globals found in code (or in ESLint-indicated
4986`globals`) as defined, the following tags will also be checked for
4987name(path) definitions to also serve as a potential "type" for checking
4988the tag types in the table below:
4989
4990`@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`.
4991
4992The following tags will also be checked but only when the mode is `closure`:
4993
4994`@package`, `@private`, `@protected`, `@public`, `@static`
4995
4996The following types are always considered defined.
4997
4998- `null`, `undefined`, `void`, `string`, `boolean`, `object`, `function`
4999- `number`, `NaN`, `Infinity`
5000- `any`, `*`
5001- `Array`, `Object`, `RegExp`, `Date`, `Function`
5002
5003Note that preferred types indicated within `settings.jsdoc.preferredTypes` will
5004also be assumed to be defined.
5005
5006<a name="eslint-plugin-jsdoc-rules-no-undefined-types-options-11"></a>
5007#### Options
5008
5009An option object may have the following key:
5010
5011- `definedTypes` - This array can be populated to indicate other types which
5012 are automatically considered as defined (in addition to globals, etc.).
5013 Defaults to an empty array.
5014
5015|||
5016|---|---|
5017|Context|everywhere|
5018|Tags|`augments`, `class`, `constant`, `enum`, `implements`, `member`, `module`, `namespace`, `param`, `property`, `returns`, `throws`, `type`, `typedef`, `yields`|
5019|Aliases|`constructor`, `const`, `extends`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
5020|Closure-only|`package`, `private`, `protected`, `public`, `static`|
5021|Options|`definedTypes`|
5022|Settings|`preferredTypes`, `mode`|
5023
5024The following patterns are considered problems:
5025
5026````js
5027/**
5028 * @param {HerType} baz - Foo.
5029 */
5030function quux(foo, bar, baz) {
5031
5032}
5033// Settings: {"jsdoc":{"preferredTypes":{"HerType":1000}}}
5034// Message: Invalid `settings.jsdoc.preferredTypes`. Values must be falsy, a string, or an object.
5035
5036/**
5037 * @param {HerType} baz - Foo.
5038 */
5039function quux(foo, bar, baz) {
5040
5041}
5042// Settings: {"jsdoc":{"preferredTypes":{"HerType":false}}}
5043// Message: The type 'HerType' is undefined.
5044
5045/**
5046 * @param {strnig} foo - Bar.
5047 */
5048function quux(foo) {
5049
5050}
5051// Message: The type 'strnig' is undefined.
5052
5053/**
5054 * @param {MyType} foo - Bar.
5055 * @param {HisType} bar - Foo.
5056 */
5057function quux(foo, bar) {
5058
5059}
5060// Options: [{"definedTypes":["MyType"]}]
5061// Message: The type 'HisType' is undefined.
5062
5063/**
5064 * @param {MyType} foo - Bar.
5065 * @param {HisType} bar - Foo.
5066 * @param {HerType} baz - Foo.
5067 */
5068function quux(foo, bar, baz) {
5069
5070}
5071// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"}}}}
5072// Options: [{"definedTypes":["MyType"]}]
5073// Message: The type 'HisType' is undefined.
5074
5075 /**
5076 * @param {MyType} foo - Bar.
5077 * @param {HisType} bar - Foo.
5078 * @param {HerType} baz - Foo.
5079 */
5080function quux(foo, bar, baz) {
5081
5082}
5083// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":false},"histype":"HisType"}}}
5084// Options: [{"definedTypes":["MyType"]}]
5085// Message: The type 'HerType' is undefined.
5086
5087/**
5088 * @template TEMPLATE_TYPE
5089 * @param {WRONG_TEMPLATE_TYPE} bar
5090 */
5091function foo (bar) {
5092};
5093// Settings: {"jsdoc":{"mode":"closure"}}
5094// Message: The type 'WRONG_TEMPLATE_TYPE' is undefined.
5095
5096class Foo {
5097 /**
5098 * @return {TEMPLATE_TYPE}
5099 */
5100 bar () {
5101 }
5102}
5103// Message: The type 'TEMPLATE_TYPE' is undefined.
5104
5105class Foo {
5106 /**
5107 * @return {TEMPLATE_TYPE}
5108 */
5109 invalidTemplateReference () {
5110 }
5111}
5112
5113/**
5114 * @template TEMPLATE_TYPE
5115 */
5116class Bar {
5117 /**
5118 * @return {TEMPLATE_TYPE}
5119 */
5120 validTemplateReference () {
5121 }
5122}
5123// Settings: {"jsdoc":{"mode":"typescript"}}
5124// Message: The type 'TEMPLATE_TYPE' is undefined.
5125
5126/**
5127 * @type {strnig}
5128 */
5129var quux = {
5130
5131};
5132// Message: The type 'strnig' is undefined.
5133
5134/**
5135 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
5136 */
5137class Foo {
5138 /**
5139 * @param {TEMPLATE_TYPE_A} baz
5140 * @return {TEMPLATE_TYPE_B}
5141 */
5142 bar (baz) {
5143 }
5144}
5145// Message: The type 'TEMPLATE_TYPE_A' is undefined.
5146
5147/**
5148 * @param {...VAR_TYPE} varargs
5149 */
5150function quux (varargs) {
5151}
5152// Message: The type 'VAR_TYPE' is undefined.
5153
5154/**
5155 * @this {Navigator}
5156 */
5157function quux () {}
5158// Settings: {"jsdoc":{"mode":"closure"}}
5159// Message: The type 'Navigator' is undefined.
5160
5161/**
5162 * @export {SomeType}
5163 */
5164function quux () {}
5165// Settings: {"jsdoc":{"mode":"closure"}}
5166// Message: The type 'SomeType' is undefined.
5167````
5168
5169The following patterns are not considered problems:
5170
5171````js
5172/**
5173 * @param {string} foo - Bar.
5174 */
5175function quux(foo) {
5176
5177}
5178
5179/**
5180 * @param {Promise} foo - Bar.
5181 */
5182function quux(foo) {
5183
5184}
5185
5186class MyClass {}
5187
5188/**
5189 * @param {MyClass} foo - Bar.
5190 */
5191function quux(foo) {
5192 console.log(foo);
5193}
5194
5195quux(0);
5196
5197const MyType = require('my-library').MyType;
5198
5199/**
5200 * @param {MyType} foo - Bar.
5201 */
5202 function quux(foo) {
5203
5204}
5205
5206const MyType = require('my-library').MyType;
5207
5208/**
5209 * @param {MyType} foo - Bar.
5210 */
5211 function quux(foo) {
5212
5213}
5214
5215import {MyType} from 'my-library';
5216
5217/**
5218 * @param {MyType} foo - Bar.
5219 * @param {object<string, number>} foo
5220 * @param {Array<string>} baz
5221 */
5222 function quux(foo, bar, baz) {
5223
5224}
5225
5226/*globals MyType*/
5227
5228/**
5229 * @param {MyType} foo - Bar.
5230 * @param {HisType} bar - Foo.
5231 */
5232 function quux(foo, bar) {
5233
5234}
5235
5236/**
5237 * @typedef {object} hello
5238 * @property {string} a - a.
5239 */
5240
5241/**
5242 * @param {hello} foo
5243 */
5244function quux(foo) {
5245
5246}
5247
5248/**
5249 * @param {Array<syntaxError} foo
5250 */
5251function quux(foo) {
5252
5253}
5254
5255/**
5256 * Callback test.
5257 *
5258 * @callback addStuffCallback
5259 * @param {String} sum - An test integer.
5260 */
5261/**
5262 * Test Eslint.
5263 *
5264 * @param {addStuffCallback} callback - A callback to run.
5265 */
5266function testFunction(callback) {
5267 callback();
5268}
5269
5270/**
5271 *
5272 *
5273 */
5274function foo () {
5275
5276}
5277
5278/**
5279 *
5280 *
5281 */
5282function foo () {
5283
5284}
5285
5286/**
5287 * @param {MyType} foo - Bar.
5288 * @param {HisType} bar - Foo.
5289 */
5290function quux(foo, bar) {
5291
5292}
5293// Options: [{"definedTypes":["MyType","HisType"]}]
5294
5295/**
5296 * @param {MyType} foo - Bar.
5297 * @param {HisType} bar - Foo.
5298 * @param {HerType} baz - Foo.
5299 */
5300function quux(foo, bar, baz) {
5301
5302}
5303// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType"},"histype":"HisType"}}}
5304// Options: [{"definedTypes":["MyType"]}]
5305
5306/**
5307 * @param {MyType} foo - Bar.
5308 * @param {HisType} bar - Foo.
5309 * @param {HerType} baz - Foo.
5310 */
5311function quux(foo, bar, baz) {
5312
5313}
5314// Settings: {"jsdoc":{"preferredTypes":{"hertype":{"replacement":"HerType<>"},"histype":"HisType.<>"}}}
5315// Options: [{"definedTypes":["MyType"]}]
5316
5317/**
5318 * @template TEMPLATE_TYPE
5319 * @param {TEMPLATE_TYPE} bar
5320 * @return {TEMPLATE_TYPE}
5321 */
5322function foo (bar) {
5323};
5324// Settings: {"jsdoc":{"mode":"closure"}}
5325
5326/**
5327 * @template TEMPLATE_TYPE
5328 */
5329class Foo {
5330 /**
5331 * @return {TEMPLATE_TYPE}
5332 */
5333 bar () {
5334 }
5335}
5336// Settings: {"jsdoc":{"mode":"closure"}}
5337
5338/**
5339 * @template TEMPLATE_TYPE
5340 */
5341class Foo {
5342 /**
5343 * @return {TEMPLATE_TYPE}
5344 */
5345 bar () {}
5346
5347 /**
5348 * @return {TEMPLATE_TYPE}
5349 */
5350 baz () {}
5351}
5352// Settings: {"jsdoc":{"mode":"closure"}}
5353
5354/**
5355 * @template TEMPLATE_TYPE_A, TEMPLATE_TYPE_B
5356 */
5357class Foo {
5358 /**
5359 * @param {TEMPLATE_TYPE_A} baz
5360 * @return {TEMPLATE_TYPE_B}
5361 */
5362 bar (baz) {
5363 }
5364}
5365// Settings: {"jsdoc":{"mode":"closure"}}
5366
5367/****/
5368
5369/**
5370 *
5371 */
5372function quux () {
5373
5374}
5375
5376/**
5377 * Run callback when hooked method is called.
5378 *
5379 * @template {BaseObject} T
5380 * @param {T} obj - object whose method should be hooked.
5381 * @param {string} method - method which should be hooked.
5382 * @param {(sender: T) => void} callback - callback which should
5383 * be called when the hooked method was invoked.
5384 */
5385function registerEvent(obj, method, callback) {
5386
5387}
5388// Settings: {"jsdoc":{"mode":"typescript"}}
5389
5390 /**
5391 * @param {...} varargs
5392 */
5393function quux (varargs) {
5394}
5395
5396/**
5397 * @param {...number} varargs
5398 */
5399function quux (varargs) {
5400}
5401
5402class Navigator {}
5403/**
5404 * @this {Navigator}
5405 */
5406function quux () {}
5407// Settings: {"jsdoc":{"mode":"closure"}}
5408
5409class SomeType {}
5410/**
5411 * @export {SomeType}
5412 */
5413function quux () {}
5414// Settings: {"jsdoc":{"mode":"closure"}}
5415````
5416
5417
5418<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence"></a>
5419### <code>require-description-complete-sentence</code>
5420
5421Requires that block description, explicit `@description`, and `@param`/`@returns`
5422tag descriptions are written in complete sentences, i.e.,
5423
5424* Description must start with an uppercase alphabetical character.
5425* Paragraphs must start with an uppercase alphabetical character.
5426* Sentences must end with a period.
5427* Every line in a paragraph (except the first) which starts with an uppercase
5428 character must be preceded by a line ending with a period.
5429* A colon or semi-colon followed by two line breaks is still part of the
5430 containing paragraph (unlike normal dual line breaks).
5431* Text within inline tags `{...}` are not checked for sentence divisions.
5432* Periods after items within the `abbreviations` option array are not treated
5433 as sentence endings.
5434
5435<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-12"></a>
5436#### Options
5437
5438<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-12-tags-2"></a>
5439##### <code>tags</code>
5440
5441If you want additional tags to be checked for their descriptions, you may
5442add them within this option.
5443
5444```js
5445{
5446 'jsdoc/require-description-complete-sentence': ['error', {tags: ['see', 'copyright']}]
5447}
5448```
5449
5450The tags `@param`/`@arg`/`@argument` and `@property`/`@prop` will be properly
5451parsed to ensure that the checked "description" text includes only the text
5452after the name.
5453
5454All other tags will treat the text following the tag name, a space, and
5455an optional curly-bracketed type expression (and another space) as part of
5456its "description" (e.g., for `@returns {someType} some description`, the
5457description is `some description` while for `@some-tag xyz`, the description
5458is `xyz`).
5459
5460<a name="eslint-plugin-jsdoc-rules-require-description-complete-sentence-options-12-abbreviations"></a>
5461##### <code>abbreviations</code>
5462
5463You can provide an `abbreviations` options array to avoid such strings of text
5464being treated as sentence endings when followed by dots. The `.` is not
5465necessary at the end of the array items.
5466
5467|||
5468|---|---|
5469|Context|everywhere|
5470|Tags|doc block, `param`, `returns`, `description`, `property`, `summary`, `file`, `classdesc`, `todo`, `deprecated`, `throws`, 'yields' and others added by `tags`|
5471|Aliases|`arg`, `argument`, `return`, `desc`, `prop`, `fileoverview`, `overview`, `exception`, `yield`|
5472|Options|`tags`, `abbreviations`|
5473The following patterns are considered problems:
5474
5475````js
5476/**
5477 * foo.
5478 */
5479function quux () {
5480
5481}
5482// Message: Sentence should start with an uppercase character.
5483
5484/**
5485 * foo?
5486 */
5487function quux () {
5488
5489}
5490// Message: Sentence should start with an uppercase character.
5491
5492/**
5493 * @description foo.
5494 */
5495function quux () {
5496
5497}
5498// Message: Sentence should start with an uppercase character.
5499
5500/**
5501 * Foo)
5502 */
5503function quux () {
5504
5505}
5506// Message: Sentence must end with a period.
5507
5508/**
5509 * `foo` is a variable
5510 */
5511function quux () {
5512
5513}
5514// Message: Sentence must end with a period.
5515
5516/**
5517 * Foo.
5518 *
5519 * foo.
5520 */
5521function quux () {
5522
5523}
5524// Message: Sentence should start with an uppercase character.
5525
5526/**
5527 * тест.
5528 */
5529function quux () {
5530
5531}
5532// Message: Sentence should start with an uppercase character.
5533
5534/**
5535 * Foo
5536 */
5537function quux () {
5538
5539}
5540// Message: Sentence must end with a period.
5541
5542/**
5543 * Foo
5544 * Bar.
5545 */
5546function quux () {
5547
5548}
5549// Message: A line of text is started with an uppercase character, but preceding line does not end the sentence.
5550
5551/**
5552 * Foo.
5553 *
5554 * @param foo foo.
5555 */
5556function quux (foo) {
5557
5558}
5559// Message: Sentence should start with an uppercase character.
5560
5561/**
5562 * Foo.
5563 *
5564 * @param foo bar
5565 */
5566function quux (foo) {
5567
5568}
5569// Message: Sentence should start with an uppercase character.
5570
5571/**
5572 * {@see Foo.bar} buz
5573 */
5574function quux (foo) {
5575
5576}
5577// Message: Sentence should start with an uppercase character.
5578
5579/**
5580 * Foo.
5581 *
5582 * @returns {number} foo
5583 */
5584function quux (foo) {
5585
5586}
5587// Message: Sentence should start with an uppercase character.
5588
5589/**
5590 * Foo.
5591 *
5592 * @returns foo.
5593 */
5594function quux (foo) {
5595
5596}
5597// Message: Sentence should start with an uppercase character.
5598
5599/**
5600 * lorem ipsum dolor sit amet, consectetur adipiscing elit. pellentesque elit diam,
5601 * iaculis eu dignissim sed, ultrices sed nisi. nulla at ligula auctor, consectetur neque sed,
5602 * tincidunt nibh. vivamus sit amet vulputate ligula. vivamus interdum elementum nisl,
5603 * vitae rutrum tortor semper ut. morbi porta ante vitae dictum fermentum.
5604 * proin ut nulla at quam convallis gravida in id elit. sed dolor mauris, blandit quis ante at,
5605 * consequat auctor magna. duis pharetra purus in porttitor mollis.
5606 */
5607function longDescription (foo) {
5608
5609}
5610// Message: Sentence should start with an uppercase character.
5611
5612/**
5613 * @arg {number} foo - Foo
5614 */
5615function quux (foo) {
5616
5617}
5618// Message: Sentence must end with a period.
5619
5620/**
5621 * @argument {number} foo - Foo
5622 */
5623function quux (foo) {
5624
5625}
5626// Message: Sentence must end with a period.
5627
5628/**
5629 * @return {number} foo
5630 */
5631function quux (foo) {
5632
5633}
5634// Message: Sentence should start with an uppercase character.
5635
5636/**
5637 * Returns bar.
5638 *
5639 * @return {number} bar
5640 */
5641function quux (foo) {
5642
5643}
5644// Message: Sentence should start with an uppercase character.
5645
5646/**
5647 * @throws {object} Hello World
5648 * hello world
5649*/
5650// Message: Sentence must end with a period.
5651
5652/**
5653 * @summary Foo
5654 */
5655function quux () {
5656
5657}
5658// Message: Sentence must end with a period.
5659
5660/**
5661 * @throws {SomeType} Foo
5662 */
5663function quux () {
5664
5665}
5666// Message: Sentence must end with a period.
5667
5668/**
5669 * @see Foo
5670 */
5671function quux () {
5672
5673}
5674// Options: [{"tags":["see"]}]
5675// Message: Sentence must end with a period.
5676
5677/**
5678 * @param foo Foo bar
5679 */
5680function quux (foo) {
5681
5682}
5683// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
5684// Options: [{"tags":["param"]}]
5685// Message: Sentence must end with a period.
5686
5687/**
5688 * Sorry, but this isn't a complete sentence, Mr.
5689 */
5690function quux () {
5691
5692}
5693// Options: [{"abbreviations":["Mr"]}]
5694// Message: Sentence must end with a period.
5695
5696/**
5697 * Sorry, but this isn't a complete sentence Mr.
5698 */
5699function quux () {
5700
5701}
5702// Options: [{"abbreviations":["Mr."]}]
5703// Message: Sentence must end with a period.
5704
5705/**
5706 * Sorry, but this isn't a complete sentence Mr.
5707 */
5708function quux () {
5709
5710}
5711// Options: [{"abbreviations":["Mr"]}]
5712// Message: Sentence must end with a period.
5713
5714/**
5715 * Sorry, but this isn't a complete sentence Mr. and Mrs.
5716 */
5717function quux () {
5718
5719}
5720// Options: [{"abbreviations":["Mr","Mrs"]}]
5721// Message: Sentence must end with a period.
5722
5723/**
5724 * This is a complete sentence. But this isn't, Mr.
5725 */
5726function quux () {
5727
5728}
5729// Options: [{"abbreviations":["Mr"]}]
5730// Message: Sentence must end with a period.
5731
5732/**
5733 * This is a complete Mr. sentence. But this isn't, Mr.
5734 */
5735function quux () {
5736
5737}
5738// Options: [{"abbreviations":["Mr"]}]
5739// Message: Sentence must end with a period.
5740
5741/**
5742 * This is a complete Mr. sentence.
5743 */
5744function quux () {
5745
5746}
5747// Message: Sentence should start with an uppercase character.
5748
5749/**
5750 * This is fun, i.e. enjoyable, but not superlatively so, e.g. not
5751 * super, wonderful, etc..
5752 */
5753function quux () {
5754
5755}
5756// Message: Sentence should start with an uppercase character.
5757
5758/**
5759 * Do not have dynamic content; e.g. homepage. Here a simple unique id
5760 * suffices.
5761 */
5762 function quux () {
5763
5764 }
5765// Message: Sentence should start with an uppercase character.
5766````
5767
5768The following patterns are not considered problems:
5769
5770````js
5771/**
5772 * @param foo - Foo.
5773 */
5774function quux () {
5775
5776}
5777
5778/**
5779 * Foo.
5780 */
5781function quux () {
5782
5783}
5784
5785/**
5786 * Foo.
5787 * Bar.
5788 */
5789function quux () {
5790
5791}
5792
5793/**
5794 * Foo.
5795 *
5796 * Bar.
5797 */
5798function quux () {
5799
5800}
5801
5802/**
5803 * Тест.
5804 */
5805function quux () {
5806
5807}
5808
5809/**
5810 * Foo
5811 * bar.
5812 */
5813function quux () {
5814
5815}
5816
5817/**
5818 * @returns Foo bar.
5819 */
5820function quux () {
5821
5822}
5823
5824/**
5825 * Foo. {@see Math.sin}.
5826 */
5827function quux () {
5828
5829}
5830
5831/**
5832 * Foo {@see Math.sin} bar.
5833 */
5834function quux () {
5835
5836}
5837
5838/**
5839 * Foo?
5840 *
5841 * Bar!
5842 *
5843 * Baz:
5844 * 1. Foo.
5845 * 2. Bar.
5846 */
5847function quux () {
5848
5849}
5850
5851/**
5852 * Hello:
5853 * World.
5854 */
5855function quux () {
5856
5857}
5858
5859/**
5860 * Hello: world.
5861 */
5862function quux () {
5863
5864}
5865
5866/**
5867 *
5868 */
5869function quux () {
5870
5871}
5872
5873/**
5874 * @description Foo.
5875 */
5876function quux () {
5877
5878}
5879
5880/**
5881 * `foo` is a variable.
5882 */
5883function quux () {
5884
5885}
5886
5887/**
5888 * Foo.
5889 *
5890 * `foo`.
5891 */
5892function quux () {
5893
5894}
5895
5896/**
5897 * @param foo - `bar`.
5898 */
5899function quux () {
5900
5901}
5902
5903/**
5904 * @returns {number} `foo`.
5905 */
5906function quux () {
5907
5908}
5909
5910/**
5911 * Foo
5912 * `bar`.
5913 */
5914function quux () {
5915
5916}
5917
5918/**
5919 * @example Foo
5920 */
5921function quux () {
5922
5923}
5924
5925/**
5926 * @see Foo
5927 */
5928function quux () {
5929
5930}
5931
5932/**
5933 * Foo.
5934 *
5935 * @param foo Foo.
5936 */
5937function quux (foo) {
5938
5939}
5940
5941/**
5942 * Foo.
5943 *
5944 * @param foo Foo.
5945 */
5946function quux (foo) {
5947
5948}
5949// Options: [{"tags":["param"]}]
5950
5951/**
5952 * @param foo Foo bar.
5953 */
5954function quux (foo) {
5955
5956}
5957// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
5958// Options: [{"tags":["param"]}]
5959
5960/**
5961 *
5962 */
5963function quux (foo) {
5964
5965}
5966// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
5967
5968/**
5969* We stop loading Items when we have loaded:
5970*
5971* 1) The main Item;
5972* 2) All its variants.
5973*/
5974
5975/**
5976 * This method is working on 2 steps.
5977 *
5978 * | Step | Comment |
5979 * |------|-------------|
5980 * | 1 | do it |
5981 * | 2 | do it again |
5982 */
5983
5984/**
5985 * This is something that
5986 * I want to test.
5987 */
5988function quux () {
5989
5990}
5991
5992/**
5993 * When making HTTP requests, the
5994 * URL is super important.
5995 */
5996function quux () {
5997
5998}
5999
6000/**
6001 * Sorry, but this isn't a complete sentence, Mr.
6002 */
6003function quux () {
6004
6005}
6006
6007/**
6008 * Sorry, but this isn't a complete sentence Mr..
6009 */
6010function quux () {
6011
6012}
6013// Options: [{"abbreviations":["Mr."]}]
6014
6015/**
6016 * Sorry, but this isn't a complete sentence Mr.
6017 */
6018function quux () {
6019
6020}
6021
6022/**
6023 * Sorry, but this isn't a complete sentence Mr. and Mrs..
6024 */
6025function quux () {
6026
6027}
6028// Options: [{"abbreviations":["Mr","Mrs"]}]
6029
6030/**
6031 * This is a complete sentence aMr.
6032 */
6033function quux () {
6034
6035}
6036// Options: [{"abbreviations":["Mr"]}]
6037
6038/**
6039 * This is a complete sentence. But this isn't, Mr.
6040 */
6041function quux () {
6042
6043}
6044
6045/**
6046 * This is a complete Mr. Sentence. But this isn't, Mr.
6047 */
6048function quux () {
6049
6050}
6051
6052/**
6053 * This is a complete Mr. sentence.
6054 */
6055function quux () {
6056
6057}
6058// Options: [{"abbreviations":["Mr"]}]
6059
6060/**
6061 * This is fun, i.e. enjoyable, but not superlatively so, e.g. not
6062 * super, wonderful, etc..
6063 */
6064function quux () {
6065
6066}
6067// Options: [{"abbreviations":["etc","e.g.","i.e."]}]
6068
6069
6070**
6071* Do not have dynamic content; e.g. homepage. Here a simple unique id
6072* suffices.
6073*/
6074function quux () {
6075
6076}
6077// Options: [{"abbreviations":["etc","e.g.","i.e."]}]
6078````
6079
6080
6081<a name="eslint-plugin-jsdoc-rules-require-description"></a>
6082### <code>require-description</code>
6083
6084Requires that all functions have a description.
6085
6086* All functions must have an implicit description or have the option
6087 `descriptionStyle` set to `tag`.
6088* Every jsdoc block description (or description tag if `descriptionStyle` is
6089 `"tag"`) must have a non-empty description that explains the purpose of the
6090 method.
6091
6092<a name="eslint-plugin-jsdoc-rules-require-description-options-13"></a>
6093#### Options
6094
6095An options object may have any of the following properties:
6096
6097- `contexts` - Set to an array of strings representing the AST context
6098 where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6
6099 classes). Overrides the default contexts (see below). Set to `"any"` if
6100 you want the rule to apply to any jsdoc block throughout your files.
6101- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the
6102 document block avoids the need for a `@description`. Defaults to an
6103 empty array.
6104- `descriptionStyle` - Whether to accept implicit descriptions (`"body"`) or
6105 `@description` tags (`"tag"`) as satisfying the rule. Set to `"any"` to
6106 accept either style. Defaults to `"body"`.
6107
6108|||
6109|---|---|
6110|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6111|Tags|`description` or jsdoc block|
6112|Aliases|`desc`|
6113|Options|`contexts`, `exemptedBy`, `descriptionStyle`|
6114|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
6115
6116The following patterns are considered problems:
6117
6118````js
6119/**
6120 *
6121 */
6122function quux () {
6123
6124}
6125// Options: [{"descriptionStyle":"tag"}]
6126// Message: Missing JSDoc @description declaration.
6127
6128/**
6129 *
6130 */
6131function quux () {
6132
6133}
6134// Options: [{"descriptionStyle":"any"}]
6135// Message: Missing JSDoc block description or @description declaration.
6136
6137/**
6138 *
6139 */
6140function quux () {
6141
6142}
6143// Options: [{"descriptionStyle":"body"}]
6144// Message: Missing JSDoc block description.
6145
6146/**
6147 *
6148 */
6149class quux {
6150
6151}
6152// Options: [{"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
6153// Message: Missing JSDoc @description declaration.
6154
6155/**
6156 *
6157 */
6158// Options: [{"contexts":["any"],"descriptionStyle":"tag"}]
6159// Message: Missing JSDoc @description declaration.
6160
6161/**
6162 *
6163 */
6164class quux {
6165
6166}
6167// Options: [{"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
6168// Message: Missing JSDoc @description declaration.
6169
6170/**
6171 *
6172 */
6173class quux {
6174
6175}
6176// Options: [{"contexts":["ClassDeclaration"],"descriptionStyle":"tag"}]
6177// Message: Missing JSDoc @description declaration.
6178
6179/**
6180 * @description
6181 */
6182function quux () {
6183
6184}
6185// Options: [{"descriptionStyle":"tag"}]
6186// Message: Missing JSDoc @description description.
6187
6188/**
6189 *
6190 */
6191interface quux {
6192
6193}
6194// Options: [{"contexts":["TSInterfaceDeclaration"],"descriptionStyle":"tag"}]
6195// Message: Missing JSDoc @description declaration.
6196
6197/**
6198 *
6199 */
6200var quux = class {
6201
6202};
6203// Options: [{"contexts":["ClassExpression"],"descriptionStyle":"tag"}]
6204// Message: Missing JSDoc @description declaration.
6205
6206/**
6207 *
6208 */
6209var quux = {
6210
6211};
6212// Options: [{"contexts":["ObjectExpression"],"descriptionStyle":"tag"}]
6213// Message: Missing JSDoc @description declaration.
6214
6215/**
6216 * @someDesc
6217 */
6218function quux () {
6219
6220}
6221// Settings: {"jsdoc":{"tagNamePreference":{"description":{"message":"Please avoid `{{tagName}}`; use `{{replacement}}` instead","replacement":"someDesc"}}}}
6222// Options: [{"descriptionStyle":"tag"}]
6223// Message: Missing JSDoc @someDesc description.
6224
6225/**
6226 * @description
6227 */
6228function quux () {
6229
6230}
6231// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6232// Options: [{"descriptionStyle":"tag"}]
6233// Message: Unexpected tag `@description`
6234
6235/**
6236 * @description
6237 */
6238function quux () {
6239
6240}
6241// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6242// Options: [{"descriptionStyle":"any"}]
6243// Message: Missing JSDoc block description or @description declaration.
6244
6245/**
6246 *
6247 */
6248function quux () {
6249}
6250// Options: [{"exemptedBy":["notPresent"]}]
6251// Message: Missing JSDoc block description.
6252````
6253
6254The following patterns are not considered problems:
6255
6256````js
6257/**
6258 *
6259 */
6260
6261/**
6262 * @description
6263 * // arbitrary description content
6264 */
6265function quux () {
6266
6267}
6268// Options: [{"descriptionStyle":"tag"}]
6269
6270/**
6271 * @description
6272 * quux(); // does something useful
6273 */
6274function quux () {
6275
6276}
6277// Options: [{"descriptionStyle":"tag"}]
6278
6279/**
6280 * @description <caption>Valid usage</caption>
6281 * quux(); // does something useful
6282 *
6283 * @description <caption>Invalid usage</caption>
6284 * quux('random unwanted arg'); // results in an error
6285 */
6286function quux () {
6287
6288}
6289// Options: [{"descriptionStyle":"tag"}]
6290
6291/**
6292 *
6293 */
6294class quux {
6295
6296}
6297// Options: [{"descriptionStyle":"tag"}]
6298
6299/**
6300 *
6301 */
6302function quux () {
6303
6304}
6305// Options: [{"contexts":["ClassDeclaration"]}]
6306
6307/**
6308 * @type {MyCallback}
6309 */
6310function quux () {
6311
6312}
6313// Options: [{"exemptedBy":["type"]}]
6314
6315/**
6316 *
6317 */
6318interface quux {
6319
6320}
6321// Options: [{"descriptionStyle":"tag"}]
6322
6323/**
6324 *
6325 */
6326var quux = class {
6327
6328};
6329// Options: [{"descriptionStyle":"tag"}]
6330
6331/**
6332 *
6333 */
6334var quux = {
6335
6336};
6337// Options: [{"descriptionStyle":"tag"}]
6338
6339/**
6340 * Has an implicit description
6341 */
6342function quux () {
6343
6344}
6345// Options: [{"descriptionStyle":"body"}]
6346
6347/**
6348 * Has an implicit description
6349 */
6350function quux () {
6351
6352}
6353
6354/**
6355 * Has an implicit description
6356 */
6357function quux () {
6358
6359}
6360// Options: [{"descriptionStyle":"any"}]
6361
6362/**
6363 * @description Has an explicit description
6364 */
6365function quux () {
6366
6367}
6368// Options: [{"descriptionStyle":"any"}]
6369
6370/**
6371 *
6372 */
6373function quux () {
6374
6375}
6376// Settings: {"jsdoc":{"tagNamePreference":{"description":false}}}
6377````
6378
6379
6380<a name="eslint-plugin-jsdoc-rules-require-example"></a>
6381### <code>require-example</code>
6382
6383Requires that all functions have examples.
6384
6385* All functions must have one or more `@example` tags.
6386* Every example tag must have a non-empty description that explains the method's usage.
6387
6388<a name="eslint-plugin-jsdoc-rules-require-example-options-14"></a>
6389#### Options
6390
6391This rule has an object option.
6392
6393<a name="eslint-plugin-jsdoc-rules-require-example-options-14-exemptedby"></a>
6394##### <code>exemptedBy</code>
6395
6396Array of tags (e.g., `['type']`) whose presence on the document
6397block avoids the need for an `@example`. Defaults to an empty array.
6398
6399<a name="eslint-plugin-jsdoc-rules-require-example-options-14-avoidexampleonconstructors"></a>
6400##### <code>avoidExampleOnConstructors</code>
6401
6402Set to `true` to avoid the need for an example on a constructor (whether
6403indicated as such by a jsdoc tag or by being within an ES6 `class`).
6404Defaults to `false`.
6405
6406<a name="eslint-plugin-jsdoc-rules-require-example-options-14-contexts-1"></a>
6407##### <code>contexts</code>
6408
6409Set this to an array of strings representing the AST context
6410where you wish the rule to be applied (e.g., `ClassDeclaration` for ES6 classes).
6411Overrides the default contexts (see below). Set to `"any"` if you want
6412the rule to apply to any jsdoc block throughout your files.
6413
6414<a name="eslint-plugin-jsdoc-rules-require-example-fixer"></a>
6415#### Fixer
6416
6417The fixer for `require-example` will add an empty `@example`, but it will still
6418report a missing example description after this is added.
6419
6420|||
6421|---|---|
6422|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6423|Tags|`example`|
6424|Options|`exemptedBy`, `avoidExampleOnConstructors`, `contexts`|
6425|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
6426
6427The following patterns are considered problems:
6428
6429````js
6430/**
6431 *
6432 */
6433function quux () {
6434
6435}
6436// Message: Missing JSDoc @example declaration.
6437
6438/**
6439 * @example
6440 */
6441function quux () {
6442
6443}
6444// Message: Missing JSDoc @example description.
6445
6446/**
6447 * @constructor
6448 */
6449function f () {
6450
6451}
6452// Settings: {"jsdoc":{"avoidExampleOnConstructors":true}}
6453// Message: `settings.jsdoc.avoidExampleOnConstructors` has been removed, use options in the rule `require-example` instead.
6454
6455/**
6456 * @constructor
6457 */
6458function quux () {
6459
6460}
6461// Message: Missing JSDoc @example declaration.
6462
6463/**
6464 * @constructor
6465 * @example
6466 */
6467function quux () {
6468
6469}
6470// Message: Missing JSDoc @example description.
6471
6472/**
6473 *
6474 */
6475class quux {
6476
6477}
6478// Options: [{"contexts":["ClassDeclaration"]}]
6479// Message: Missing JSDoc @example declaration.
6480
6481/**
6482 *
6483 */
6484// Options: [{"contexts":["any"]}]
6485// Message: Missing JSDoc @example declaration.
6486
6487/**
6488 *
6489 */
6490function quux () {
6491}
6492// Options: [{"exemptedBy":["notPresent"]}]
6493// Message: Missing JSDoc @example declaration.
6494````
6495
6496The following patterns are not considered problems:
6497
6498````js
6499/**
6500 *
6501 */
6502
6503/**
6504 * @example
6505 * // arbitrary example content
6506 */
6507function quux () {
6508
6509}
6510
6511/**
6512 * @example
6513 * quux(); // does something useful
6514 */
6515function quux () {
6516
6517}
6518
6519/**
6520 * @example <caption>Valid usage</caption>
6521 * quux(); // does something useful
6522 *
6523 * @example <caption>Invalid usage</caption>
6524 * quux('random unwanted arg'); // results in an error
6525 */
6526function quux () {
6527
6528}
6529
6530/**
6531 * @constructor
6532 */
6533function quux () {
6534
6535}
6536// Options: [{"avoidExampleOnConstructors":true}]
6537
6538/**
6539 * @constructor
6540 * @example
6541 */
6542function quux () {
6543
6544}
6545// Options: [{"avoidExampleOnConstructors":true}]
6546
6547class Foo {
6548 /**
6549 *
6550 */
6551 constructor () {
6552
6553 }
6554}
6555// Options: [{"avoidExampleOnConstructors":true}]
6556
6557/**
6558 * @inheritdoc
6559 */
6560function quux () {
6561
6562}
6563
6564/**
6565 * @type {MyCallback}
6566 */
6567function quux () {
6568
6569}
6570// Options: [{"exemptedBy":["type"]}]
6571
6572/**
6573 * @example Some example code
6574 */
6575class quux {
6576
6577}
6578// Options: [{"contexts":["ClassDeclaration"]}]
6579
6580/**
6581 *
6582 */
6583function quux () {
6584
6585}
6586// Options: [{"contexts":["ClassDeclaration"]}]
6587````
6588
6589
6590<a name="eslint-plugin-jsdoc-rules-require-file-overview"></a>
6591### <code>require-file-overview</code>
6592
6593Checks that:
6594
65951. All files have a `@file`, `@fileoverview`, or `@overview` tag.
65962. Duplicate file overview tags within a given file will be reported
65973. File overview tags will be reported which are not, as per
6598 [the docs](https://jsdoc.app/tags-file.html), "at the beginning of
6599 the file"–where beginning of the file is interpreted in this rule
6600 as being when the overview tag is not preceded by anything other than
6601 a comment.
6602
6603|||
6604|---|---|
6605|Context|Everywhere|
6606|Tags|`file`|
6607|Aliases|`fileoverview`, `overview`|
6608
6609The following patterns are considered problems:
6610
6611````js
6612
6613// Message: Missing @file
6614
6615/**
6616 *
6617 */
6618// Message: Missing @file
6619
6620/**
6621 *
6622 */
6623function quux () {}
6624// Message: Missing @file
6625
6626/**
6627 *
6628 */
6629function quux () {}
6630// Settings: {"jsdoc":{"tagNamePreference":{"file":"fileoverview"}}}
6631// Message: Missing @fileoverview
6632
6633/**
6634 *
6635 */
6636function quux () {}
6637// Settings: {"jsdoc":{"tagNamePreference":{"file":"overview"}}}
6638// Message: Missing @overview
6639
6640/**
6641 *
6642 */
6643function quux () {}
6644// Settings: {"jsdoc":{"tagNamePreference":{"file":false}}}
6645// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
6646
6647/**
6648 *
6649 */
6650function quux () {}
6651// Settings: {"jsdoc":{"tagNamePreference":{"file":{"message":"Don't use file"}}}}
6652// Message: `settings.jsdoc.tagNamePreference` cannot block @file for the `require-file-overview` rule
6653
6654/**
6655 * @param a
6656 */
6657function quux (a) {}
6658// Message: Missing @file
6659
6660/**
6661 * @param a
6662 */
6663function quux (a) {}
6664
6665/**
6666 * @param b
6667 */
6668function bar (b) {}
6669// Message: Missing @file
6670
6671/**
6672 * @file
6673 */
6674
6675 /**
6676 * @file
6677 */
6678// Message: Duplicate @file
6679
6680function quux () {
6681}
6682/**
6683 * @file
6684 */
6685// Message: @file should be at the beginning of the file
6686````
6687
6688The following patterns are not considered problems:
6689
6690````js
6691/**
6692 * @file
6693 */
6694
6695// Ok preceded by comment
6696/**
6697 * @file
6698 */
6699
6700/**
6701 * @fileoverview
6702 */
6703// Settings: {"jsdoc":{"tagNamePreference":{"file":"fileoverview"}}}
6704
6705/**
6706 * @overview
6707 */
6708// Settings: {"jsdoc":{"tagNamePreference":{"file":"overview"}}}
6709
6710/**
6711 * @file Description of file
6712 */
6713
6714/**
6715 * @file Description of file
6716 */
6717function quux () {
6718}
6719
6720/**
6721 *
6722 */
6723````
6724
6725
6726<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description"></a>
6727### <code>require-hyphen-before-param-description</code>
6728
6729Requires a hyphen before the `@param` description.
6730
6731<a name="eslint-plugin-jsdoc-rules-require-hyphen-before-param-description-options-15"></a>
6732#### Options
6733
6734This 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"`.
6735
6736|||
6737|---|---|
6738|Context|everywhere|
6739|Tags|`param`|
6740|Aliases|`arg`, `argument`|
6741|Options|(a string matching `"always"|"never"`)|
6742
6743The following patterns are considered problems:
6744
6745````js
6746/**
6747 * @param foo Foo.
6748 */
6749function quux () {
6750
6751}
6752// Options: ["always"]
6753// Message: There must be a hyphen before @param description.
6754
6755/**
6756 * @param foo Foo.
6757 */
6758function quux () {
6759
6760}
6761// Message: There must be a hyphen before @param description.
6762
6763/**
6764 * @param foo - Foo.
6765 */
6766function quux () {
6767
6768}
6769// Options: ["never"]
6770// Message: There must be no hyphen before @param description.
6771
6772/**
6773 * @param foo - foo
6774 * @param foo foo
6775 */
6776function quux () {
6777
6778}
6779// Options: ["always"]
6780// Message: There must be a hyphen before @param description.
6781
6782/**
6783 * @param foo foo
6784 * bar
6785 * @param bar - bar
6786 */
6787function quux () {
6788
6789}
6790// Options: ["always"]
6791// Message: There must be a hyphen before @param description.
6792
6793/**
6794 * @param foo
6795 */
6796function quux (foo) {
6797
6798}
6799// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
6800// Message: Unexpected tag `@param`
6801````
6802
6803The following patterns are not considered problems:
6804
6805````js
6806/**
6807 * @param foo - Foo.
6808 */
6809function quux () {
6810
6811}
6812// Options: ["always"]
6813
6814/**
6815 * @param foo Foo.
6816 */
6817function quux () {
6818
6819}
6820// Options: ["never"]
6821
6822/**
6823 * @param foo
6824 */
6825function quux () {
6826
6827}
6828````
6829
6830
6831<a name="eslint-plugin-jsdoc-rules-require-jsdoc"></a>
6832### <code>require-jsdoc</code>
6833
6834Checks for presence of jsdoc comments, on class declarations as well as
6835functions.
6836
6837<a name="eslint-plugin-jsdoc-rules-require-jsdoc-options-16"></a>
6838#### Options
6839
6840Accepts one optional options object with the following optional keys.
6841
6842- `publicOnly` - This option will insist that missing jsdoc blocks are
6843 only reported for function bodies / class declarations that are exported
6844 from the module. May be a boolean or object. If set to `true`, the defaults
6845 below will be used. If unset, jsdoc block reporting will not be limited to
6846 exports.
6847
6848 This object supports the following optional boolean keys (`false` unless
6849 otherwise noted):
6850
6851 - `ancestorsOnly` - Only check node ancestors to check if node is exported
6852 - `esm` - ESM exports are checked for JSDoc comments (Defaults to `true`)
6853 - `cjs` - CommonJS exports are checked for JSDoc comments (Defaults to `true`)
6854 - `window` - Window global exports are checked for JSDoc comments
6855
6856- `require` - An object with the following optional boolean keys which all
6857 default to `false` except as noted, indicating the contexts where the rule
6858 will apply:
6859
6860 - `ArrowFunctionExpression`
6861 - `ClassDeclaration`
6862 - `ClassExpression`
6863 - `FunctionDeclaration` (defaults to `true`)
6864 - `FunctionExpression`
6865 - `MethodDefinition`
6866
6867- `contexts` - Set this to an array of strings representing the additional
6868 AST contexts where you wish the rule to be applied (e.g., `Property` for
6869 properties). Defaults to an empty array.
6870
6871- `exemptEmptyFunctions` (default: false) - When `true`, the rule will not report
6872 missing jsdoc blocks above functions/methods with no parameters or return values
6873 (intended where variable names are sufficient for themselves as documentation).
6874
6875|||
6876|---|---|
6877|Context|`ArrowFunctionExpression`, `ClassDeclaration`, `ClassExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled|
6878|Tags|N/A|
6879|Options|`publicOnly`, `require`, `contexts`, `exemptEmptyFunctions`|
6880
6881The following patterns are considered problems:
6882
6883````js
6884/**
6885 * @func myFunction
6886 */
6887function myFunction() {
6888
6889}
6890// Settings: {"jsdoc":{"maxLines":3,"minLines":2}}
6891// Message: Missing JSDoc comment.
6892
6893/**
6894 * @func myFunction
6895 */
6896
6897
6898function myFunction() {
6899
6900}
6901// Settings: {"jsdoc":{"maxLines":2}}
6902// Message: Missing JSDoc comment.
6903
6904/** @func myFunction */ function myFunction() {
6905
6906}
6907// Settings: {"jsdoc":{"minLines":1}}
6908// Message: Missing JSDoc comment.
6909
6910export var test = function () {
6911
6912};
6913// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
6914// Message: Missing JSDoc comment.
6915
6916function test () {
6917
6918}
6919export var test2 = test;
6920// Options: [{"publicOnly":true,"require":{"FunctionDeclaration":true}}]
6921// Message: Missing JSDoc comment.
6922
6923export const test = () => {
6924
6925};
6926// Options: [{"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
6927// Message: Missing JSDoc comment.
6928
6929export let test = class {
6930
6931};
6932// Options: [{"publicOnly":true,"require":{"ClassExpression":true}}]
6933// Message: Missing JSDoc comment.
6934
6935export default function () {}
6936// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
6937// Message: Missing JSDoc comment.
6938
6939export default () => {}
6940// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"ArrowFunctionExpression":true}}]
6941// Message: Missing JSDoc comment.
6942
6943export default (function () {})
6944// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
6945// Message: Missing JSDoc comment.
6946
6947export default class {}
6948// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"ClassDeclaration":true}}]
6949// Message: Missing JSDoc comment.
6950
6951function quux (foo) {
6952
6953}
6954// Message: Missing JSDoc comment.
6955
6956
6957// Settings: {"jsdoc":{"exemptEmptyFunctions":true}}
6958// Message: `settings.jsdoc.exemptEmptyFunctions` has been removed, use options in the rule `require-jsdoc` instead.
6959
6960function quux (foo) {
6961
6962}
6963// Options: [{"exemptEmptyFunctions":true}]
6964// Message: Missing JSDoc comment.
6965
6966function quux (foo) {
6967
6968}
6969// Settings: {"jsdoc":{"minLines":2}}
6970// Options: [{"exemptEmptyFunctions":true}]
6971// Message: Missing JSDoc comment.
6972
6973function myFunction() {}
6974// Message: Missing JSDoc comment.
6975
6976/**
6977 * Description for A.
6978 */
6979class A {
6980 constructor(xs) {
6981 this.a = xs;
6982 }
6983}
6984// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
6985// Message: Missing JSDoc comment.
6986
6987class A {
6988 /**
6989 * Description for constructor.
6990 * @param {object[]} xs - xs
6991 */
6992 constructor(xs) {
6993 this.a = xs;
6994 }
6995}
6996// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
6997// Message: Missing JSDoc comment.
6998
6999class A extends B {
7000 /**
7001 * Description for constructor.
7002 * @param {object[]} xs - xs
7003 */
7004 constructor(xs) {
7005 this.a = xs;
7006 }
7007}
7008// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7009// Message: Missing JSDoc comment.
7010
7011export class A extends B {
7012 /**
7013 * Description for constructor.
7014 * @param {object[]} xs - xs
7015 */
7016 constructor(xs) {
7017 this.a = xs;
7018 }
7019}
7020// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7021// Message: Missing JSDoc comment.
7022
7023export default class A extends B {
7024 /**
7025 * Description for constructor.
7026 * @param {object[]} xs - xs
7027 */
7028 constructor(xs) {
7029 this.a = xs;
7030 }
7031}
7032// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7033// Message: Missing JSDoc comment.
7034
7035var myFunction = () => {}
7036// Options: [{"require":{"ArrowFunctionExpression":true}}]
7037// Message: Missing JSDoc comment.
7038
7039var myFunction = () => () => {}
7040// Options: [{"require":{"ArrowFunctionExpression":true}}]
7041// Message: Missing JSDoc comment.
7042
7043var foo = function() {}
7044// Options: [{"require":{"FunctionExpression":true}}]
7045// Message: Missing JSDoc comment.
7046
7047const foo = {bar() {}}
7048// Options: [{"require":{"FunctionExpression":true}}]
7049// Message: Missing JSDoc comment.
7050
7051var foo = {bar: function() {}}
7052// Options: [{"require":{"FunctionExpression":true}}]
7053// Message: Missing JSDoc comment.
7054
7055function foo (abc) {}
7056// Options: [{"exemptEmptyFunctions":false}]
7057// Message: Missing JSDoc comment.
7058
7059function foo () {
7060 return true;
7061}
7062// Options: [{"exemptEmptyFunctions":false}]
7063// Message: Missing JSDoc comment.
7064
7065module.exports = function quux () {
7066
7067}
7068// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7069// Message: Missing JSDoc comment.
7070
7071module.exports = function quux () {
7072
7073}
7074// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7075// Message: Missing JSDoc comment.
7076
7077module.exports = {
7078 method: function() {
7079
7080 }
7081}
7082// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7083// Message: Missing JSDoc comment.
7084
7085module.exports = {
7086 test: {
7087 test2: function() {
7088
7089 }
7090 }
7091}
7092// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7093// Message: Missing JSDoc comment.
7094
7095module.exports = {
7096 test: {
7097 test2: function() {
7098
7099 }
7100 }
7101}
7102// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7103// Message: Missing JSDoc comment.
7104
7105const test = module.exports = function () {
7106
7107}
7108// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7109// Message: Missing JSDoc comment.
7110
7111/**
7112*
7113*/
7114const test = module.exports = function () {
7115
7116}
7117
7118test.prototype.method = function() {}
7119// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7120// Message: Missing JSDoc comment.
7121
7122const test = function () {
7123
7124}
7125module.exports = {
7126 test: test
7127}
7128// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7129// Message: Missing JSDoc comment.
7130
7131const test = () => {
7132
7133}
7134module.exports = {
7135 test: test
7136}
7137// Options: [{"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
7138// Message: Missing JSDoc comment.
7139
7140class Test {
7141 method() {
7142
7143 }
7144}
7145module.exports = Test;
7146// Options: [{"publicOnly":true,"require":{"MethodDefinition":true}}]
7147// Message: Missing JSDoc comment.
7148
7149export default function quux () {
7150
7151}
7152// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7153// Message: Missing JSDoc comment.
7154
7155export default function quux () {
7156
7157}
7158// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7159// Message: Missing JSDoc comment.
7160
7161function quux () {
7162
7163}
7164export default quux;
7165// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7166// Message: Missing JSDoc comment.
7167
7168export function test() {
7169
7170}
7171// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7172// Message: Missing JSDoc comment.
7173
7174export function test() {
7175
7176}
7177// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7178// Message: Missing JSDoc comment.
7179
7180var test = function () {
7181
7182}
7183var test2 = 2;
7184export { test, test2 }
7185// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7186// Message: Missing JSDoc comment.
7187
7188var test = function () {
7189
7190}
7191export { test as test2 }
7192// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7193// Message: Missing JSDoc comment.
7194
7195export default class A {
7196
7197}
7198// Options: [{"publicOnly":true,"require":{"ClassDeclaration":true}}]
7199// Message: Missing JSDoc comment.
7200
7201export default class A {
7202
7203}
7204// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true}}]
7205// Message: Missing JSDoc comment.
7206
7207var test = function () {
7208
7209}
7210// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7211// Message: Missing JSDoc comment.
7212
7213window.test = function () {
7214
7215}
7216// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7217// Message: Missing JSDoc comment.
7218
7219function test () {
7220
7221}
7222// Options: [{"publicOnly":{"window":true}}]
7223// Message: Missing JSDoc comment.
7224
7225module.exports = function() {
7226
7227}
7228// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionExpression":true}}]
7229// Message: Missing JSDoc comment.
7230
7231export function someMethod() {
7232
7233}
7234// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
7235// Message: Missing JSDoc comment.
7236
7237export function someMethod() {
7238
7239}
7240// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionDeclaration":true}}]
7241// Message: Missing JSDoc comment.
7242
7243const myObject = {
7244 myProp: true
7245};
7246// Options: [{"contexts":["Property"]}]
7247// Message: Missing JSDoc comment.
7248````
7249
7250The following patterns are not considered problems:
7251
7252````js
7253/**
7254 *
7255 */
7256
7257var array = [1,2,3];
7258array.forEach(function() {});
7259
7260/**
7261 * @class MyClass
7262 **/
7263function MyClass() {}
7264
7265/**
7266 Function doing something
7267 */
7268function myFunction() {}
7269/**
7270 Function doing something
7271 */
7272var myFunction = function() {};
7273/**
7274 Function doing something
7275 */
7276Object.myFunction = function () {};
7277var obj = {
7278 /**
7279 * Function doing something
7280 **/
7281 myFunction: function () {} };
7282
7283/**
7284 @func myFunction
7285 */
7286function myFunction() {}
7287/**
7288 @method myFunction
7289 */
7290function myFunction() {}
7291/**
7292 @function myFunction
7293 */
7294function myFunction() {}
7295
7296/**
7297 @func myFunction
7298 */
7299var myFunction = function () {}
7300/**
7301 @method myFunction
7302 */
7303var myFunction = function () {}
7304/**
7305 @function myFunction
7306 */
7307var myFunction = function () {}
7308
7309/**
7310 @func myFunction
7311 */
7312Object.myFunction = function() {}
7313/**
7314 @method myFunction
7315 */
7316Object.myFunction = function() {}
7317/**
7318 @function myFunction
7319 */
7320Object.myFunction = function() {}
7321(function(){})();
7322
7323var object = {
7324 /**
7325 * @func myFunction - Some function
7326 */
7327 myFunction: function() {} }
7328var object = {
7329 /**
7330 * @method myFunction - Some function
7331 */
7332 myFunction: function() {} }
7333var object = {
7334 /**
7335 * @function myFunction - Some function
7336 */
7337 myFunction: function() {} }
7338
7339var array = [1,2,3];
7340array.filter(function() {});
7341Object.keys(this.options.rules || {}).forEach(function(name) {}.bind(this));
7342var object = { name: 'key'};
7343Object.keys(object).forEach(function() {})
7344
7345/**
7346 * @func myFunction
7347 */
7348
7349function myFunction() {
7350
7351}
7352// Settings: {"jsdoc":{"maxLines":2,"minLines":0}}
7353
7354/**
7355 * @func myFunction
7356 */
7357
7358
7359function myFunction() {
7360
7361}
7362// Settings: {"jsdoc":{"maxLines":3,"minLines":0}}
7363
7364/** @func myFunction */ function myFunction() {
7365
7366}
7367// Settings: {"jsdoc":{"maxLines":0,"minLines":0}}
7368
7369/**
7370 * @func myFunction
7371 */
7372
7373function myFunction() {
7374
7375}
7376// Settings: {"jsdoc":{"maxLines":3,"minLines":2}}
7377
7378function myFunction() {}
7379// Options: [{"require":{"ClassDeclaration":true,"FunctionDeclaration":false,"MethodDefinition":true}}]
7380
7381var myFunction = function() {}
7382// Options: [{"require":{"ClassDeclaration":true,"FunctionDeclaration":false,"MethodDefinition":true}}]
7383
7384/**
7385 * Description for A.
7386 */
7387class A {
7388 /**
7389 * Description for constructor.
7390 * @param {object[]} xs - xs
7391 */
7392 constructor(xs) {
7393 this.a = xs;
7394 }
7395}
7396// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7397
7398/**
7399 * Description for A.
7400 */
7401class App extends Component {
7402 /**
7403 * Description for constructor.
7404 * @param {object[]} xs - xs
7405 */
7406 constructor(xs) {
7407 this.a = xs;
7408 }
7409}
7410// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7411
7412/**
7413 * Description for A.
7414 */
7415export default class App extends Component {
7416 /**
7417 * Description for constructor.
7418 * @param {object[]} xs - xs
7419 */
7420 constructor(xs) {
7421 this.a = xs;
7422 }
7423}
7424// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7425
7426/**
7427 * Description for A.
7428 */
7429export class App extends Component {
7430 /**
7431 * Description for constructor.
7432 * @param {object[]} xs - xs
7433 */
7434 constructor(xs) {
7435 this.a = xs;
7436 }
7437}
7438// Options: [{"require":{"ClassDeclaration":true,"MethodDefinition":true}}]
7439
7440class A {
7441 constructor(xs) {
7442 this.a = xs;
7443 }
7444}
7445// Options: [{"require":{"ClassDeclaration":false,"MethodDefinition":false}}]
7446
7447/**
7448* Function doing something
7449*/
7450var myFunction = () => {}
7451// Options: [{"require":{"ArrowFunctionExpression":true}}]
7452
7453/**
7454* Function doing something
7455*/
7456var myFunction = function () {}
7457// Options: [{"require":{"ArrowFunctionExpression":true}}]
7458
7459/**
7460* Function doing something
7461*/
7462var myFunction = () => {}
7463// Options: [{"require":{"ArrowFunctionExpression":false}}]
7464
7465/**
7466 Function doing something
7467*/
7468var myFunction = () => () => {}
7469// Options: [{"require":{"ArrowFunctionExpression":true}}]
7470
7471setTimeout(() => {}, 10);
7472// Options: [{"require":{"ArrowFunctionExpression":true}}]
7473
7474/**
7475JSDoc Block
7476*/
7477var foo = function() {}
7478// Options: [{"require":{"FunctionExpression":true}}]
7479
7480const foo = {/**
7481JSDoc Block
7482*/
7483bar() {}}
7484// Options: [{"require":{"FunctionExpression":true}}]
7485
7486var foo = {/**
7487JSDoc Block
7488*/
7489bar: function() {}}
7490// Options: [{"require":{"FunctionExpression":true}}]
7491
7492var foo = { [function() {}]: 1 };
7493// Options: [{"require":{"FunctionExpression":true}}]
7494
7495function foo () {}
7496// Options: [{"exemptEmptyFunctions":true}]
7497
7498function foo () {
7499 return;
7500}
7501// Options: [{"exemptEmptyFunctions":true}]
7502
7503const test = {};
7504/**
7505 * test
7506 */
7507 test.method = function () {
7508
7509}
7510module.exports = {
7511 prop: { prop2: test.method }
7512}
7513// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7514
7515/**
7516 *
7517 */
7518function test() {
7519
7520}
7521
7522module.exports = {
7523 prop: { prop2: test }
7524}
7525// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7526
7527/**
7528 *
7529 */
7530test = function() {
7531
7532}
7533
7534module.exports = {
7535 prop: { prop2: test }
7536}
7537// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionExpression":true}}]
7538
7539/**
7540 *
7541 */
7542test = function() {
7543
7544}
7545
7546exports.someMethod = {
7547 prop: { prop2: test }
7548}
7549// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
7550
7551/**
7552 *
7553 */
7554const test = () => {
7555
7556}
7557
7558module.exports = {
7559prop: { prop2: test }
7560}
7561// Options: [{"publicOnly":true,"require":{"ArrowFunctionExpression":true}}]
7562
7563const test = () => {
7564
7565}
7566module.exports = {
7567 prop: { prop2: test }
7568}
7569// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"ArrowFunctionExpression":true}}]
7570
7571/**
7572 *
7573 */
7574window.test = function() {
7575
7576}
7577
7578module.exports = {
7579prop: window
7580}
7581// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7582
7583test = function() {
7584
7585}
7586
7587/**
7588 *
7589 */
7590test = function() {
7591
7592}
7593
7594module.exports = {
7595prop: { prop2: test }
7596}
7597// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7598
7599test = function() {
7600
7601}
7602
7603test = 2;
7604
7605module.exports = {
7606prop: { prop2: test }
7607}
7608// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7609
7610/**
7611 *
7612 */
7613function test() {
7614
7615}
7616
7617/**
7618 *
7619 */
7620test.prototype.method = function() {
7621
7622}
7623
7624module.exports = {
7625prop: { prop2: test }
7626}
7627// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7628
7629class Test {
7630 /**
7631 * Test
7632 */
7633 method() {
7634
7635 }
7636}
7637module.exports = Test;
7638// Options: [{"publicOnly":true,"require":{"MethodDefinition":true}}]
7639
7640/**
7641 *
7642 */
7643export default function quux () {
7644
7645}
7646// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7647
7648/**
7649 *
7650 */
7651export default function quux () {
7652
7653}
7654// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7655
7656/**
7657 *
7658 */
7659function quux () {
7660
7661}
7662export default quux;
7663// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7664
7665function quux () {
7666
7667}
7668export default quux;
7669// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7670
7671/**
7672 *
7673 */
7674export function test() {
7675
7676}
7677// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7678
7679/**
7680 *
7681 */
7682export function test() {
7683
7684}
7685// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"FunctionExpression":true}}]
7686
7687/**
7688 *
7689 */
7690var test = function () {
7691
7692}
7693var test2 = 2;
7694export { test, test2 }
7695// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7696
7697/**
7698 *
7699 */
7700var test = function () {
7701
7702}
7703export { test as test2 }
7704// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7705
7706/**
7707 *
7708 */
7709export default class A {
7710
7711}
7712// Options: [{"publicOnly":{"ancestorsOnly":true},"require":{"ClassDeclaration":true}}]
7713
7714/**
7715 *
7716 */
7717var test = function () {
7718
7719}
7720// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7721
7722let test = function () {
7723
7724}
7725// Options: [{"publicOnly":{"window":true},"require":{"FunctionExpression":true}}]
7726
7727let test = class {
7728
7729}
7730// Options: [{"publicOnly":true,"require":{"ClassExpression":false}}]
7731
7732/**
7733 *
7734 */
7735let test = class {
7736
7737}
7738// Options: [{"publicOnly":true,"require":{"ClassExpression":true}}]
7739
7740export function someMethod() {
7741
7742}
7743// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionDeclaration":true}}]
7744
7745export function someMethod() {
7746
7747}
7748// Options: [{"publicOnly":{"cjs":true,"esm":false,"window":false},"require":{"FunctionDeclaration":true}}]
7749
7750exports.someMethod = function() {
7751
7752}
7753// Options: [{"publicOnly":{"cjs":false,"esm":true,"window":false},"require":{"FunctionExpression":true}}]
7754
7755const myObject = {
7756 myProp: true
7757};
7758// Options: [{"contexts":[]}]
7759
7760function bear() {}
7761/**
7762 *
7763 */
7764function quux () {
7765}
7766export default quux;
7767// Options: [{"publicOnly":true,"require":{"FunctionExpression":true}}]
7768
7769/**
7770 * This example interface is great!
7771 */
7772export interface Example {
7773 /**
7774 * My super test string!
7775 */
7776 test: string
7777}
7778// Options: [{"contexts":["TSInterfaceDeclaration"]}]
7779
7780/**
7781 * This example interface is great!
7782 */
7783interface Example {
7784 /**
7785 * My super test string!
7786 */
7787 test: string
7788}
7789// Options: [{"contexts":["TSInterfaceDeclaration"]}]
7790
7791/**
7792 * This example type is great!
7793 */
7794export type Example = {
7795 /**
7796 * My super test string!
7797 */
7798 test: string
7799};
7800// Options: [{"contexts":["TSTypeAliasDeclaration"]}]
7801
7802/**
7803 * This example type is great!
7804 */
7805type Example = {
7806 /**
7807 * My super test string!
7808 */
7809 test: string
7810};
7811// Options: [{"contexts":["TSTypeAliasDeclaration"]}]
7812
7813/**
7814 * This example enum is great!
7815 */
7816export enum Example {
7817 /**
7818 * My super test enum!
7819 */
7820 test = 123
7821}
7822// Options: [{"contexts":["TSEnumDeclaration"]}]
7823
7824/**
7825 * This example enum is great!
7826 */
7827enum Example {
7828 /**
7829 * My super test enum!
7830 */
7831 test = 123
7832}
7833// Options: [{"contexts":["TSEnumDeclaration"]}]
7834
7835const foo = {...{}};
7836function bar() {}
7837// Options: [{"exemptEmptyFunctions":false,"publicOnly":true,"require":{"ArrowFunctionExpression":true,"ClassDeclaration":true,"ClassExpression":true,"FunctionDeclaration":true,"FunctionExpression":false,"MethodDefinition":true}}]
7838
7839/**
7840 * Class documentation
7841 */
7842 @logged
7843export default class Foo {
7844 // ....
7845}
7846// Options: [{"exemptEmptyFunctions":false,"require":{"ClassDeclaration":true}}]
7847````
7848
7849
7850<a name="eslint-plugin-jsdoc-rules-require-param-description"></a>
7851### <code>require-param-description</code>
7852
7853Requires that each `@param` tag has a `description` value.
7854
7855|||
7856|---|---|
7857|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
7858|Tags|`param`|
7859|Aliases|`arg`, `argument`|
7860
7861The following patterns are considered problems:
7862
7863````js
7864/**
7865 * @param foo
7866 */
7867function quux (foo) {
7868
7869}
7870// Message: Missing JSDoc @param "foo" description.
7871
7872/**
7873 * @arg foo
7874 */
7875function quux (foo) {
7876
7877}
7878// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
7879// Message: Missing JSDoc @arg "foo" description.
7880
7881/**
7882 * @param foo
7883 */
7884function quux (foo) {
7885
7886}
7887// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
7888// Message: Unexpected tag `@param`
7889````
7890
7891The following patterns are not considered problems:
7892
7893````js
7894/**
7895 *
7896 */
7897function quux (foo) {
7898
7899}
7900
7901/**
7902 * @param foo Foo.
7903 */
7904function quux (foo) {
7905
7906}
7907````
7908
7909
7910<a name="eslint-plugin-jsdoc-rules-require-param-name"></a>
7911### <code>require-param-name</code>
7912
7913Requires that all function parameters have names.
7914
7915> 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.
7916>
7917> [JSDoc](https://jsdoc.app/tags-param.html#overview)
7918
7919|||
7920|---|---|
7921|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
7922|Tags|`param`|
7923|Aliases|`arg`, `argument`|
7924
7925The following patterns are considered problems:
7926
7927````js
7928/**
7929 * @param
7930 */
7931function quux (foo) {
7932
7933}
7934// Message: There must be an identifier after @param type.
7935
7936/**
7937 * @param {string}
7938 */
7939function quux (foo) {
7940
7941}
7942// Message: There must be an identifier after @param tag.
7943
7944/**
7945 * @param foo
7946 */
7947function quux (foo) {
7948
7949}
7950// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
7951// Message: Unexpected tag `@param`
7952````
7953
7954The following patterns are not considered problems:
7955
7956````js
7957/**
7958 * @param foo
7959 */
7960function quux (foo) {
7961
7962}
7963
7964/**
7965 * @param {string} foo
7966 */
7967function quux (foo) {
7968
7969}
7970````
7971
7972
7973<a name="eslint-plugin-jsdoc-rules-require-param-type"></a>
7974### <code>require-param-type</code>
7975
7976Requires that each `@param` tag has a `type` value.
7977
7978|||
7979|---|---|
7980|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
7981|Tags|`param`|
7982|Aliases|`arg`, `argument`|
7983
7984The following patterns are considered problems:
7985
7986````js
7987/**
7988 * @param foo
7989 */
7990function quux (foo) {
7991
7992}
7993// Message: Missing JSDoc @param "foo" type.
7994
7995/**
7996 * @arg foo
7997 */
7998function quux (foo) {
7999
8000}
8001// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8002// Message: Missing JSDoc @arg "foo" type.
8003
8004/**
8005 * @param foo
8006 */
8007function quux (foo) {
8008
8009}
8010// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
8011// Message: Unexpected tag `@param`
8012````
8013
8014The following patterns are not considered problems:
8015
8016````js
8017/**
8018 *
8019 */
8020function quux (foo) {
8021
8022}
8023
8024/**
8025 * @param {number} foo
8026 */
8027function quux (foo) {
8028
8029}
8030````
8031
8032
8033<a name="eslint-plugin-jsdoc-rules-require-param"></a>
8034### <code>require-param</code>
8035
8036Requires that all function parameters are documented.
8037
8038<a name="eslint-plugin-jsdoc-rules-require-param-options-17"></a>
8039#### Options
8040
8041An options object accepts one optional property:
8042
8043- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
8044 block avoids the need for a `@param`. Defaults to an empty array.
8045
8046|||
8047|---|---|
8048|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
8049|Tags|`param`|
8050|Aliases|`arg`, `argument`|
8051|Options|`exemptedBy`|
8052|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
8053
8054The following patterns are considered problems:
8055
8056````js
8057/**
8058 *
8059 */
8060function quux (foo) {
8061
8062}
8063// Message: Missing JSDoc @param "foo" declaration.
8064
8065/**
8066 *
8067 */
8068function quux (foo, bar) {
8069
8070}
8071// Message: Missing JSDoc @param "foo" declaration.
8072
8073/**
8074 * @param foo
8075 */
8076function quux (foo, bar) {
8077
8078}
8079// Message: Missing JSDoc @param "bar" declaration.
8080
8081/**
8082 * @param bar
8083 */
8084function quux (foo, bar, baz) {
8085
8086}
8087// Message: Missing JSDoc @param "foo" declaration.
8088
8089/**
8090 * @param foo
8091 * @param bar
8092 */
8093function quux (foo, bar, baz) {
8094
8095}
8096// Message: Missing JSDoc @param "baz" declaration.
8097
8098/**
8099 * @param baz
8100 */
8101function quux (foo, bar, baz) {
8102
8103}
8104// Message: Missing JSDoc @param "foo" declaration.
8105
8106/**
8107 * @param
8108 */
8109function quux (foo) {
8110
8111}
8112// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8113// Message: Missing JSDoc @arg "foo" declaration.
8114
8115/**
8116 * @param foo
8117 */
8118function quux (foo, bar) {
8119
8120}
8121// Message: Missing JSDoc @param "bar" declaration.
8122
8123/**
8124 * @override
8125 */
8126function quux (foo) {
8127
8128}
8129// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
8130// Message: Missing JSDoc @param "foo" declaration.
8131
8132/**
8133 * @implements
8134 */
8135function quux (foo) {
8136
8137}
8138// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
8139// Message: Missing JSDoc @param "foo" declaration.
8140
8141/**
8142 * @augments
8143 */
8144function quux (foo) {
8145
8146}
8147// Message: Missing JSDoc @param "foo" declaration.
8148
8149/**
8150 * @extends
8151 */
8152function quux (foo) {
8153
8154}
8155// Message: Missing JSDoc @param "foo" declaration.
8156
8157/**
8158 * @override
8159 */
8160class A {
8161 /**
8162 *
8163 */
8164 quux (foo) {
8165
8166 }
8167}
8168// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
8169// Message: Missing JSDoc @param "foo" declaration.
8170
8171/**
8172 * @implements
8173 */
8174class A {
8175 /**
8176 *
8177 */
8178 quux (foo) {
8179
8180 }
8181}
8182// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
8183// Message: Missing JSDoc @param "foo" declaration.
8184
8185/**
8186 * @augments
8187 */
8188class A {
8189 /**
8190 *
8191 */
8192 quux (foo) {
8193
8194 }
8195}
8196// Message: Missing JSDoc @param "foo" declaration.
8197
8198/**
8199 * @extends
8200 */
8201class A {
8202 /**
8203 *
8204 */
8205 quux (foo) {
8206
8207 }
8208}
8209// Message: Missing JSDoc @param "foo" declaration.
8210
8211export class SomeClass {
8212 /**
8213 * @param property
8214 */
8215 constructor(private property: string, private foo: number) {}
8216}
8217// Message: Missing JSDoc @param "foo" declaration.
8218
8219/**
8220 * @param
8221 */
8222function quux (foo) {
8223
8224}
8225// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
8226// Message: Unexpected tag `@param`
8227
8228/**
8229 *
8230 */
8231function quux ({bar, baz}, foo) {
8232}
8233// Message: Missing JSDoc @param "foo" declaration.
8234
8235/**
8236 *
8237 */
8238function quux (foo, {bar, baz}) {
8239}
8240// Message: Missing JSDoc @param "foo" declaration.
8241
8242/**
8243 *
8244 */
8245function quux ([bar, baz], foo) {
8246}
8247// Message: Missing JSDoc @param "foo" declaration.
8248
8249/**
8250 *
8251 */
8252function quux (foo) {
8253}
8254// Options: [{"exemptedBy":["notPresent"]}]
8255// Message: Missing JSDoc @param "foo" declaration.
8256````
8257
8258The following patterns are not considered problems:
8259
8260````js
8261/**
8262 * @param foo
8263 */
8264function quux (foo) {
8265
8266}
8267
8268/**
8269 * @inheritdoc
8270 */
8271function quux (foo) {
8272
8273}
8274
8275/**
8276 * @arg foo
8277 */
8278function quux (foo) {
8279
8280}
8281// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
8282
8283/**
8284 * @override
8285 * @param foo
8286 */
8287function quux (foo) {
8288
8289}
8290
8291/**
8292 * @override
8293 */
8294function quux (foo) {
8295
8296}
8297
8298/**
8299 * @override
8300 */
8301class A {
8302 /**
8303 *
8304 */
8305 quux (foo) {
8306
8307 }
8308}
8309
8310/**
8311 * @override
8312 */
8313function quux (foo) {
8314
8315}
8316// Settings: {"jsdoc":{"overrideReplacesDocs":true}}
8317
8318/**
8319 * @implements
8320 */
8321class A {
8322 /**
8323 *
8324 */
8325 quux (foo) {
8326
8327 }
8328}
8329
8330/**
8331 * @implements
8332 */
8333function quux (foo) {
8334
8335}
8336
8337/**
8338 * @implements
8339 */
8340function quux (foo) {
8341
8342}
8343// Settings: {"jsdoc":{"implementsReplacesDocs":true}}
8344
8345/**
8346 * @implements
8347 * @param foo
8348 */
8349function quux (foo) {
8350
8351}
8352
8353/**
8354 * @augments
8355 */
8356function quux (foo) {
8357
8358}
8359// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8360
8361/**
8362 * @augments
8363 * @param foo
8364 */
8365function quux (foo) {
8366
8367}
8368
8369/**
8370 * @extends
8371 */
8372function quux (foo) {
8373
8374}
8375// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8376
8377/**
8378 * @extends
8379 * @param foo
8380 */
8381function quux (foo) {
8382
8383}
8384
8385/**
8386 * @augments
8387 */
8388function quux (foo) {
8389
8390}
8391// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8392
8393/**
8394 * @extends
8395 */
8396function quux (foo) {
8397
8398}
8399// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8400
8401/**
8402 * @override
8403 */
8404class A {
8405 /**
8406 * @param foo
8407 */
8408 quux (foo) {
8409
8410 }
8411}
8412
8413/**
8414 * @override
8415 */
8416class A {
8417 /**
8418 *
8419 */
8420 quux (foo) {
8421
8422 }
8423}
8424// Settings: {"jsdoc":{"overrideReplacesDocs":true}}
8425
8426/**
8427 * @implements
8428 */
8429class A {
8430 /**
8431 *
8432 */
8433 quux (foo) {
8434
8435 }
8436}
8437// Settings: {"jsdoc":{"implementsReplacesDocs":true}}
8438
8439/**
8440 * @implements
8441 */
8442class A {
8443 /**
8444 * @param foo
8445 */
8446 quux (foo) {
8447
8448 }
8449}
8450
8451/**
8452 * @augments
8453 */
8454class A {
8455 /**
8456 *
8457 */
8458 quux (foo) {
8459
8460 }
8461}
8462// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8463
8464/**
8465 * @augments
8466 */
8467class A {
8468 /**
8469 * @param foo
8470 */
8471 quux (foo) {
8472
8473 }
8474}
8475
8476/**
8477 * @extends
8478 */
8479class A {
8480 /**
8481 *
8482 */
8483 quux (foo) {
8484
8485 }
8486}
8487// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8488
8489/**
8490 * @extends
8491 */
8492class A {
8493 /**
8494 * @param foo
8495 */
8496 quux (foo) {
8497
8498 }
8499}
8500
8501/**
8502 * @augments
8503 */
8504class A {
8505 /**
8506 *
8507 */
8508 quux (foo) {
8509
8510 }
8511}
8512// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8513
8514/**
8515 * @extends
8516 */
8517class A {
8518 /**
8519 *
8520 */
8521 quux (foo) {
8522
8523 }
8524}
8525// Settings: {"jsdoc":{"augmentsExtendsReplacesDocs":true}}
8526
8527/**
8528 * @private
8529 */
8530function quux (foo) {
8531
8532}
8533// Settings: {"jsdoc":{"ignorePrivate":true}}
8534
8535/**
8536 * @access private
8537 */
8538function quux (foo) {
8539
8540}
8541// Settings: {"jsdoc":{"ignorePrivate":true}}
8542
8543// issue 182: optional chaining
8544/** @const {boolean} test */
8545const test = something?.find(_ => _)
8546
8547/** @type {RequestHandler} */
8548function foo(req, res, next) {}
8549
8550/**
8551 * @type {MyCallback}
8552 */
8553function quux () {
8554
8555}
8556// Options: [{"exemptedBy":["type"]}]
8557
8558/**
8559 * @override
8560 */
8561var A = class {
8562 /**
8563 *
8564 */
8565 quux (foo) {
8566
8567 }
8568}
8569
8570export class SomeClass {
8571 /**
8572 * @param property
8573 */
8574 constructor(private property: string) {}
8575}
8576
8577/**
8578 * Assign the project to an employee.
8579 *
8580 * @param {object} employee - The employee who is responsible for the project.
8581 * @param {string} employee.name - The name of the employee.
8582 * @param {string} employee.department - The employee's department.
8583 */
8584function assign({name, department}) {
8585 // ...
8586}
8587
8588export abstract class StephanPlugin<O, D> {
8589
8590 /**
8591 * Called right after Stephan loads the plugin file.
8592 *
8593 * @example
8594 *```typescript
8595 * type Options = {
8596 * verbose?: boolean;
8597 * token?: string;
8598 * }
8599 * ```
8600 *
8601 * Note that your Options type should only have optional properties...
8602 *
8603 * @param args Arguments compiled and provided by StephanClient.
8604 * @param args.options The options as provided by the user, or an empty object if not provided.
8605 * @param defaultOptions The default options as provided by the plugin, or an empty object.
8606 */
8607 public constructor({options, client}: {
8608 options: O;
8609 client: unknown;
8610 }, defaultOptions: D) {
8611
8612 }
8613}
8614````
8615
8616
8617<a name="eslint-plugin-jsdoc-rules-require-property"></a>
8618### <code>require-property</code>
8619
8620Requires that all `@typedef` and `@namespace` tags have `@property`
8621when their type is a plain `object`, `Object`, or `PlainObject`.
8622
8623Note that if any other type, including a subtype of object such as
8624`object<string, string>`, will not be reported.
8625
8626<a name="eslint-plugin-jsdoc-rules-require-property-fixer-1"></a>
8627#### Fixer
8628
8629The fixer for `require-example` will add an empty `@property`.
8630
8631|||
8632|---|---|
8633|Context|Everywhere|
8634|Tags|`typedef`, `namespace`|
8635
8636The following patterns are considered problems:
8637
8638````js
8639/**
8640 * @typedef {object} SomeTypedef
8641 */
8642// Message: Missing JSDoc @property.
8643
8644/**
8645 * @typedef {PlainObject} SomeTypedef
8646 */
8647// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
8648// Message: Missing JSDoc @prop.
8649
8650/**
8651 * @namespace {Object} SomeName
8652 */
8653// Message: Missing JSDoc @property.
8654````
8655
8656The following patterns are not considered problems:
8657
8658````js
8659/**
8660 *
8661 */
8662
8663/**
8664 * @property
8665 */
8666
8667/**
8668 * @typedef {Object} SomeTypedef
8669 * @property {SomeType} propName Prop description
8670 */
8671
8672/**
8673 * @typedef {object} SomeTypedef
8674 * @prop {SomeType} propName Prop description
8675 */
8676// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
8677
8678/**
8679 * @typedef {object} SomeTypedef
8680 * @property
8681 * // arbitrary property content
8682 */
8683
8684/**
8685 * @typedef {object<string, string>} SomeTypedef
8686 */
8687
8688/**
8689 * @typedef {string} SomeTypedef
8690 */
8691
8692/**
8693 * @namespace {object} SomeName
8694 * @property {SomeType} propName Prop description
8695 */
8696
8697/**
8698 * @namespace {object} SomeName
8699 * @property
8700 * // arbitrary property content
8701 */
8702
8703/**
8704 * @typedef {object} SomeTypedef
8705 * @property someProp
8706 * @property anotherProp This with a description
8707 * @property {anotherType} yetAnotherProp This with a type and desc.
8708 */
8709function quux () {
8710
8711}
8712````
8713
8714
8715<a name="eslint-plugin-jsdoc-rules-require-property-description"></a>
8716### <code>require-property-description</code>
8717
8718Requires that each `@property` tag has a `description` value.
8719
8720|||
8721|---|---|
8722|Context|everywhere|
8723|Tags|N/A|
8724
8725The following patterns are considered problems:
8726
8727````js
8728/**
8729 * @typedef {SomeType} SomeTypedef
8730 * @property foo
8731 */
8732// Message: Missing JSDoc @property "foo" description.
8733
8734/**
8735 * @typedef {SomeType} SomeTypedef
8736 * @prop foo
8737 */
8738// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
8739// Message: Missing JSDoc @prop "foo" description.
8740
8741/**
8742 * @typedef {SomeType} SomeTypedef
8743 * @property foo
8744 */
8745// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
8746// Message: Unexpected tag `@property`
8747````
8748
8749The following patterns are not considered problems:
8750
8751````js
8752/**
8753 * @typedef {SomeType} SomeTypedef
8754 */
8755
8756/**
8757 * @typedef {SomeType} SomeTypedef
8758 * @property foo Foo.
8759 */
8760
8761/**
8762 * @namespace {SomeType} SomeName
8763 * @property foo Foo.
8764 */
8765
8766/**
8767 * @class
8768 * @property foo Foo.
8769 */
8770````
8771
8772
8773<a name="eslint-plugin-jsdoc-rules-require-property-name"></a>
8774### <code>require-property-name</code>
8775
8776Requires that all function `@property` tags have names.
8777
8778|||
8779|---|---|
8780|Context|everywhere|
8781|Tags|N/A|
8782
8783The following patterns are considered problems:
8784
8785````js
8786/**
8787 * @typedef {SomeType} SomeTypedef
8788 * @property
8789 */
8790// Message: There must be an identifier after @property type.
8791
8792/**
8793 * @typedef {SomeType} SomeTypedef
8794 * @property {string}
8795 */
8796// Message: There must be an identifier after @property tag.
8797
8798/**
8799 * @typedef {SomeType} SomeTypedef
8800 * @property foo
8801 */
8802// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
8803// Message: Unexpected tag `@property`
8804````
8805
8806The following patterns are not considered problems:
8807
8808````js
8809/**
8810 * @typedef {SomeType} SomeTypedef
8811 * @property foo
8812 */
8813
8814/**
8815 * @typedef {SomeType} SomeTypedef
8816 * @property {string} foo
8817 */
8818
8819/**
8820 * @namespace {SomeType} SomeName
8821 * @property {string} foo
8822 */
8823
8824/**
8825 * @class
8826 * @property {string} foo
8827 */
8828````
8829
8830
8831<a name="eslint-plugin-jsdoc-rules-require-property-type"></a>
8832### <code>require-property-type</code>
8833
8834Requires that each `@property` tag has a `type` value.
8835
8836|||
8837|---|---|
8838|Context|everywhere|
8839|Tags|N/A|
8840
8841The following patterns are considered problems:
8842
8843````js
8844/**
8845 * @typedef {SomeType} SomeTypedef
8846 * @property foo
8847 */
8848// Message: Missing JSDoc @property "foo" type.
8849
8850/**
8851 * @typedef {SomeType} SomeTypedef
8852 * @prop foo
8853 */
8854// Settings: {"jsdoc":{"tagNamePreference":{"property":"prop"}}}
8855// Message: Missing JSDoc @prop "foo" type.
8856
8857/**
8858 * @typedef {SomeType} SomeTypedef
8859 * @property foo
8860 */
8861// Settings: {"jsdoc":{"tagNamePreference":{"property":false}}}
8862// Message: Unexpected tag `@property`
8863````
8864
8865The following patterns are not considered problems:
8866
8867````js
8868/**
8869 * @typedef {SomeType} SomeTypedef
8870 */
8871
8872/**
8873 * @typedef {SomeType} SomeTypedef
8874 * @property {number} foo
8875 */
8876
8877/**
8878 * @namespace {SomeType} SomeName
8879 * @property {number} foo
8880 */
8881
8882/**
8883 * @class
8884 * @property {number} foo
8885 */
8886````
8887
8888
8889<a name="eslint-plugin-jsdoc-rules-require-returns-check"></a>
8890### <code>require-returns-check</code>
8891
8892Requires a return statement in function body if a `@returns` tag is specified in jsdoc comment.
8893
8894Will also report if multiple `@returns` tags are present.
8895
8896|||
8897|---|---|
8898|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
8899|Tags|`returns`|
8900|Aliases|`return`|
8901
8902The following patterns are considered problems:
8903
8904````js
8905/**
8906 * @returns
8907 */
8908function quux (foo) {
8909
8910}
8911// Message: JSDoc @returns declaration present but return expression not available in function.
8912
8913/**
8914 * @return
8915 */
8916function quux (foo) {
8917
8918}
8919// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
8920// Message: JSDoc @return declaration present but return expression not available in function.
8921
8922/**
8923 * @returns
8924 */
8925const quux = () => {}
8926// Message: JSDoc @returns declaration present but return expression not available in function.
8927
8928/**
8929 * @returns {undefined} Foo.
8930 * @returns {String} Foo.
8931 */
8932function quux () {
8933
8934 return foo;
8935}
8936// Message: Found more than one @returns declaration.
8937
8938const language = {
8939 /**
8940 * @param {string} name
8941 * @returns {string}
8942 */
8943 get name() {
8944 this._name = name;
8945 }
8946}
8947// Message: JSDoc @returns declaration present but return expression not available in function.
8948
8949class Foo {
8950 /**
8951 * @returns {string}
8952 */
8953 bar () {
8954 }
8955}
8956// Message: JSDoc @returns declaration present but return expression not available in function.
8957
8958/**
8959 * @returns
8960 */
8961function quux () {
8962
8963}
8964// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
8965// Message: Unexpected tag `@returns`
8966
8967/**
8968 * @returns {string}
8969 */
8970function f () {
8971 function g() {
8972 return 'foo'
8973 }
8974
8975 () => {
8976 return 5
8977 }
8978}
8979// Message: JSDoc @returns declaration present but return expression not available in function.
8980````
8981
8982The following patterns are not considered problems:
8983
8984````js
8985/**
8986 * @returns Foo.
8987 */
8988function quux () {
8989
8990 return foo;
8991}
8992
8993/**
8994 * @returns {string} Foo.
8995 */
8996function quux () {
8997
8998 return foo;
8999}
9000
9001/**
9002 * @returns {string} Foo.
9003 */
9004function quux () {
9005
9006 return foo;
9007}
9008
9009/**
9010 *
9011 */
9012function quux () {
9013}
9014
9015/**
9016 * @returns {*} Foo.
9017 */
9018const quux = () => foo;
9019
9020/**
9021 * @returns {undefined} Foo.
9022 */
9023function quux () {}
9024
9025/**
9026 * @returns { void } Foo.
9027 */
9028function quux () {}
9029
9030/**
9031 * @returns {Promise<void>}
9032 */
9033async function quux() {}
9034
9035/**
9036 * @returns {Promise<void>}
9037 */
9038const quux = async function () {}
9039
9040/**
9041 * @returns {Promise<void>}
9042 */
9043const quux = async () => {}
9044
9045/**
9046 * @returns Foo.
9047 * @abstract
9048 */
9049function quux () {
9050 throw new Error('must be implemented by subclass!');
9051}
9052
9053/**
9054 * @returns Foo.
9055 * @virtual
9056 */
9057function quux () {
9058 throw new Error('must be implemented by subclass!');
9059}
9060
9061/**
9062 * @returns Foo.
9063 * @constructor
9064 */
9065function quux () {
9066}
9067
9068/**
9069 * @interface
9070 */
9071class Foo {
9072 /**
9073 * @returns {string}
9074 */
9075 bar () {
9076 }
9077}
9078
9079/**
9080 * @returns {undefined} Foo.
9081 */
9082function quux () {
9083}
9084
9085/**
9086 * @returns {void} Foo.
9087 */
9088function quux () {
9089}
9090
9091/**
9092 * @returns {void} Foo.
9093 */
9094function quux () {
9095 return undefined;
9096}
9097
9098/**
9099 * @returns {void} Foo.
9100 */
9101function quux () {
9102 return;
9103}
9104
9105/**
9106 *
9107 */
9108function quux () {
9109 return undefined;
9110}
9111
9112/**
9113 *
9114 */
9115function quux () {
9116 return;
9117}
9118
9119/**
9120 * @returns {true}
9121 */
9122function quux () {
9123 try {
9124 return true;
9125 } catch (err) {
9126 }
9127 return;
9128}
9129
9130/**
9131 * @returns {true}
9132 */
9133function quux () {
9134 try {
9135 } finally {
9136 return true;
9137 }
9138 return;
9139}
9140
9141/**
9142 * @returns {true}
9143 */
9144function quux () {
9145 try {
9146 return;
9147 } catch (err) {
9148 }
9149 return true;
9150}
9151
9152/**
9153 * @returns {true}
9154 */
9155function quux () {
9156 try {
9157 something();
9158 } catch (err) {
9159 return true;
9160 }
9161 return;
9162}
9163
9164/**
9165 * @returns {true}
9166 */
9167function quux () {
9168 switch (true) {
9169 case 'abc':
9170 return true;
9171 }
9172 return;
9173}
9174
9175/**
9176 * @returns {true}
9177 */
9178function quux () {
9179 switch (true) {
9180 case 'abc':
9181 return;
9182 }
9183 return true;
9184}
9185
9186/**
9187 * @returns {true}
9188 */
9189function quux () {
9190 for (const i of abc) {
9191 return true;
9192 }
9193 return;
9194}
9195
9196/**
9197 * @returns {true}
9198 */
9199function quux () {
9200 for (const a in b) {
9201 return true;
9202 }
9203}
9204
9205/**
9206 * @returns {true}
9207 */
9208function quux () {
9209 for (let i=0; i<n; i+=1) {
9210 return true;
9211 }
9212}
9213
9214/**
9215 * @returns {true}
9216 */
9217function quux () {
9218 while(true) {
9219 return true
9220 }
9221}
9222
9223/**
9224 * @returns {true}
9225 */
9226function quux () {
9227 do {
9228 return true
9229 }
9230 while(true)
9231}
9232
9233/**
9234 * @returns {true}
9235 */
9236function quux () {
9237 if (true) {
9238 return;
9239 }
9240 return true;
9241}
9242
9243/**
9244 * @returns {true}
9245 */
9246function quux () {
9247 if (true) {
9248 return true;
9249 }
9250}
9251
9252/**
9253 * @returns {true}
9254 */
9255function quux () {
9256 var a = {};
9257 with (a) {
9258 return true;
9259 }
9260}
9261
9262/**
9263 * @returns {true}
9264 */
9265function quux () {
9266 if (true) {
9267 return;
9268 } else {
9269 return true;
9270 }
9271 return;
9272}
9273````
9274
9275
9276<a name="eslint-plugin-jsdoc-rules-require-returns-description"></a>
9277### <code>require-returns-description</code>
9278
9279Requires that the `@returns` tag has a `description` value. The error
9280will not be reported if the return value is `void` or `undefined`.
9281
9282|||
9283|---|---|
9284|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
9285|Tags|`returns`|
9286|Aliases|`return`|
9287
9288The following patterns are considered problems:
9289
9290````js
9291/**
9292 * @returns
9293 */
9294function quux (foo) {
9295
9296}
9297// Message: Missing JSDoc @returns description.
9298
9299/**
9300 * @returns {string}
9301 */
9302function quux (foo) {
9303
9304}
9305// Message: Missing JSDoc @returns description.
9306
9307/**
9308 * @return
9309 */
9310function quux (foo) {
9311
9312}
9313// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
9314// Message: Missing JSDoc @return description.
9315
9316/**
9317 * @returns
9318 */
9319function quux () {
9320
9321}
9322// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
9323// Message: Unexpected tag `@returns`
9324````
9325
9326The following patterns are not considered problems:
9327
9328````js
9329/**
9330 *
9331 */
9332function quux () {
9333
9334}
9335
9336/**
9337 * @returns Foo.
9338 */
9339function quux () {
9340
9341}
9342
9343/**
9344 * @returns {undefined}
9345 */
9346function quux () {
9347
9348}
9349
9350/**
9351 * @returns {void}
9352 */
9353function quux () {
9354
9355}
9356````
9357
9358
9359<a name="eslint-plugin-jsdoc-rules-require-returns-type"></a>
9360### <code>require-returns-type</code>
9361
9362Requires that `@returns` tag has `type` value.
9363
9364|||
9365|---|---|
9366|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
9367|Tags|`returns`|
9368|Aliases|`return`|
9369
9370The following patterns are considered problems:
9371
9372````js
9373/**
9374 * @returns
9375 */
9376function quux () {
9377
9378}
9379// Message: Missing JSDoc @returns type.
9380
9381/**
9382 * @returns Foo.
9383 */
9384function quux () {
9385
9386}
9387// Message: Missing JSDoc @returns type.
9388
9389/**
9390 * @return Foo.
9391 */
9392function quux () {
9393
9394}
9395// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
9396// Message: Missing JSDoc @return type.
9397
9398/**
9399 * @returns
9400 */
9401function quux () {
9402
9403}
9404// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
9405// Message: Unexpected tag `@returns`
9406````
9407
9408The following patterns are not considered problems:
9409
9410````js
9411/**
9412 * @returns {number}
9413 */
9414function quux () {
9415
9416}
9417````
9418
9419
9420<a name="eslint-plugin-jsdoc-rules-require-returns"></a>
9421### <code>require-returns</code>
9422
9423Requires returns are documented.
9424
9425Will also report if multiple `@returns` tags are present.
9426
9427<a name="eslint-plugin-jsdoc-rules-require-returns-options-18"></a>
9428#### Options
9429
9430- `exemptedBy` - Array of tags (e.g., `['type']`) whose presence on the document
9431 block avoids the need for a `@returns`. Defaults to an empty array.
9432- `forceRequireReturn` - Set to `true` to always insist on
9433 `@returns` documentation regardless of implicit or explicit `return`'s
9434 in the function. May be desired to flag that a project is aware of an
9435 `undefined`/`void` return. Defaults to `false`.
9436- `forceReturnsWithAsync` - By default `async` functions that do not explicitly
9437 return a value pass this rule as an `async` function will always return a
9438 `Promise`, even if the `Promise` resolves to void. You can force all `async`
9439 functions to require return statements by setting `forceReturnsWithAsync`
9440 to `true` on the options object. This may be useful for flagging that there
9441 has been consideration of return type. Defaults to `false`.
9442
9443```js
9444'jsdoc/require-returns': ['error', {forceReturnsWithAsync: true}]
9445```
9446
9447|||
9448|---|---|
9449|Context|`ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`|
9450|Tags|`returns`|
9451|Aliases|`return`|
9452|Options|`exemptedBy`, `forceRequireReturn`, `forceReturnsWithAsync`|
9453|Settings|`overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
9454
9455The following patterns are considered problems:
9456
9457````js
9458/**
9459 *
9460 */
9461function quux (foo) {
9462
9463 return foo;
9464}
9465// Message: Missing JSDoc @returns declaration.
9466
9467/**
9468 *
9469 */
9470const foo = () => ({
9471 bar: 'baz'
9472})
9473// Message: Missing JSDoc @returns declaration.
9474
9475/**
9476 *
9477 */
9478const foo = bar=>({ bar })
9479// Message: Missing JSDoc @returns declaration.
9480
9481/**
9482 *
9483 */
9484const foo = bar => bar.baz()
9485// Message: Missing JSDoc @returns declaration.
9486
9487/**
9488 *
9489 */
9490function quux (foo) {
9491
9492 return foo;
9493}
9494// Settings: {"jsdoc":{"tagNamePreference":{"returns":"return"}}}
9495// Message: Missing JSDoc @return declaration.
9496
9497/**
9498 *
9499 */
9500function foo() {}
9501
9502/**
9503 *
9504 */
9505function bar() {}
9506// Settings: {"jsdoc":{"forceRequireReturn":true}}
9507// Message: `settings.jsdoc.forceRequireReturn` has been removed, use options in the rule `require-returns` instead.
9508
9509/**
9510 *
9511 */
9512async function quux() {
9513}
9514// Options: [{"forceRequireReturn":true}]
9515// Message: Missing JSDoc @returns declaration.
9516
9517/**
9518 *
9519 */
9520const quux = async function () {}
9521// Options: [{"forceRequireReturn":true}]
9522// Message: Missing JSDoc @returns declaration.
9523
9524/**
9525 *
9526 */
9527const quux = async () => {}
9528// Options: [{"forceRequireReturn":true}]
9529// Message: Missing JSDoc @returns declaration.
9530
9531/**
9532 *
9533 */
9534async function quux () {}
9535// Options: [{"forceRequireReturn":true}]
9536// Message: Missing JSDoc @returns declaration.
9537
9538/**
9539 *
9540 */
9541function quux () {
9542}
9543// Options: [{"forceRequireReturn":true}]
9544// Message: Missing JSDoc @returns declaration.
9545
9546const language = {
9547 /**
9548 * @param {string} name
9549 */
9550 get name() {
9551 return this._name;
9552 }
9553}
9554// Message: Missing JSDoc @returns declaration.
9555
9556/**
9557 *
9558 */
9559async function quux () {
9560}
9561// Options: [{"forceReturnsWithAsync":true}]
9562// Message: Missing JSDoc @returns declaration.
9563
9564/**
9565 * @returns {undefined}
9566 * @returns {void}
9567 */
9568function quux (foo) {
9569
9570 return foo;
9571}
9572// Message: Found more than one @returns declaration.
9573
9574/**
9575 * @returns
9576 */
9577function quux () {
9578
9579}
9580// Settings: {"jsdoc":{"tagNamePreference":{"returns":false}}}
9581// Message: Unexpected tag `@returns`
9582
9583/**
9584 * @param foo
9585 */
9586function quux (foo) {
9587 return 'bar';
9588}
9589// Options: [{"exemptedBy":["notPresent"]}]
9590// Message: Missing JSDoc @returns declaration.
9591
9592/**
9593 * @param {array} a
9594 */
9595async function foo(a) {
9596 return;
9597}
9598// Options: [{"forceReturnsWithAsync":true}]
9599// Message: Missing JSDoc @returns declaration.
9600
9601/**
9602 * @param {array} a
9603 */
9604async function foo(a) {
9605 return Promise.all(a);
9606}
9607// Options: [{"forceReturnsWithAsync":true}]
9608// Message: Missing JSDoc @returns declaration.
9609````
9610
9611The following patterns are not considered problems:
9612
9613````js
9614/**
9615 * @returns Foo.
9616 */
9617function quux () {
9618
9619 return foo;
9620}
9621
9622/**
9623 *
9624 */
9625function quux () {
9626}
9627
9628/**
9629 *
9630 */
9631function quux (bar) {
9632 bar.filter(baz => {
9633 return baz.corge();
9634 })
9635}
9636
9637/**
9638 * @returns Array
9639 */
9640function quux (bar) {
9641 return bar.filter(baz => {
9642 return baz.corge();
9643 })
9644}
9645
9646/**
9647 * @returns Array
9648 */
9649const quux = (bar) => bar.filter(({ corge }) => corge())
9650
9651/**
9652 * @inheritdoc
9653 */
9654function quux (foo) {
9655}
9656
9657/**
9658 * @override
9659 */
9660function quux (foo) {
9661}
9662
9663/**
9664 * @constructor
9665 */
9666function quux (foo) {
9667}
9668
9669/**
9670 * @implements
9671 */
9672function quux (foo) {
9673}
9674
9675/**
9676 * @override
9677 */
9678function quux (foo) {
9679
9680 return foo;
9681}
9682
9683/**
9684 * @class
9685 */
9686function quux (foo) {
9687
9688}
9689
9690/**
9691 * @constructor
9692 */
9693function quux (foo) {
9694
9695}
9696
9697/**
9698 * @returns {object}
9699 */
9700function quux () {
9701
9702 return {a: foo};
9703}
9704
9705/**
9706 * @returns {object}
9707 */
9708const quux = () => ({a: foo});
9709
9710/**
9711 * @returns {object}
9712 */
9713const quux = () => {
9714 return {a: foo}
9715};
9716
9717/**
9718 * @returns {void}
9719 */
9720function quux () {
9721}
9722
9723/**
9724 * @returns {void}
9725 */
9726const quux = () => {
9727
9728}
9729
9730/**
9731 * @returns {undefined}
9732 */
9733function quux () {
9734}
9735
9736/**
9737 * @returns {undefined}
9738 */
9739const quux = () => {
9740
9741}
9742
9743/**
9744 *
9745 */
9746function quux () {
9747}
9748
9749/**
9750 *
9751 */
9752const quux = () => {
9753
9754}
9755
9756class Foo {
9757 /**
9758 *
9759 */
9760 constructor () {
9761 }
9762}
9763// Options: [{"forceRequireReturn":true}]
9764
9765const language = {
9766 /**
9767 * @param {string} name
9768 */
9769 set name(name) {
9770 this._name = name;
9771 }
9772}
9773
9774/**
9775 * @returns {void}
9776 */
9777function quux () {
9778}
9779// Options: [{"forceRequireReturn":true}]
9780
9781/**
9782 * @returns {void}
9783 */
9784function quux () {
9785 return undefined;
9786}
9787
9788/**
9789 * @returns {void}
9790 */
9791function quux () {
9792 return undefined;
9793}
9794// Options: [{"forceRequireReturn":true}]
9795
9796/**
9797 * @returns {void}
9798 */
9799function quux () {
9800 return;
9801}
9802
9803/**
9804 * @returns {void}
9805 */
9806function quux () {
9807}
9808// Options: [{"forceRequireReturn":true}]
9809
9810/**
9811 * @returns {void}
9812 */
9813function quux () {
9814 return;
9815}
9816// Options: [{"forceRequireReturn":true}]
9817
9818/** @type {RequestHandler} */
9819function quux (req, res , next) {
9820 return;
9821}
9822
9823/**
9824 * @returns {Promise}
9825 */
9826async function quux () {
9827}
9828// Options: [{"forceRequireReturn":true}]
9829
9830/**
9831 * @returns {Promise}
9832 */
9833async function quux () {
9834}
9835// Options: [{"forceReturnsWithAsync":true}]
9836
9837/**
9838 *
9839 */
9840async function quux () {}
9841
9842/**
9843 *
9844 */
9845const quux = async function () {}
9846
9847/**
9848 *
9849 */
9850const quux = async () => {}
9851
9852/** foo class */
9853class foo {
9854 /** foo constructor */
9855 constructor () {
9856 // =>
9857 this.bar = true;
9858 }
9859}
9860
9861export default foo;
9862
9863/**
9864 *
9865 */
9866function quux () {
9867}
9868// Options: [{"forceReturnsWithAsync":true}]
9869
9870/**
9871 * @type {MyCallback}
9872 */
9873function quux () {
9874
9875}
9876// Options: [{"exemptedBy":["type"]}]
9877
9878/**
9879 * @param {array} a
9880 */
9881async function foo(a) {
9882 return Promise.all(a);
9883}
9884
9885/**
9886 * @param {array} a
9887 */
9888async function foo(a) {
9889 return;
9890}
9891````
9892
9893
9894<a name="eslint-plugin-jsdoc-rules-valid-types"></a>
9895### <code>valid-types</code>
9896
9897Requires all types to be valid JSDoc or Closure compiler types without syntax errors.
9898
9899Also impacts behaviors on namepath (or event)-defining and pointing tags:
9900
99011. Name(path)-defining tags requiring namepath: `@external`, `@host`, `@name`, `@typedef`
99021. Name(path)-defining tags (which may have value without namepath or their
9903 namepath can be expressed elsewhere on the block): `@event`, `@callback`,
9904 `@class`, `@constructor`, `@constant`, `@const`,
9905 `@function`, `@func`, `@method`, `@interface`, `@member`, `@var`,
9906 `@mixin`, `@namespace`
99071. Name(path)-pointing tags requiring namepath: `@alias`, `@augments`, `@extends`, `@lends`, `@memberof`, `@memberof!`, `@mixes`, `@this`
99081. Name(path)-pointing tags (which may have value without namepath or their
9909 namepath can be expressed elsewhere on the block): `@listens`, `@fires`,
9910 `@emits`, and `@modifies`
99111. Name(path)-pointing tags (multiple names in one): `@borrows`
9912
9913...with the following applying to the above sets:
9914
9915- Expect tags in set 1-4 to have a valid namepath if present
9916- Prevent sets 2 and 4 from being empty by setting `allowEmptyNamepaths` to
9917 `false` as these tags might have some indicative value without a path
9918 or may allow a name expressed elsewhere on the block (but sets 1 and 3 will
9919 always fail if empty)
9920- For the special case of set 5, i.e., `@borrows <that namepath> as <this namepath>`,
9921 check that both namepaths are present and valid and ensure there is an `as `
9922 between them. In the case of `<this namepath>`, it can be preceded by
9923 one of the name path operators, `#`, `.`, or `~`.
9924- For the special case of `@memberof` and `@memberof!` (part of set 3), as
9925 per the [specification](https://jsdoc.app/tags-memberof.html), they also
9926 allow `#`, `.`, or `~` at the end (which is not allowed at the end of
9927 normal paths).
9928
9929<a name="eslint-plugin-jsdoc-rules-valid-types-options-19"></a>
9930#### Options
9931
9932- `allowEmptyNamepaths` (default: true) - Set to `false` to disallow
9933 empty name paths with `@callback`, `@event`, `@class`, `@constructor`,
9934 `@constant`, `@const`, `@function`, `@func`, `@method`, `@interface`,
9935 `@member`, `@var`, `@mixin`, `@namespace`, `@listens`, `@fires`,
9936 `@modifies`, or `@emits` (these might often be expected to have an
9937 accompanying name path, though they have some indicative value without
9938 one; these may also allow names to be defined in another manner elsewhere
9939 in the block)
9940- `checkSeesForNamepaths` (default: false) - Set this to `true` to insist
9941 that `@see` only use name paths (the tag is normally permitted to
9942 allow other text)
9943
9944
9945|||
9946|---|---|
9947|Context|everywhere|
9948|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)|
9949|Aliases|`extends`, `constructor`, `const`, `host`, `emits`, `func`, `method`, `var`, `arg`, `argument`, `prop`, `return`, `exception`, `yield`|
9950|Closure-only|For type only: `package`, `private`, `protected`, `public`, `static`|
9951|Options|`allowEmptyNamepaths`, `checkSeesForNamepaths`|
9952|Settings|`mode`|
9953
9954The following patterns are considered problems:
9955
9956````js
9957/**
9958 * @param {Array<string} foo
9959 */
9960function quux() {
9961
9962}
9963// Message: Syntax error in type: Array<string
9964
9965/**
9966 * @memberof module:namespace.SomeClass<~
9967 */
9968function quux() {
9969
9970}
9971// Message: Syntax error in namepath: module:namespace.SomeClass<~
9972
9973/**
9974 * @memberof module:namespace.SomeClass~<
9975 */
9976function quux() {
9977
9978}
9979// Message: Syntax error in namepath: module:namespace.SomeClass~<
9980
9981/**
9982 * @borrows foo% as bar
9983 */
9984function quux() {
9985
9986}
9987// Message: Syntax error in namepath: foo%
9988
9989/**
9990 * @borrows #foo as bar
9991 */
9992function quux() {
9993
9994}
9995// Message: Syntax error in namepath: #foo
9996
9997/**
9998 * @borrows foo as bar%
9999 */
10000function quux() {
10001
10002}
10003// Message: Syntax error in namepath: bar%
10004
10005/**
10006 * @borrows foo
10007 */
10008function quux() {
10009
10010}
10011// Message: @borrows must have an "as" expression. Found ""
10012
10013/**
10014 * @see foo%
10015 */
10016function quux() {
10017
10018}
10019// Options: [{"checkSeesForNamepaths":true}]
10020// Message: Syntax error in namepath: foo%
10021
10022/** */
10023function foo() {}
10024// Settings: {"jsdoc":{"allowEmptyNamepaths":true,"checkSeesForNamepaths":true}}
10025// Message: `settings.jsdoc.allowEmptyNamepaths` has been removed, use options in the rule `valid-types` instead.
10026
10027/**
10028 * @alias module:abc#event:foo-bar
10029 */
10030function quux() {
10031
10032}
10033// Message: Syntax error in namepath: module:abc#event:foo-bar
10034
10035/**
10036 * @mixes module:namespace.SomeClass~
10037 */
10038function quux() {
10039
10040}
10041// Message: Syntax error in namepath: module:namespace.SomeClass~
10042
10043/**
10044 * @callback
10045 */
10046function quux() {
10047
10048}
10049// Options: [{"allowEmptyNamepaths":false}]
10050// Message: Tag @callback must have a name/namepath
10051
10052/**
10053 * @constant {str%ng}
10054 */
10055 const FOO = 'foo';
10056// Message: Syntax error in type: str%ng
10057
10058/**
10059 * @typedef {str%ng} UserString
10060 */
10061// Message: Syntax error in type: str%ng
10062
10063/**
10064 * @typedef {string} UserStr%ng
10065 */
10066// Message: Syntax error in namepath: UserStr%ng
10067
10068/**
10069 * @extends
10070 */
10071 class Bar {};
10072// Message: Tag @extends must have either a type or namepath
10073
10074/**
10075 * @type
10076 */
10077 let foo;
10078// Message: Tag @type must have a type
10079
10080/**
10081 * @modifies {bar|foo<}
10082 */
10083function quux (foo, bar, baz) {}
10084// Message: Syntax error in type: bar|foo<
10085
10086/**
10087 * @private {BadTypeChecked<}
10088 */
10089function quux () {}
10090// Settings: {"jsdoc":{"mode":"closure"}}
10091// Message: Syntax error in type: BadTypeChecked<
10092
10093/**
10094 * @this {BadTypeChecked<}
10095 */
10096function quux () {}
10097// Settings: {"jsdoc":{"mode":"closure"}}
10098// Message: Syntax error in type: BadTypeChecked<
10099
10100/**
10101 * @define
10102 */
10103 function quux () {}
10104// Settings: {"jsdoc":{"mode":"closure"}}
10105// Message: Tag @define must have a type
10106
10107/**
10108 * @this
10109 */
10110 let foo;
10111// Settings: {"jsdoc":{"mode":"closure"}}
10112// Message: Tag @this must have a type
10113````
10114
10115The following patterns are not considered problems:
10116
10117````js
10118/**
10119 * @param {Array<string>} foo
10120 */
10121function quux() {
10122
10123}
10124
10125/**
10126 * @param {string} foo
10127 */
10128function quux() {
10129
10130}
10131
10132/**
10133 * @param foo
10134 */
10135function quux() {
10136
10137}
10138
10139/**
10140 * @borrows foo as bar
10141 */
10142function quux() {
10143
10144}
10145
10146/**
10147 * @borrows foo as #bar
10148 */
10149function quux() {
10150
10151}
10152
10153/**
10154 * @see foo%
10155 */
10156function quux() {
10157
10158}
10159
10160/**
10161 * @alias module:namespace.SomeClass#event:ext_anevent
10162 */
10163function quux() {
10164
10165}
10166
10167/**
10168 * @callback foo
10169 */
10170function quux() {
10171
10172}
10173
10174/**
10175 * @callback
10176 */
10177function quux() {
10178
10179}
10180// Options: [{"allowEmptyNamepaths":true}]
10181
10182/**
10183 * @class
10184 */
10185function quux() {
10186
10187}
10188
10189/**
10190 * @see {@link foo}
10191 */
10192function quux() {
10193
10194}
10195// Options: [{"checkSeesForNamepaths":true}]
10196
10197/**
10198 *
10199 * @fires {module:namespace.SomeClass#event:ext_anevent}
10200 */
10201function quux() {
10202
10203}
10204
10205/**
10206 * @memberof module:namespace.SomeClass~
10207 */
10208function quux() {
10209
10210}
10211
10212/**
10213 * @memberof! module:namespace.SomeClass.
10214 */
10215function quux() {
10216
10217}
10218
10219/**
10220 *
10221 */
10222function quux() {
10223
10224}
10225
10226/**
10227 * @constant {string}
10228 */
10229 const FOO = 'foo';
10230
10231/**
10232 * @constant {string} FOO
10233 */
10234 const FOO = 'foo';
10235
10236/**
10237 * @extends Foo
10238 */
10239 class Bar {};
10240
10241/**
10242 * @extends {Foo<String>}
10243 */
10244 class Bar {};
10245
10246/**
10247 * @typedef {number|string} UserDefinedType
10248 */
10249
10250/**
10251 * @typedef {number|string}
10252 */
10253let UserDefinedGCCType;
10254
10255/**
10256 * @modifies {foo|bar}
10257 */
10258function quux (foo, bar, baz) {}
10259
10260/**
10261 * @private {BadTypeNotCheckedInJsdoc<}
10262 */
10263function quux () {}
10264
10265/**
10266 * @this {Navigator}
10267 */
10268function quux () {}
10269// Settings: {"jsdoc":{"mode":"closure"}}
10270
10271/**
10272 * @export {SomeType}
10273 */
10274function quux () {}
10275// Settings: {"jsdoc":{"mode":"closure"}}
10276
10277/**
10278 * @define {boolean}
10279 */
10280function quux () {}
10281// Settings: {"jsdoc":{"mode":"closure"}}
10282
10283/**
10284 * @define
10285 */
10286 function quux () {}
10287````
10288
10289
10290
\No newline at end of file