# require-param
* [Fixer](#user-content-require-param-fixer)
* [Destructured object and array naming](#user-content-require-param-fixer-destructured-object-and-array-naming)
* [Missing root fixing](#user-content-require-param-fixer-missing-root-fixing)
* [Rest Element (`RestElement`) insertions](#user-content-require-param-fixer-rest-element-restelement-insertions)
* [Object Rest Property insertions](#user-content-require-param-fixer-object-rest-property-insertions)
* [Options](#user-content-require-param-options)
* [`autoIncrementBase`](#user-content-require-param-options-autoincrementbase)
* [`checkConstructors`](#user-content-require-param-options-checkconstructors)
* [`checkDestructured`](#user-content-require-param-options-checkdestructured)
* [`checkDestructuredRoots`](#user-content-require-param-options-checkdestructuredroots)
* [`checkGetters`](#user-content-require-param-options-checkgetters)
* [`checkRestProperty`](#user-content-require-param-options-checkrestproperty)
* [`checkSetters`](#user-content-require-param-options-checksetters)
* [`checkTypesPattern`](#user-content-require-param-options-checktypespattern)
* [`contexts`](#user-content-require-param-options-contexts)
* [`enableFixer`](#user-content-require-param-options-enablefixer)
* [`enableRestElementFixer`](#user-content-require-param-options-enablerestelementfixer)
* [`enableRootFixer`](#user-content-require-param-options-enablerootfixer)
* [`exemptedBy`](#user-content-require-param-options-exemptedby)
* [`ignoreWhenAllParamsMissing`](#user-content-require-param-options-ignorewhenallparamsmissing)
* [`interfaceExemptsParamsCheck`](#user-content-require-param-options-interfaceexemptsparamscheck)
* [`unnamedRootBase`](#user-content-require-param-options-unnamedrootbase)
* [`useDefaultObjectProperties`](#user-content-require-param-options-usedefaultobjectproperties)
* [Context and settings](#user-content-require-param-context-and-settings)
* [Failing examples](#user-content-require-param-failing-examples)
* [Passing examples](#user-content-require-param-passing-examples)
Requires that all function parameters are documented.
## Fixer
Adds `@param ` for each tag present in the function signature but
missing in the jsdoc. Can be disabled by setting the `enableFixer`
option to `false`.
### Destructured object and array naming
When the fixer is applied to destructured objects, only the input name is
used.
So for:
```js
/**
* @param cfg
*/
function quux ({foo: bar, baz: bax = 5}) {
}
```
...the fixed JSDoc will be:
```js
/**
* @param cfg
* @param cfg.foo
* @param cfg.baz
*/
```
This is because the input to the function is the relevant item for
understanding the function's input, not how the variable is renamed
for internal use (the signature itself documents that).
For destructured arrays, the input name is merely the array index.
So for:
```js
/**
* @param cfg
*/
function quux ([foo, bar]) {
}
```
..the fixed JSDoc will be:
```js
/**
* @param cfg
* @param cfg."0"
* @param cfg."1"
*/
```
### Missing root fixing
Note that unless `enableRootFixer` (or `enableFixer`) is set to `false`,
missing roots will be added and auto-incremented. The default behavior
is for "root" to be auto-inserted for missing roots, followed by a
0-based auto-incrementing number.
So for:
```js
function quux ({foo}, {bar}, {baz}) {
}
```
...the default JSDoc that would be added if the fixer is enabled would be:
```js
/**
* @param root0
* @param root0.foo
* @param root1
* @param root1.bar
* @param root2
* @param root2.baz
*/
```
The name of "root" can be configured with `unnamedRootBase` (which also allows
cycling through a list of multiple root names before there is need for any
numeric component).
And one can have the count begin at another number (e.g., `1`) by changing
`autoIncrementBase` from the default of `0`.
### Rest Element (RestElement) insertions
The fixer will automatically report/insert
[JSDoc repeatable parameters](https://jsdoc.app/tags-param.html#multiple-types-and-repeatable-parameters)
if missing.
```js
/**
* @param {GenericArray} cfg
* @param {number} cfg."0"
*/
function baar ([a, ...extra]) {
//
}
```
...becomes:
```js
/**
* @param {GenericArray} cfg
* @param {number} cfg."0"
* @param {...any} cfg."1"
*/
function baar ([a, ...extra]) {
//
}
```
Note that the type `any` is included since we don't know of any specific
type to use.
To disable such rest element insertions, set `enableRestElementFixer` to
`false`.
Note too that the following will be reported even though there is an item
corresponding to `extra`:
```js
/**
* @param {GenericArray} cfg
* @param {number} cfg."0"
* @param {any} cfg."1"
*/
function baar ([a, ...extra]) {
//
}
```
...because it does not use the `...` syntax in the type.
### Object Rest Property insertions
If the `checkRestProperty` option is set to `true` (`false` by default),
missing rest properties will be reported with documentation auto-inserted:
```js
/**
* @param cfg
* @param cfg.num
*/
function quux ({num, ...extra}) {
}
```
...becomes:
```js
/**
* @param cfg
* @param cfg.num
* @param cfg.extra
*/
function quux ({num, ...extra}) {
}
```
You may wish to manually note in your JSDoc for `extra` that this is a
rest property, however, as jsdoc
[does not appear](https://github.com/jsdoc/jsdoc/issues/1773)
to currently support syntax or output to distinguish rest properties from
other properties, so in looking at the docs alone without looking at the
function signature, it may appear that there is an actual property named
`extra`.
## Options
A single options object has the following properties.
### autoIncrementBase
Numeric to indicate the number at which to begin auto-incrementing roots.
Defaults to `0`.
### checkConstructors
A value indicating whether `constructor`s should be checked. Defaults to
`true`.
### checkDestructured
Whether to require destructured properties. Defaults to `true`.
### checkDestructuredRoots
Whether to check the existence of a corresponding `@param` for root objects
of destructured properties (e.g., that for `function ({a, b}) {}`, that there
is something like `@param myRootObj` defined that can correspond to
the `{a, b}` object parameter).
If `checkDestructuredRoots` is `false`, `checkDestructured` will also be
implied to be `false` (i.e., the inside of the roots will not be checked
either, e.g., it will also not complain if `a` or `b` do not have their own
documentation). Defaults to `true`.
### checkGetters
A value indicating whether getters should be checked. Defaults to `false`.
### checkRestProperty
If set to `true`, will report (and add fixer insertions) for missing rest
properties. Defaults to `false`.
If set to `true`, note that you can still document the subproperties of the
rest property using other jsdoc features, e.g., `@typedef`:
```js
/**
* @typedef ExtraOptions
* @property innerProp1
* @property innerProp2
*/
/**
* @param cfg
* @param cfg.num
* @param {ExtraOptions} extra
*/
function quux ({num, ...extra}) {
}
```
Setting this option to `false` (the default) may be useful in cases where
you already have separate `@param` definitions for each of the properties
within the rest property.
For example, with the option disabled, this will not give an error despite
`extra` not having any definition:
```js
/**
* @param cfg
* @param cfg.num
*/
function quux ({num, ...extra}) {
}
```
Nor will this:
```js
/**
* @param cfg
* @param cfg.num
* @param cfg.innerProp1
* @param cfg.innerProp2
*/
function quux ({num, ...extra}) {
}
```
### checkSetters
A value indicating whether setters should be checked. Defaults to `false`.
### checkTypesPattern
When one specifies a type, unless it is of a generic type, like `object`
or `array`, it may be considered unnecessary to have that object's
destructured components required, especially where generated docs will
link back to the specified type. For example:
```js
/**
* @param {SVGRect} bbox - a SVGRect
*/
export const bboxToObj = function ({x, y, width, height}) {
return {x, y, width, height};
};
```
By default `checkTypesPattern` is set to
`/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/v`,
meaning that destructuring will be required only if the type of the `@param`
(the text between curly brackets) is a match for "Object" or "Array" (with or
without initial caps), "PlainObject", or "GenericObject", "GenericArray" (or
if no type is present). So in the above example, the lack of a match will
mean that no complaint will be given about the undocumented destructured
parameters.
Note that the `/` delimiters are optional, but necessary to add flags.
Defaults to using (only) the `v` flag, so to add your own flags, encapsulate
your expression as a string, but like a literal, e.g., `/^object$/vi`.
You could set this regular expression to a more expansive list, or you
could restrict it such that even types matching those strings would not
need destructuring.
### contexts
Set this to an array of strings representing the AST context (or an object with
optional `context` and `comment` properties) where you wish the rule to be applied.
`context` defaults to `any` and `comment` defaults to no specific comment context.
Overrides the default contexts (`ArrowFunctionExpression`, `FunctionDeclaration`,
`FunctionExpression`). May be useful for adding such as
`TSMethodSignature` in TypeScript or restricting the contexts
which are checked.
See the ["AST and Selectors"](../advanced.md#ast-and-selectors)
section of our Advanced docs for more on the expected format.
### enableFixer
Whether to enable the fixer. Defaults to `true`.
### enableRestElementFixer
Whether to enable the rest element fixer.
The fixer will automatically report/insert
[JSDoc repeatable parameters](https://jsdoc.app/tags-param.html#multiple-types-and-repeatable-parameters)
if missing.
```js
/**
* @param {GenericArray} cfg
* @param {number} cfg."0"
*/
function baar ([a, ...extra]) {
//
}
```
...becomes:
```js
/**
* @param {GenericArray} cfg
* @param {number} cfg."0"
* @param {...any} cfg."1"
*/
function baar ([a, ...extra]) {
//
}
```
Note that the type `any` is included since we don't know of any specific
type to use.
Defaults to `true`.
### enableRootFixer
Whether to enable the auto-adding of incrementing roots.
The default behavior of `true` is for "root" to be auto-inserted for missing
roots, followed by a 0-based auto-incrementing number.
So for:
```js
function quux ({foo}, {bar}, {baz}) {
}
```
...the default JSDoc that would be added if the fixer is enabled would be:
```js
/**
* @param root0
* @param root0.foo
* @param root1
* @param root1.bar
* @param root2
* @param root2.baz
*/
```
Has no effect if `enableFixer` is set to `false`.
### exemptedBy
Array of tags (e.g., `['type']`) whose presence on the document block
avoids the need for a `@param`. Defaults to an array with
`inheritdoc`. If you set this array, it will overwrite the default,
so be sure to add back `inheritdoc` if you wish its presence to cause
exemption of the rule.
### ignoreWhenAllParamsMissing
Set to `true` to ignore reporting when all params are missing. Defaults to
`false`.
### interfaceExemptsParamsCheck
Set if you wish TypeScript interfaces to exempt checks for the existence of
`@param`'s.
Will check for a type defining the function itself (on a variable
declaration) or if there is a single destructured object with a type.
Defaults to `false`.
### unnamedRootBase
An array of root names to use in the fixer when roots are missing. Defaults
to `['root']`. Note that only when all items in the array besides the last
are exhausted will auto-incrementing occur. So, with
`unnamedRootBase: ['arg', 'config']`, the following:
```js
function quux ({foo}, [bar], {baz}) {
}
```
...will get the following JSDoc block added:
```js
/**
* @param arg
* @param arg.foo
* @param config0
* @param config0."0" (`bar`)
* @param config1
* @param config1.baz
*/
```
### useDefaultObjectProperties
Set to `true` if you wish to expect documentation of properties on objects
supplied as default values. Defaults to `false`.
## Context and settings
| | |
| -------- | ----------------------------------------------------------------------------- |
| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
| Tags | `param` |
| Aliases | `arg`, `argument` |
|Recommended | true|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `ignoreWhenAllParamsMissing`, `interfaceExemptsParamsCheck`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Settings | `ignoreReplacesDocs`, `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|
## Failing examples
The following patterns are considered problems:
````ts
/**
*
*/
function quux (foo) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
*
*/
function quux (foo) {
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["FunctionDeclaration"]}]
// Message: Missing JSDoc @param "foo" declaration.
/**
*
*/
function quux ({foo}) {
}
// Message: Missing JSDoc @param "root0" declaration.
/**
* @param foo
*/
function quux (foo, bar, {baz}) {
}
// "jsdoc/require-param": ["error"|"warn", {"checkDestructured":false}]
// Message: Missing JSDoc @param "bar" declaration.
/**
* @param foo
*/
function quux (foo, bar, {baz}) {
}
// "jsdoc/require-param": ["error"|"warn", {"checkDestructuredRoots":false}]
// Message: Missing JSDoc @param "bar" declaration.
/**
*
*/
function quux ({foo}) {
}
// "jsdoc/require-param": ["error"|"warn", {"enableFixer":false}]
// Message: Missing JSDoc @param "root0" declaration.
/**
*
*/
function quux ({foo: bar = 5} = {}) {
}
// Message: Missing JSDoc @param "root0" declaration.
/**
* @param
*/
function quux ({foo}) {
}
// Message: Missing JSDoc @param "root0" declaration.
/**
* @param
*/
function quux ({foo}) {
}
// "jsdoc/require-param": ["error"|"warn", {"autoIncrementBase":1}]
// Message: Missing JSDoc @param "root1" declaration.
/**
* @param options
*/
function quux ({foo}) {
}
// Message: Missing JSDoc @param "options.foo" declaration.
/**
* @param
*/
function quux ({ foo, bar: { baz }}) {
}
// Message: Missing JSDoc @param "root0" declaration.
/**
* @param root0
* @param root0.foo
* @param root0.bar.baz
*/
function quux ({ foo, bar: { baz }}) {
}
// Message: Missing JSDoc @param "root0.bar" declaration.
/**
*
*/
function quux ({foo}, {bar}) {
}
// "jsdoc/require-param": ["error"|"warn", {"unnamedRootBase":["arg"]}]
// Message: Missing JSDoc @param "arg0" declaration.
/**
*
*/
function quux ({foo}, {bar}) {
}
// "jsdoc/require-param": ["error"|"warn", {"unnamedRootBase":["arg","config"]}]
// Message: Missing JSDoc @param "arg" declaration.
/**
*
*/
function quux ({foo}, {bar}) {
}
// "jsdoc/require-param": ["error"|"warn", {"enableRootFixer":false,"unnamedRootBase":["arg","config"]}]
// Message: Missing JSDoc @param "arg" declaration.
/**
*
*/
function quux (foo, bar) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @param foo
*/
function quux (foo, bar) {
}
// Message: Missing JSDoc @param "bar" declaration.
/**
* @param bar
*/
function quux (foo, bar, baz) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @param foo
* @param bar
*/
function quux (foo, bar, baz) {
}
// Message: Missing JSDoc @param "baz" declaration.
/**
* @param baz
*/
function quux (foo, bar, baz) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @param
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":"arg"}}}
// Message: Missing JSDoc @arg "foo" declaration.
/**
* @override
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @ignore
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"ignoreReplacesDocs":false}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @implements
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @augments
*/
function quux (foo) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @extends
*/
function quux (foo) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @override
*/
class A {
/**
*
*/
quux (foo) {
}
}
// Settings: {"jsdoc":{"overrideReplacesDocs":false}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @ignore
*/
class A {
/**
*
*/
quux (foo) {
}
}
// Settings: {"jsdoc":{"ignoreReplacesDocs":false}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @implements
*/
class A {
/**
*
*/
quux (foo) {
}
}
// Settings: {"jsdoc":{"implementsReplacesDocs":false}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @augments
*/
class A {
/**
*
*/
quux (foo) {
}
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @extends
*/
class A {
/**
*
*/
quux (foo) {
}
}
// Message: Missing JSDoc @param "foo" declaration.
export class SomeClass {
/**
* @param property
*/
constructor(private property: string, private foo: number) {}
}
// Message: Missing JSDoc @param "foo" declaration.
/**
* @param
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"tagNamePreference":{"param":false}}}
// Message: Unexpected tag `@param`
/**
*
*/
function quux ({bar, baz}, foo) {
}
// Message: Missing JSDoc @param "root0" declaration.
/**
*
*/
function quux (foo, {bar, baz}) {
}
// Message: Missing JSDoc @param "foo" declaration.
/**
*
*/
function quux ([bar, baz], foo) {
}
// Message: Missing JSDoc @param "root0" declaration.
/**
*
*/
function quux (foo) {
}
// "jsdoc/require-param": ["error"|"warn", {"exemptedBy":["notPresent"]}]
// Message: Missing JSDoc @param "foo" declaration.
/**
* @inheritdoc
*/
function quux (foo) {
}
// "jsdoc/require-param": ["error"|"warn", {"exemptedBy":[]}]
// Message: Missing JSDoc @param "foo" declaration.
/**
* @inheritdoc
*/
function quux (foo) {
}
// Settings: {"jsdoc":{"mode":"closure"}}
// Message: Missing JSDoc @param "foo" declaration.
/**
* Assign the project to a list of employees.
* @param {object[]} employees - The employees who are responsible for the project.
* @param {string} employees[].name - The name of an employee.
* @param {string} employees[].department - The employee's department.
*/
function assign (employees, name) {
};
// Message: Missing JSDoc @param "name" declaration.
interface ITest {
/**
* Test description.
*/
TestMethod(id: number): void;
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSMethodSignature"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A test class.
*/
abstract class TestClass
{
/**
* A test method.
*/
abstract TestFunction(id);
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSEmptyBodyFunctionExpression"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A test class.
*/
declare class TestClass
{
/**
*
*/
TestMethod(id);
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSEmptyBodyFunctionExpression"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A test function.
*/
declare let TestFunction: (id) => void;
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A test function.
*/
let TestFunction: (id) => void;
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A test function.
*/
function test(
processor: (id: number) => string
) {
return processor(10);
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A test function.
*/
let test = (processor: (id: number) => string) =>
{
return processor(10);
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
class TestClass {
/**
* A class property.
*/
public Test: (id: number) => string;
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
class TestClass {
/**
* A class method.
*/
public TestMethod(): (id: number) => string
{
}
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
interface TestInterface {
/**
* An interface property.
*/
Test: (id: number) => string;
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
interface TestInterface {
/**
* An interface method.
*/
TestMethod(): (id: number) => string;
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A function with return type
*/
function test(): (id: number) => string;
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* A function with return type
*/
let test = (): (id: number) => string =>
{
return (id) => `${id}`;
}
// "jsdoc/require-param": ["error"|"warn", {"contexts":["TSFunctionType"]}]
// Message: Missing JSDoc @param "id" declaration.
/**
* @param baz
* @param options
*/
function quux (baz, {foo: bar}) {
}
// Message: Missing JSDoc @param "options.foo" declaration.
class Client {
/**
* Set collection data.
* @param {Object} data The collection data object.
* @param {number} data.last_modified
* @param {Object} options The options object.
* @param {Object} [options.headers] The headers object option.
* @param {Number} [options.retry=0] Number of retries to make
* when faced with transient errors.
* @param {Boolean} [options.safe] The safe option.
* @param {Boolean} [options.patch] The patch option.
* @param {Number} [options.last_modified] The last_modified option.
* @return {Promise