Skip to content

Commit

Permalink
feat(require-param): add ignoreWhenAllParamsMissing option; fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
brettz9 committed Sep 26, 2024
1 parent 51c68b1 commit 3b18435
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
7 changes: 6 additions & 1 deletion .README/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@ documentation). Defaults to `true`.
Set to `true` if you wish to expect documentation of properties on objects
supplied as default values. Defaults to `false`.

### `ignoreWhenAllParamsMissing`

Set to `true` to ignore reporting when all params are missing. Defaults to
`false`.

## Context and settings

| | |
Expand All @@ -377,7 +382,7 @@ supplied as default values. Defaults to `false`.
| Tags | `param` |
| Aliases | `arg`, `argument` |
|Recommended | true|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `ignoreWhenAllParamsMissing`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Settings | `ignoreReplacesDocs`, `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|

## Failing examples
Expand Down
24 changes: 23 additions & 1 deletion docs/rules/require-param.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* [`checkDestructured`](#user-content-require-param-options-checkdestructured)
* [`checkDestructuredRoots`](#user-content-require-param-options-checkdestructuredroots)
* [`useDefaultObjectProperties`](#user-content-require-param-options-usedefaultobjectproperties)
* [`ignoreWhenAllParamsMissing`](#user-content-require-param-options-ignorewhenallparamsmissing)
* [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)
Expand Down Expand Up @@ -437,6 +438,13 @@ documentation). Defaults to `true`.
Set to `true` if you wish to expect documentation of properties on objects
supplied as default values. Defaults to `false`.

<a name="user-content-require-param-options-ignorewhenallparamsmissing"></a>
<a name="require-param-options-ignorewhenallparamsmissing"></a>
### <code>ignoreWhenAllParamsMissing</code>

Set to `true` to ignore reporting when all params are missing. Defaults to
`false`.

<a name="user-content-require-param-context-and-settings"></a>
<a name="require-param-context-and-settings"></a>
## Context and settings
Expand All @@ -447,7 +455,7 @@ supplied as default values. Defaults to `false`.
| Tags | `param` |
| Aliases | `arg`, `argument` |
|Recommended | true|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Options |`autoIncrementBase`, `checkConstructors`, `checkDestructured`, `checkDestructuredRoots`, `checkGetters`, `checkRestProperty`, `checkSetters`, `checkTypesPattern`, `contexts`, `enableFixer`, `enableRestElementFixer`, `enableRootFixer`, `exemptedBy`, `ignoreWhenAllParamsMissing`, `unnamedRootBase`, `useDefaultObjectProperties`|
| Settings | `ignoreReplacesDocs`, `overrideReplacesDocs`, `augmentsExtendsReplacesDocs`, `implementsReplacesDocs`|

<a name="user-content-require-param-failing-examples"></a>
Expand Down Expand Up @@ -1162,6 +1170,14 @@ class A {
}
}
// Message: Missing JSDoc @param "root1" declaration.

/**
* Some desc.
* @param a
*/
function quux (a, b) {}
// "jsdoc/require-param": ["error"|"warn", {"ignoreWhenAllParamsMissing":true}]
// Message: Missing JSDoc @param "b" declaration.
````


Expand Down Expand Up @@ -1813,5 +1829,11 @@ const inner = (c: number, d: string): void => {
console.log(d);
};
// Settings: {"jsdoc":{"contexts":["VariableDeclaration"]}}

/**
* Some desc.
*/
function quux (a, b) {}
// "jsdoc/require-param": ["error"|"warn", {"ignoreWhenAllParamsMissing":true}]
````

8 changes: 8 additions & 0 deletions src/rules/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default iterateJsdoc(({
'root',
],
useDefaultObjectProperties = false,
ignoreWhenAllParamsMissing = false,
} = context.options[0] || {};

const preferredTagName = /** @type {string} */ (utils.getPreferredTagName({
Expand All @@ -83,6 +84,10 @@ export default iterateJsdoc(({
* }[]}
*/ (utils.getJsdocTagsDeep(preferredTagName));

if (ignoreWhenAllParamsMissing && !jsdocParameterNames.length) {
return;
}

const shallowJsdocParameterNames = jsdocParameterNames.filter((tag) => {
return !tag.name.includes('.');
}).map((tag, idx) => {
Expand Down Expand Up @@ -571,6 +576,9 @@ export default iterateJsdoc(({
},
type: 'array',
},
ignoreWhenAllParamsMissing: {
type: 'boolean',
},
unnamedRootBase: {
items: {
type: 'string',
Expand Down
40 changes: 40 additions & 0 deletions test/rules/assertions/requireParam.js
Original file line number Diff line number Diff line change
Expand Up @@ -2527,6 +2527,33 @@ export default {
}
`,
},
{
code: `
/**
* Some desc.
* @param a
*/
function quux (a, b) {}
`,
errors: [
{
message: 'Missing JSDoc @param "b" declaration.',
},
],
options: [
{
ignoreWhenAllParamsMissing: true,
}
],
output: `
/**
* Some desc.
* @param a
* @param b
*/
function quux (a, b) {}
`,
},
],
valid: [
{
Expand Down Expand Up @@ -3604,5 +3631,18 @@ export default {
}
},
},
{
code: `
/**
* Some desc.
*/
function quux (a, b) {}
`,
options: [
{
ignoreWhenAllParamsMissing: true,
}
],
},
],
};

0 comments on commit 3b18435

Please sign in to comment.