Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .README/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,24 @@ A value indicating whether getters should be checked. Defaults to `false`.

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`.

| | |
| -------- | ------------------------------------------------------------------------------------------------------------- |
| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
| Tags | `param` |
| Aliases | `arg`, `argument` |
| Options | `autoIncrementBase`, `checkDestructured`, `contexts`, `enableFixer`, `enableRootFixer`, `enableRestElementFixer`, `checkRestProperty`, `exemptedBy`, `checkConstructors`, `checkGetters`, `checkSetters`, `checkTypesPattern`, `unnamedRootBase` |
| Options | `autoIncrementBase`, `checkDestructured`, `checkDestructuredRoots`, `contexts`, `enableFixer`, `enableRootFixer`, `enableRestElementFixer`, `checkRestProperty`, `exemptedBy`, `checkConstructors`, `checkGetters`, `checkSetters`, `checkTypesPattern`, `unnamedRootBase` |
| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` |

<!-- assertions requireParam -->
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10666,12 +10666,25 @@ A value indicating whether getters should be checked. Defaults to `false`.

Whether to require destructured properties. Defaults to `true`.

<a name="eslint-plugin-jsdoc-rules-require-param-options-23-checkdestructuredroots"></a>
##### <code>checkDestructuredRoots</code>

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`.

| | |
| -------- | ------------------------------------------------------------------------------------------------------------- |
| Context | `ArrowFunctionExpression`, `FunctionDeclaration`, `FunctionExpression`; others when `contexts` option enabled |
| Tags | `param` |
| Aliases | `arg`, `argument` |
| Options | `autoIncrementBase`, `checkDestructured`, `contexts`, `enableFixer`, `enableRootFixer`, `enableRestElementFixer`, `checkRestProperty`, `exemptedBy`, `checkConstructors`, `checkGetters`, `checkSetters`, `checkTypesPattern`, `unnamedRootBase` |
| Options | `autoIncrementBase`, `checkDestructured`, `checkDestructuredRoots`, `contexts`, `enableFixer`, `enableRootFixer`, `enableRestElementFixer`, `checkRestProperty`, `exemptedBy`, `checkConstructors`, `checkGetters`, `checkSetters`, `checkTypesPattern`, `unnamedRootBase` |
| Settings | `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs` |

The following patterns are considered problems:
Expand Down Expand Up @@ -10711,6 +10724,15 @@ function quux (foo, bar, {baz}) {
// Options: [{"checkDestructured":false}]
// Message: Missing JSDoc @param "bar" declaration.

/**
* @param foo
*/
function quux (foo, bar, {baz}) {

}
// Options: [{"checkDestructuredRoots":false}]
// Message: Missing JSDoc @param "bar" declaration.

/**
*
*/
Expand Down Expand Up @@ -11808,6 +11830,15 @@ function quux (foo, bar, {baz}) {
}
// Options: [{"checkDestructured":false}]

/**
* @param foo
* @param bar
*/
function quux (foo, bar, {baz}) {

}
// Options: [{"checkDestructuredRoots":false}]

/**
* @param root
* @param root.foo
Expand Down
10 changes: 10 additions & 0 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default iterateJsdoc(({
autoIncrementBase = 0,
checkRestProperty = false,
checkDestructured = true,
checkDestructuredRoots = true,
checkTypesPattern = '/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/',
enableFixer = true,
enableRootFixer = true,
Expand Down Expand Up @@ -133,6 +134,10 @@ export default iterateJsdoc(({
return;
}

if (!checkDestructuredRoots) {
return;
}

names.forEach((paramName, idx) => {
// Add root if the root name is not in the docs (and is not already
// in the tags to be fixed)
Expand Down Expand Up @@ -274,6 +279,11 @@ export default iterateJsdoc(({
type: 'boolean',
},
checkDestructured: {
default: true,
type: 'boolean',
},
checkDestructuredRoots: {
default: true,
type: 'boolean',
},
checkGetters: {
Expand Down
45 changes: 45 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,35 @@ export default {
}
`,
},
{
code: `
/**
* @param foo
*/
function quux (foo, bar, {baz}) {

}
`,
errors: [
{
message: 'Missing JSDoc @param "bar" declaration.',
},
],
options: [
{
checkDestructuredRoots: false,
},
],
output: `
/**
* @param foo
* @param bar
*/
function quux (foo, bar, {baz}) {

}
`,
},
{
code: `
/**
Expand Down Expand Up @@ -2776,6 +2805,22 @@ export default {
},
],
},
{
code: `
/**
* @param foo
* @param bar
*/
function quux (foo, bar, {baz}) {

}
`,
options: [
{
checkDestructuredRoots: false,
},
],
},
{
code: `
/**
Expand Down